feature. See also
. The project being documented here (as the example) is the Zig library itself.
Progress.Ipc
pub const Ipc = packed struct(u32)
File
Code
pub const Ipc = packed struct(u32) {
locked: bool,
valid: bool,
unused: @Int(.unsigned, 32 - 2 - @bitSizeOf(Generation)) = 0,
generation: Generation,
pub const Slot = std.math.IntFittingRange(0, ipc_storage_buffer_len - 1);
pub const Generation = @Int(.unsigned, 32 - @bitSizeOf(Slot));
const SlotAtomic = @Int(.unsigned, std.math.ceilPowerOfTwoAssert(usize, @min(@bitSizeOf(Slot), 8)));
pub const Index = packed struct(u32) {
slot: Slot,
generation: Generation,
};
const Data = struct {
state: State,
bytes_read: u16,
main_index: u8,
start_index: u8,
nodes_len: u8,
const State = enum { unused, pending, ready };
const unused: Data = .{
.state = .unused,
.bytes_read = 0,
.main_index = 0,
.start_index = 0,
.nodes_len = 0,
};
fn findLastPacket(data: *const Data, buffer: *const [max_packet_len]u8) struct { u16, u16 } {
assert(data.state == .ready);
var packet_start: u16 = 0;
var packet_end: u16 = 0;
const bytes_read = data.bytes_read;
while (bytes_read - packet_end >= 1) {
const nodes_len: u16 = buffer[packet_end];
const packet_len = 1 + nodes_len * (@sizeOf(Node.Storage) + @sizeOf(Node.Parent));
if (packet_end + packet_len > bytes_read) break;
packet_start = packet_end;
packet_end += packet_len;
}
return .{ packet_start, packet_end };
}
fn rebase(
data: *Data,
buffer: *[max_packet_len]u8,
vec: *[1][]u8,
batch: *std.Io.Batch,
slot: Slot,
packet_end: u16,
) void {
assert(data.state == .ready);
const remaining = buffer[packet_end..data.bytes_read];
@memmove(buffer[0..remaining.len], remaining);
vec.* = .{buffer[remaining.len..]};
batch.addAt(slot, .{ .file_read_streaming = .{
.file = global_progress.ipc_files[slot],
.data = vec,
} });
data.state = .pending;
data.bytes_read = @intCast(remaining.len);
}
};
}