diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 35 | 
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig index e8db093..ebb7d33 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,6 +2,40 @@  //! 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 SaprusPacketType = enum(u16) { +    relay = 0x003C, +    file_transfer = 0x8888, +}; + +const SaprusHeaderFrame = struct { +    msg_type: SaprusPacketType, +    payload: []u8, + +    const Self = @This(); + +    fn toBytes(s: Self, allocator: Allocator) ![]u8 { +        const buf = allocator.alloc(u8, 32 + s.payload.len); +        std.mem.writeInt(u16, buf[0..2], s.msg_type, .big); +        std.mem.writeInt(u16, buf[2..4], s.payload.len); +        std.mem.copyForwards(u8, buf[4..], s.payload); +        return buf; +    } +}; + +const SaprusRelayMessage = struct { +    dest: [4]u8, +    payload: []u8, + +    const Self = @This(); + +    fn toBytes(s: Self, allocator: Allocator) ![]u8 { +        const buf = allocator.alloc(u8, 4 + s.payload.len); +        std.mem.copyForwards(u8, buf[0..4], s.dest); +        std.mem.copyForwards(u8, buf[4..], s.payload); +        return buf; +    } +}; +  pub fn main() !void {      // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)      std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); @@ -37,3 +71,4 @@ test "fuzz example" {  }  const std = @import("std"); +const Allocator = std.mem.Allocator;  | 
