diff options
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/message_parser.zig | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/src/server/message_parser.zig b/src/server/message_parser.zig index 52d1422..381dc2c 100644 --- a/src/server/message_parser.zig +++ b/src/server/message_parser.zig @@ -1,37 +1,8 @@ const std = @import("std"); -pub const MessageType = enum { - info, - connect, - @"pub", - hpub, - sub, - unsub, - msg, - hmsg, - ping, - pong, - @"+ok", - @"-err", - - fn parseMemEql(input: []const u8) ?MessageType { - // if (std.mem.eql(u8, "INFO", input)) return .info; - if (std.mem.eql(u8, "CONNECT", input)) return .connect; - if (std.mem.eql(u8, "PUB", input)) return .@"pub"; - if (std.mem.eql(u8, "HPUB", input)) return .hpub; - if (std.mem.eql(u8, "SUB", input)) return .sub; - if (std.mem.eql(u8, "UNSUB", input)) return .unsub; - // if (std.mem.eql(u8, "MSG", input)) return .msg; - // if (std.mem.eql(u8, "HMSG", input)) return .hmsg; - if (std.mem.eql(u8, "PING", input)) return .ping; - if (std.mem.eql(u8, "PONG", input)) return .pong; - // if (std.mem.eql(u8, "@"+OK"", input)) return .@"+ok"; - // if (std.mem.eql(u8, "@"-ERR"", input)) return .@"-err"; - return error.InvalidMessageType; - } -}; +pub const MessageType = @typeInfo(Message).@"union".tag_type.?; -pub const Message = union(MessageType) { +pub const Message = union(enum) { info: ServerInfo, connect: Connect, @"pub": Pub, @@ -437,6 +408,7 @@ fn parsePub(alloc: std.mem.Allocator, in: *std.Io.Reader) !Message { var third: ?std.ArrayList(u8) = null; defer if (third) |*t| t.deinit(alloc); var payload: std.Io.Writer.Allocating = .init(alloc); + errdefer payload.deinit(); sw: switch (@as(States, .before_second)) { .before_second => { @@ -574,6 +546,7 @@ fn parseHPub(alloc: std.mem.Allocator, in: *std.Io.Reader) !Message { var fourth: ?std.ArrayList(u8) = null; defer if (fourth) |*f| f.deinit(alloc); var payload: std.Io.Writer.Allocating = .init(alloc); + errdefer payload.deinit(); sw: switch (@as(States, .before_second)) { .before_second => { |
