diff --git a/src/protocol.zig b/src/protocol.zig index acce43f..d746c3c 100644 --- a/src/protocol.zig +++ b/src/protocol.zig @@ -1,28 +1,49 @@ const std = @import("std"); -const DataV1 = struct { - // TODO: Implement version!! - // version: i8, +const VERSION: u8 = 1; + +// Integers +// u4 -> 16 +// u8 -> 256 +// u16 -> 65,535 +// u32 -> 4,294,967,295 + +// Data format: +// u8 -> version +// u16 -> width +// u16 -> height +// u8,u8,u8 list of rgb for each pixel, going from left to right, top to bottom +// +// UDP Packet Size: 65,535 Bytes +// 1 Byte = 8 Bits +// 8+16+16 = 40 Bits header +// (65k * 8) - 40 = 524,240 +// 8+8+8 = 24 +// 24 / 524,240 = 21,843 pixel +// 1920*1080 = 2,073,600 pixel + +const Data = struct { + version: u8, count: u8, }; const SerializationError = error{ VersionDoesNotMatchError, OtherError }; -fn deserialize(input: []u8) SerializationError!DataV1 { +fn deserialize(input: []u8) SerializationError!Data { if (input.len == 0) { return SerializationError.OtherError; } return .{ .count = input[0] }; } -fn serialize(allocator: std.mem.Allocator, input: DataV1) ![]u8 { +fn serialize(allocator: std.mem.Allocator, input: Data) ![]u8 { const data = try allocator.alloc(u8, 1); data[0] = input.count; return data; } test "expect DataV1 can be serialized and deserialized" { - const expected: DataV1 = .{ .count = 128 }; + const expected: Data = .{ .count = 128 }; const serialized = try serialize(std.testing.allocator, expected); defer std.testing.allocator.free(serialized);