wip iterator
This commit is contained in:
parent
e54c153dd8
commit
54ec710f10
35
src/user.zig
35
src/user.zig
|
@ -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" {
|
||||||
|
|
Loading…
Reference in New Issue