Skip to content

5.4 Canonical Wire v1 Encoding

Wiki Keeper (Grok Bot) edited this page Oct 15, 2026 · 1 revision

Canonical Wire-v1 Encoding

Deterministic, validated encoding for wire-version-1 IpcMessage envelopes. Public API: encode_canonical_ipc_message → Result<Vec<u8>, CanonicalEncodeError>. Normative spec (also in the crates.io package): docs/wire-encoding.md. Helpers live in src/canonical_ser.rs.

This is the corpus-ipc project wire profile. It is not RFC 8785 / JCS.

Pipeline

  1. message.validate() — fail closed (CanonicalEncodeError::Validation); non-finite floats never become JSON null.
  2. Wrap in WireEnvelope with wire_version = WireCompatibility::CURRENT (1).
  3. Serialize via serialize_f32_as_f64 so finite f32 values are emitted as widened f64 decimals (stable under consumer serde_json arbitrary_precision unification).
  4. Value::sort_all_objects() — recursive byte-wise key sort at every nesting depth (correct even if a consumer enables preserve_order).
  5. Compact serde_json::to_vec (no insignificant whitespace).

Envelope shape (keys sorted, so payload precedes wire_version):

{"payload":<payload>,"wire_version":1}

Struct variants are externally tagged objects; unit variants are JSON strings ("Ping", "Shutdown", "TrainingComplete").

ConfigValue note

ConfigValue stays Float-first on the wire: Integer(42) round-trips as Float(42.0); integers above 2^24 can lose identity on an f32 round-trip. Documented in the wire spec and locked by normalization goldens / properties.

Errors

Variant Meaning
CanonicalEncodeError::Validation(ValidationError) Validate failed before serialization
CanonicalEncodeError::Json(...) serde_json failure after validation

Decode path remains decode_ipc_message_json / decode_ipc_message_value (see 5.3). Prefer the canonical encoder for new fixtures; never regenerate legacy / negative vectors through it.

Related tests

Clone this wiki locally