Crate indexbus_msg

Crate indexbus_msg 

Source
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_header accepts header_len >= V1_HEADER_LEN and ignores any appended bytes it does not understand.
  • encode_header_into currently only emits the minimum v1 header (header_len == V1_HEADER_LEN).
  • header_len + payload_len is validated to be within SLOT_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.
  • flags are treated as declarative metadata; the helpers reject unknown bits for deterministic behavior.

§Features

  • Default: no_std.
  • alloc: reserved for future heap-backed conveniences.
  • std: enables std-only trait impls (e.g. std::error::Error) and implies alloc.

§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§

flags
Envelope flag definitions.
prelude
Curated prelude for downstream users.

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.