Base64 encode relay message

write the packed connection struct directly instead of each of the fields.
This commit is contained in:
2025-04-02 23:43:28 -04:00
parent 741f1efc46
commit 46ac234c80

View File

@@ -1,4 +1,5 @@
const is_debug = builtin.mode == .Debug;
const base64 = std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
const SaprusPacketType = enum(u16) {
relay = 0x003C,
@@ -23,7 +24,7 @@ const SaprusMessage = union(SaprusPacketType) {
payload: []u8,
},
file_transfer: void, // unimplemented
connection: struct {
connection: packed struct {
src_port: u16,
dest_port: u16,
seq_num: u32 = 0,
@@ -43,16 +44,11 @@ const SaprusMessage = union(SaprusPacketType) {
.relay => |r| {
try w.writeAll(&r.dest);
try w.writeInt(u16, @intCast(r.payload.len), .big);
try w.writeAll(r.payload);
try base64.encodeWriter(w, 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);
try w.writeStruct(c);
},
}