diff options
| -rw-r--r-- | src/main.zig | 40 | 
1 files changed, 32 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig index 5989e40..f5f293b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,12 +1,20 @@ -//! By convention, main.zig is where your main function lives in the case that -//! you are building an executable. If you are making a library, the convention -//! is to delete this file and start with root.zig instead. -  const is_debug = builtin.mode == .Debug;  const SaprusPacketType = enum(u16) {      relay = 0x003C,      file_transfer = 0x8888, +    connection = 0x00E9, +}; + +const SaprusConnectionOptions = packed struct { +    opt1: bool = false, +    opt2: bool = false, +    opt3: bool = false, +    opt4: bool = false, +    opt5: bool = false, +    opt6: bool = false, +    opt7: bool = false, +    opt8: bool = false,  };  const SaprusMessage = union(SaprusPacketType) { @@ -15,6 +23,14 @@ const SaprusMessage = union(SaprusPacketType) {          payload: []u8,      },      file_transfer: void, // unimplemented +    connection: struct { +        src_port: u16, +        dest_port: u16, +        seq_num: u32 = 0, +        msg_id: u32 = 0, +        reserved: u8 = 0, +        options: SaprusConnectionOptions = .{}, +    },      const Self = @This(); @@ -24,12 +40,20 @@ const SaprusMessage = union(SaprusPacketType) {          try w.writeInt(u16, @intFromEnum(@as(SaprusPacketType, s)), .big);          switch (s) { -            .relay => |relay| { -                try w.writeAll(&relay.dest); -                try w.writeInt(u16, @intCast(relay.payload.len), .big); -                try w.writeAll(relay.payload); +            .relay => |r| { +                try w.writeAll(&r.dest); +                try w.writeInt(u16, @intCast(r.payload.len), .big); +                try w.writeAll(r.payload);              },              .file_transfer => unreachable, +            .connection => |c| { +                try w.writeInt(u16, c.src_port, .big); +                try w.writeInt(u16, c.dest_port, .big); +                try w.writeInt(u32, c.seq_num, .big); +                try w.writeInt(u32, c.msg_id, .big); +                try w.writeInt(u8, c.reserved, .big); +                try w.writeStruct(c.options); +            },          }          return buf.toOwnedSlice();  | 
