mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 19:54:48 +00:00
Remove unnecessary explicit enum
This can be computed (as it is now)
This commit is contained in:
@@ -1,37 +1,8 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const MessageType = enum {
|
||||
info,
|
||||
connect,
|
||||
@"pub",
|
||||
hpub,
|
||||
sub,
|
||||
unsub,
|
||||
msg,
|
||||
hmsg,
|
||||
ping,
|
||||
pong,
|
||||
@"+ok",
|
||||
@"-err",
|
||||
pub const MessageType = @typeInfo(Message).@"union".tag_type.?;
|
||||
|
||||
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 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 => {
|
||||
|
||||
Reference in New Issue
Block a user