From 5a91b37ee7dd36db52dfde1727b780ec3fa4c67d Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sat, 23 Sep 2023 15:18:38 +0100 Subject: Add error_response Start adding connection abstraction --- src/password_message.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/password_message.zig') diff --git a/src/password_message.zig b/src/password_message.zig index 33214bf..1a8c17a 100644 --- a/src/password_message.zig +++ b/src/password_message.zig @@ -6,16 +6,17 @@ pub const Tag: u8 = 'p'; password: []const u8, password_owned: bool = false, - pub fn read(allocator: std.mem.Allocator, b: []const u8) !PasswordMessage { return .{ .password = try allocator.dupe(u8, b), .password_owned = true }; } + pub fn write(self: PasswordMessage, _: std.mem.Allocator, stream_writer: anytype) !void { try stream_writer.writeByte(Tag); try stream_writer.writeIntBig(u32, 5 + @as(u32, @intCast(self.password.len))); try stream_writer.writeAll(self.password); try stream_writer.writeByte(0); } + pub fn deinit(self: *PasswordMessage, allocator: std.mem.Allocator) void { if (self.password_owned) allocator.free(self.password); } -- cgit v1.2.3-ZIG