Expand description
Structured message envelope for IndexBus.
This crate defines a small, versioned, bytes-on-wire header designed to live at the start of
Slot.data[..].
§Contracts and invariants
- The v1 envelope is little-endian and begins with
MAGIC. - The header is designed to be append-only over time.
decode_headeracceptsheader_len >= V1_HEADER_LENand ignores any appended bytes it does not understand. encode_header_intocurrently only emits the minimum v1 header (header_len == V1_HEADER_LEN).header_len + payload_lenis validated to be withinSLOT_CAPACITY.
This crate intentionally does not interpret payload bytes. Fields such as codec_id,
schema_id, and msg_type are treated as application-defined identifiers.
§Error semantics
- Decode helpers validate structural properties (magic, lengths, known flags).
- Decode helpers do not attempt to authenticate the payload or validate codec-specific formats.
flagsare treated as declarative metadata; the helpers reject unknown bits for deterministic behavior.
§Features
- Default:
no_std. alloc: reserved for future heap-backed conveniences.std: enablesstd-only trait impls (e.g.std::error::Error) and impliesalloc.
§Minimal v1 encode/decode
use indexbus_msg::{decode_header, encode_header_into, Header, V1_HEADER_LEN};
let payload = b"hello";
let hdr = Header {
flags: 0,
codec_id: 0,
header_len: V1_HEADER_LEN as u8,
schema_id: 1,
msg_type: 42,
msg_version: 1,
payload_len: payload.len() as u16,
};
let mut buf = [0u8; 64];
let n = encode_header_into(&mut buf, hdr).unwrap();
buf[n..(n + payload.len())].copy_from_slice(payload);
let (parsed, parsed_payload) = decode_header(&buf[..(n + payload.len())]).unwrap();
assert_eq!(parsed, hdr);
assert_eq!(parsed_payload, payload);Modules§
Structs§
- Header
- Parsed v1 envelope header.
Enums§
- Error
- Errors returned by v1 envelope encode/decode helpers.
Constants§
- MAGIC
- Envelope magic for v1 (“USM1”).
- SLOT_
CAPACITY - Absolute maximum bytes available per slot.
- V1_
HEADER_ LEN - Minimum v1 header length in bytes.
Functions§
- decode_
header - Decode a v1 header from
input. - encode_
header_ into - Encode a v1 header into
out. - max_
payload_ len_ v1 - Maximum payload length for a v1 message, excluding any optional appended fields.