From afac4c8c7780cc40bb41d8bae97a4ae83a79db9f Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Tue, 20 Oct 2026 03:35:56 -0500 Subject: Finished minimal message impl --- src/lib/reply.zig | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/lib/reply.zig (limited to 'src/lib/reply.zig') diff --git a/src/lib/reply.zig b/src/lib/reply.zig new file mode 100644 index 0000000..61df971 --- /dev/null +++ b/src/lib/reply.zig @@ -0,0 +1,41 @@ +const std = @import("std"); +const Io = std.Io; + +pub const Code = enum(u16) { + ready = 220, + cannot_verify = 252, + closing = 221, + start_data = 354, + ok = 250, + not_avail = 421, + bad_cmd = 500, + bad_param = 501, + not_impl = 502, + bad_sequence = 503, + param_not_impl = 504, + rejected = 550, + too_many = 452, + exceeded = 552, + param_unrecognized = 555, + _, //@as(Code, @enumFromInt(user defined code)) +}; + +pub const Action = enum { cont, data, close }; + +pub const Reply = struct { + code: Code, + lines: []const []const u8, + action: Action = .cont, + + pub fn single(code: Code, comptime text: []const u8) Reply { + return .{ .code = code, .lines = &.{text} }; + } + + pub fn send(self: Reply, w: *Io.Writer) !void { + const code = @intFromEnum(self.code); + for (self.lines, 0..) |line, i| { + const sep: u8 = if (i == self.lines.len - 1) ' ' else '-'; + try w.print("{d}{c}{s}\r\n", .{ code, sep, line }); + } + } +}; -- cgit v1.2.3