const std = @import("std"); const Self = @This(); class: u4, destination_identifier: u4, codes_count: [16]u8, values: [16][]u8, pub fn read(gpa: std.mem.Allocator, reader: *std.Io.Reader) !Self { const kind = try reader.takeByte(); var self: Self = undefined; self.class = @truncate(kind >> 4); self.destination_identifier = @truncate(kind); for (self.codes_count[0..]) |*count| { count.* = try reader.takeByte(); } for (self.values[0..], self.codes_count) |*values, count| { values.* = try gpa.alloc(u8, count); for (values.*) |*value| { value.* = try reader.takeByte(); } } return self; } pub fn deinit(self: *Self, gpa: std.mem.Allocator) void { for (self.values) |value| { gpa.free(value); } self.* = undefined; } pub fn size_in_file(self: Self) usize { var size: usize = 17; for (self.codes_count) |count| { size += count; } return size; }