Skip to main content

Module envelope

Module envelope 

Source
Expand description

Versioned network message envelope (spec section 4.10, S1D-001).

Every message on every MongrelDB wire protocol travels inside a ProtocolEnvelope, never as an unversioned payload. The canonical encoding is:

protocol_version : u32 LE
message_type     : u32 LE
payload_len      : u32 LE
payload          : [u8; payload_len]
payload_crc32    : u32 LE

The CRC-32 (IEEE, reflected) covers the protocol version, the message type, the payload length, and the payload. This mirrors the fail-closed shape of mongreldb-log’s CommandEnvelope: unknown protocol versions, oversized payloads, truncated frames, trailing bytes, and checksum mismatches are all decode errors (spec section 4.10: unknown required fields or incompatible versions fail closed).

Unlike CommandEnvelope the checksum is a CRC-32 rather than SHA-256: this crate’s dependency set is frozen (serde, thiserror, mongreldb-types), and transport integrity plus peer authentication are provided by TLS 1.3 (S1D-002), so the checksum’s job here is only framing sanity, not cryptographic authentication.

Encoding is deterministic: ProtocolEnvelope::encode is a pure function of the envelope fields, so equal envelopes produce byte-identical frames and decode(encode(e)) is the identity.

Payload evolution rules (spec section 4.10):

  • message_type discriminants and payload field numbers are never reused; new message types are allocated fresh numbers.
  • The envelope never interprets payload bytes; payload decoding is the adapter’s job (Protobuf control frames, Arrow IPC result frames, per S1D-002 and ADR 0005).
  • Unknown protocol versions fail closed with EnvelopeError::UnsupportedVersion.

Structs§

ProtocolEnvelope
The versioned, checksummed form of every protocol message.

Enums§

EnvelopeError
Errors produced while verifying or decoding a ProtocolEnvelope.

Constants§

CHECKSUM_LEN
Encoded length of the trailing checksum.
HEADER_LEN
Encoded length of the fixed header preceding the payload.
MAX_MESSAGE_PAYLOAD_BYTES
Upper bound on a single message payload.
MIN_SUPPORTED_PROTOCOL_VERSION
The oldest protocol version this build accepts.
PROTOCOL_VERSION
The protocol version this build writes.