1
Fork 0

wip iterator

This commit is contained in:
Motiejus Jakštys 2022-02-20 12:44:21 +02:00 committed by Motiejus Jakštys
parent e54c153dd8
commit 54ec710f10
1 changed files with 35 additions and 0 deletions

View File

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const pad = @import("padding.zig"); const pad = @import("padding.zig");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList; const ArrayList = std.ArrayList;
const cast = std.math.cast; 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; const testing = std.testing;
test "PackedUser is byte-aligned" { test "PackedUser is byte-aligned" {