mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 03:34: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");
|
const std = @import("std");
|
||||||
|
|
||||||
pub const MessageType = enum {
|
pub const MessageType = @typeInfo(Message).@"union".tag_type.?;
|
||||||
info,
|
|
||||||
connect,
|
|
||||||
@"pub",
|
|
||||||
hpub,
|
|
||||||
sub,
|
|
||||||
unsub,
|
|
||||||
msg,
|
|
||||||
hmsg,
|
|
||||||
ping,
|
|
||||||
pong,
|
|
||||||
@"+ok",
|
|
||||||
@"-err",
|
|
||||||
|
|
||||||
fn parseMemEql(input: []const u8) ?MessageType {
|
pub const Message = union(enum) {
|
||||||
// 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) {
|
|
||||||
info: ServerInfo,
|
info: ServerInfo,
|
||||||
connect: Connect,
|
connect: Connect,
|
||||||
@"pub": Pub,
|
@"pub": Pub,
|
||||||
@@ -437,6 +408,7 @@ fn parsePub(alloc: std.mem.Allocator, in: *std.Io.Reader) !Message {
|
|||||||
var third: ?std.ArrayList(u8) = null;
|
var third: ?std.ArrayList(u8) = null;
|
||||||
defer if (third) |*t| t.deinit(alloc);
|
defer if (third) |*t| t.deinit(alloc);
|
||||||
var payload: std.Io.Writer.Allocating = .init(alloc);
|
var payload: std.Io.Writer.Allocating = .init(alloc);
|
||||||
|
errdefer payload.deinit();
|
||||||
|
|
||||||
sw: switch (@as(States, .before_second)) {
|
sw: switch (@as(States, .before_second)) {
|
||||||
.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;
|
var fourth: ?std.ArrayList(u8) = null;
|
||||||
defer if (fourth) |*f| f.deinit(alloc);
|
defer if (fourth) |*f| f.deinit(alloc);
|
||||||
var payload: std.Io.Writer.Allocating = .init(alloc);
|
var payload: std.Io.Writer.Allocating = .init(alloc);
|
||||||
|
errdefer payload.deinit();
|
||||||
|
|
||||||
sw: switch (@as(States, .before_second)) {
|
sw: switch (@as(States, .before_second)) {
|
||||||
.before_second => {
|
.before_second => {
|
||||||
|
|||||||
Reference in New Issue
Block a user