diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-04-02 23:21:55 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-04-06 13:08:09 -0400 |
commit | 741f1efc46f672e735faa251b9f5c39f55171f4d (patch) | |
tree | ad8a7feb86c2a724c02b1330015363232cb26726 /src/main.zig | |
parent | 0c0a678811bb92bb1564f92cd05cf916921c215a (diff) |
Add connection message type
Diffstat (limited to 'src/main.zig')
-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(); |