Add comments and fix tests

Also added networkBytesAsValue and restored bytesAsValue.
These are useful for treating the bytes from the network directly as a Message.
Otherwise, the init function would overwrite the packet type and length to be correct.
I would like the message handling to fail if the message body is incorrect.
This commit is contained in:
2025-05-10 12:50:19 -04:00
parent 56e72928c6
commit 583f9d8b8f
2 changed files with 63 additions and 31 deletions

View File

@@ -127,7 +127,7 @@ pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusConnection {
const len = try sock.receive(&response_buf);
std.debug.print("response bytes: {x}\n", .{response_buf[0..len]});
initial_conn_res = SaprusMessage.init(.connection, response_buf[0..len]);
initial_conn_res = try .networkBytesAsValue(response_buf[0..len]);
// Complete handshake after awaiting response
try broadcastSaprusMessage(msg, randomPort());