reliakit_codec/format.rs
1//! Canonical binary format rules.
2//!
3//! Version 0.1 intentionally defines one binary representation per supported
4//! value:
5//!
6//! - integers are fixed-width little-endian,
7//! - `bool` is exactly `0x00` or `0x01`,
8//! - strings are UTF-8 bytes prefixed by a `u32` little-endian byte length,
9//! - vectors are prefixed by a `u32` little-endian item count,
10//! - `Option<T>` and `Result<T, E>` use one-byte tags,
11//! - fixed arrays and tuples encode fields in declaration order.
12//!
13//! Floats, pointer-sized integers, hash maps, unordered maps, schema
14//! negotiation, and non-canonical alternatives are not part of this initial
15//! format. They are omitted because their representation or ordering can be
16//! platform-dependent, ambiguous, or outside this crate's first-version scope.
17//!
18//! The vector length prefix is an item count, not a byte length. Decoding a
19//! vector performs work proportional to that count. For element types that
20//! decode from zero bytes (such as `[u8; 0]`), the declared count is therefore
21//! not bounded by the remaining input length; only decode lengths you are
22//! willing to iterate over from untrusted sources, or frame such inputs before
23//! decoding.
24//!
25//! Generic fixed-array decoding (`[T; N]`) requires the `alloc` feature in this
26//! version because the crate forbids unsafe code and Rust 1.85 does not provide
27//! a stable fallible array initializer. In no-alloc builds, `[u8; N]` decoding is
28//! available because it can be filled directly from the source without heap
29//! allocation.
30
31/// Tag used for `false`.
32pub const BOOL_FALSE: u8 = 0x00;
33/// Tag used for `true`.
34pub const BOOL_TRUE: u8 = 0x01;
35/// Tag used for `None`.
36pub const OPTION_NONE: u8 = 0x00;
37/// Tag used for `Some`.
38pub const OPTION_SOME: u8 = 0x01;
39/// Tag used for `Ok`.
40pub const RESULT_OK: u8 = 0x00;
41/// Tag used for `Err`.
42pub const RESULT_ERR: u8 = 0x01;