sim: port the .bctrace TraceWriter (NDJSON trace subsystem)#67
Merged
Conversation
Ports `sim/trace_writer.go`'s `TraceWriter` to `src/sim/trace_writer.zig`: a compact NDJSON `.bctrace` writer — header line, one JSON-array tuple per event, and a footer carrying a 100 ms time index. Byte layout, field order, event-row shape, and index cadence match the Go reference, locked down by golden-byte tests captured from the Go writer. Adaptations (documented in the module): output accumulates into an owned byte buffer rather than Go's `io.Writer`+`bufio` sink, and `t0` / `topology` / `config` enter as caller-provided raw values (the Zig sim has no `time.Time` or reflective `json.Marshal`). The event-code table for the `TracingObserver` wrapper is exported for a follow-up once the broadcast `Observer` interface lands (#58). Refs #59.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #59.
Ports the Go sim's
.bctracetrace subsystem —sim/trace_writer.goTraceWriter— tosrc/sim/trace_writer.zig. There was no Zig counterpart (tracematched nothing undersrc/).What it does
A compact NDJSON writer:
v,t0,nodes,topology,config, optionaldecoderName/peer_ids)[usec, node, ev, args…]{ts, byte-offset}pairs)Byte layout, field order, event-row shape, and the index cadence match the Go reference, locked down by golden-byte tests captured from the Go writer (same inputs as Go's
TestTraceWriter_RoundTrip), including the JSON string escaping (",\, control chars, and the</>/&HTML-escape thatencoding/jsonapplies by default).Adaptations (documented in the module header)
bytes()) rather than Go'sio.Writer+bufiosink — observable bytes are identical.t0/topology/configenter as caller-provided raw values (RFC3339 string + raw JSON), since the Zig sim has notime.Timeor reflectivejson.Marshal. The event-code table for theTracingObserverwrapper is exported for a follow-up once the broadcastObserverinterface lands (broadcast: implement Observer interface callbacks + SessionRole enum #58).Verification
zig fmt --checkandzig build testpass on stock Zig 0.16.0 (7 golden/behaviour tests in the module).