From 54ec710f10a40b7a70bcc1a8db82c0b8531c0d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 20 Feb 2022 12:44:21 +0200 Subject: [PATCH] wip iterator --- src/user.zig | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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" {