diff --git a/src/user.zig b/src/user.zig index 8aab1a4..57745f7 100644 --- a/src/user.zig +++ b/src/user.zig @@ -1,6 +1,7 @@ const std = @import("std"); const pad = @import("padding.zig"); +const assert = std.debug.assert; const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList; const cast = std.math.cast; @@ -90,6 +91,40 @@ pub const UserWriter = struct { } }; +pub const UserReader = struct { + const shellIndexProto = fn (u10) []const u8; + + shellIndex: shellIndexProto, + blob: []const u8, + + pub const PackedUserEntry = struct { + packed_user: *PackedUser, + blob: []const u8, + }; + + pub fn init(shellIndex: shellIndexProto, blob: []const u8) UserReader { + return UserReader{ + .shellIndex = shellIndex, + .blob = blob, + }; + } + + pub const PackedUserIterator = struct { + ur: *const UserReader, + index: u32 = 0, + + pub fn next(it: *PackedUserIterator) ?PackedUserEntry { + if (it.index == it.ur.blob.len) return null; + assert(it.index < it.blob.len); + + const start = it.index; + const end = it.index + it.index + @sizeOf(PackedUser); + var pu = std.mem.bytesAsValue(it.ur.blob[start..end]); + _ = pu; + } + }; +}; + const testing = std.testing; test "PackedUser is byte-aligned" {