diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/core/dump.zig b/core/dump.zig index 82098449..547f9f7d 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -261,7 +261,8 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { /// on every side: panes.reloadTerminals), its sequence in flight with it. /// What is left is the session's mutable state, made in its step. With it /// the session's digest at that moment, which the client checks its load -/// by. +/// by, and after it that digest a field at a time (`joinParts`), which +/// names what a load that is not the session has otherwise. /// /// One moment: nothing in it gives up the turn (pardes.turn: a host call /// does, tape.out), or a 9P request answered meanwhile is in the dump and @@ -281,6 +282,22 @@ pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) !s return .{ .bytes = bytes, .digest = pardes.tape.digestOf(p) }; } +/// What a join's dump ends with: the session's digest a field at a time +/// (tape.digestParts), their count, this word. +const parts_word = "parts\x00\x00\x01"; + +/// The session's digest a field at a time that a join's dump `bytes` ends +/// with, in `gpa`; null for a dump with none. +pub fn joinParts(gpa: std.mem.Allocator, bytes: []const u8) ?[]u64 { + const tail = parts_word.len + 8; + if (bytes.len < tail or !std.mem.endsWith(u8, bytes, parts_word)) return null; + const n = std.mem.bytesToValue(u64, bytes[bytes.len - tail ..][0..8]); + if (n > (bytes.len - tail) / 8) return null; + const out = gpa.alloc(u64, @intCast(n)) catch return null; + @memcpy(std.mem.sliceAsBytes(out), bytes[bytes.len - tail - out.len * 8 ..][0 .. out.len * 8]); + return out; +} + /// `dumpExit`'s: a terminal dumps its size, not its emulator. pub var slim_terminals = false; /// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file), @@ -307,6 +324,13 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 } const kept: []const views.Shares = others; try d.put([]const views.Shares, &kept); + const parts = try p.gpa.create(pardes.tape.Parts); + defer p.gpa.destroy(parts); + const each = pardes.tape.digestParts(p, parts); + const w = &d.out.writer; + try w.writeAll(std.mem.sliceAsBytes(each)); + try w.writeAll(std.mem.asBytes(&@as(u64, each.len))); + try w.writeAll(parts_word); return d.finish(); } |
