feat(capture): OCPP-J live frame decode → canonical events#62
Merged
Conversation
Decode one WebSocket text frame into a canonical engine Event. Live direction is known from the socket (which peer sent the frame), so it is set explicitly and `unknown` never arises — an accuracy win over the offline two-pass inference; the timestamp is the wall-clock receipt time. Otherwise decode mirrors the offline pipeline exactly — the same schema gate (parser.validateRawMessage) and the same normalizer field extraction — so a recorded frame re-parses to the same event offline. A parity test proves the round-trip (decode -> JSONL record -> offline parseTrace -> identical event), the portability the recorder (#56) and the conformance contract rest on. Exposes two pure engine helpers the decoder reuses (parser.validateRawMessage, normalizer.messageIdOf). Untrusted input is bounded (10 MiB per message, matching the engine's ceiling); malformed frames return a typed error the caller records/skips rather than aborting the session. Closes #55.
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 #55. Second issue of S5 — Live capture (builds on #54).
Summary
src/capture/decode.zigturns one WebSocket text frame into a canonical engineEvent. The key difference from the offline parser: live direction is knownfrom the socket (which peer sent the frame), so it's set explicitly and
unknownnever arises — an accuracy win over the offline two-pass inference. Thetimestamp is the wall-clock receipt time (live frames carry no message-level
timestamp of their own).
Everything else mirrors the offline pipeline exactly — the same schema gate
(
parser.validateRawMessage) and the same normalizer field extraction — so arecorded frame re-parses to the same event offline. That portability is what
the recorder (#56) and the shared conformance contract rest on.
Parity anchor
A test proves the full round-trip:
decodeEvent→ JSONL object record(
{timestamp, direction, message}) → offlineparseTrace→ identical event(id, message_id, type, action, direction, timestamp, payload). Recording detail
surfaced here and noted for #56:
received_msis epoch milliseconds, andreal wall-clock is always ≥ 10¹², so it survives the offline normalizer's
seconds/ms threshold unchanged.
Reuse, not duplication
Exposes two pure engine helpers the decoder shares with the offline path:
parser.validateRawMessageandnormalizer.messageIdOf(bothfn→pub fn).No logic is re-implemented.
Hardening (untrusted input)
before parsing — live and offline reject the same oversized messages.
InvalidJson/NotOcppJMessage) return a typed error thecaller records/skips, never aborting the session.
Tests
6 new (144 total, up from 138): Call/CallResult/CallError decode with
socket-direction, direction-not-inferred, every rejection path, oversize, and the
offline-parity round-trip.
Verification
native test -Dplatform=null→ 144/144.native build(ReleaseFast) → clean.zig fmt --checkclean.