mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24:50 +00:00
Add connection message type
This commit is contained in:
40
src/main.zig
40
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 is_debug = builtin.mode == .Debug;
|
||||||
|
|
||||||
const SaprusPacketType = enum(u16) {
|
const SaprusPacketType = enum(u16) {
|
||||||
relay = 0x003C,
|
relay = 0x003C,
|
||||||
file_transfer = 0x8888,
|
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) {
|
const SaprusMessage = union(SaprusPacketType) {
|
||||||
@@ -15,6 +23,14 @@ const SaprusMessage = union(SaprusPacketType) {
|
|||||||
payload: []u8,
|
payload: []u8,
|
||||||
},
|
},
|
||||||
file_transfer: void, // unimplemented
|
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();
|
const Self = @This();
|
||||||
|
|
||||||
@@ -24,12 +40,20 @@ const SaprusMessage = union(SaprusPacketType) {
|
|||||||
try w.writeInt(u16, @intFromEnum(@as(SaprusPacketType, s)), .big);
|
try w.writeInt(u16, @intFromEnum(@as(SaprusPacketType, s)), .big);
|
||||||
|
|
||||||
switch (s) {
|
switch (s) {
|
||||||
.relay => |relay| {
|
.relay => |r| {
|
||||||
try w.writeAll(&relay.dest);
|
try w.writeAll(&r.dest);
|
||||||
try w.writeInt(u16, @intCast(relay.payload.len), .big);
|
try w.writeInt(u16, @intCast(r.payload.len), .big);
|
||||||
try w.writeAll(relay.payload);
|
try w.writeAll(r.payload);
|
||||||
},
|
},
|
||||||
.file_transfer => unreachable,
|
.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();
|
return buf.toOwnedSlice();
|
||||||
|
|||||||
Reference in New Issue
Block a user