Terminalwire.Codec (Terminalwire v0.1.0)

Copy Markdown View Source

Pure bytes <-> frame conversion. A frame is a map with string keys (the wire shape). No I/O, no transport — the sans-IO seam the conformance corpus exercises directly. Mirrors Terminalwire::V2::Codec.

Wire format is MessagePack. One subtlety that matters for cross-language interop: binary payloads (e.g. data.bytes) must be encoded as MessagePack bin, not str, or the Go client's []byte decode fails. Callers pass such fields wrapped in Msgpax.Bin (see Terminalwire.Frames.data/2).

Summary

Functions

Decode MessagePack bytes for exactly one frame. Returns the frame map (string keys). Raises ProtocolError for anything that isn't a well-formed frame. bin values come back wrapped in Msgpax.Bin (binary: true) so a decode then re-encode preserves the MessagePack bin type instead of degrading to str; consumers unwrap them before use (see Terminalwire.Server.Session).

Encode a frame map to MessagePack bytes (a binary).

Functions

decode(bytes)

Decode MessagePack bytes for exactly one frame. Returns the frame map (string keys). Raises ProtocolError for anything that isn't a well-formed frame. bin values come back wrapped in Msgpax.Bin (binary: true) so a decode then re-encode preserves the MessagePack bin type instead of degrading to str; consumers unwrap them before use (see Terminalwire.Server.Session).

encode(frame)

Encode a frame map to MessagePack bytes (a binary).

Note: msgpack map key order is unspecified, so the exact byte sequence may differ from another implementation's encoding of the same frame — that is fine and fully interoperable. The contract is that every implementation decodes the canonical golden bytes identically, and that what one encodes another decodes correctly. We do not promise byte-identical encoding across languages.