Value encoding
Slots
All scalar values cross the Rust API as Slot(u64):
- unsigned integers are zero-extended;
- signed integers are sign-extended by
as u64; boolis 0 or 1;f32isf32::to_bits() as u64;f64isf64::to_bits();- an enum is its zero-based variant index.
Value wraps a scalar slot, a list of slots, or a UTF-8 string. A decoded field
also carries a Validity.
Final values and quantisation
For a field with quantise: step, the sender computes
q = round_half_away_from_zero(v / step). If range: [lo, hi] is declared, the
quantised bounds are round(lo / step) and round(hi / step) and q is clamped
to them. Otherwise q is clamped to the signed range of the wire width. Clamping
sets bound_applies = false for that field and frame.
The receiver emits the final value:
- quantised field:
cast(q * step); - unquantised field:
cast(v); f32: round tof32, then widen tof64;- integer: round half away from zero, then saturate to the type’s range;
bool:1.0whenx >= 0.5, otherwise0.0.
Both ends update their predictors with final values, never with raw input. That is what makes the tolerance check meaningful: it compares the sender’s true value as the receiver would emit it with the value the receiver actually emits.
Wire widths
| Field kind | Width and content |
|---|---|
Quantised with range | max(1, ceil_log2(q_hi - q_lo + 1)) bits, unsigned q - q_lo |
Quantised without range | signed q: 32 bits for f32, 64 bits for f64, type width for integers |
| Not quantised | raw bits: bool 1, integer width, f32 32, f64 64 |
| Enum | max(1, ceil_log2(n_variants)) bits, unsigned variant index |
ceil_log2(1) is 0, so a single variant uses one bit by the max(1, …) rule.
An index at or above the variant count is Malformed on decode.
Strings and lists
A variable-length field starts with an unsigned 16-bit length, LSB first. A string’s length counts UTF-8 bytes; a list’s length counts elements. Elements are bit-packed with no byte alignment and use the rules of their element type; quantisation and range apply to every list element.
Empty strings and lists are valid. The encoder rejects a value longer than
max_len with TooLong. The decoder rejects a wire length above max_len, an
element count whose bits would overrun the frame, and invalid UTF-8 as
Malformed. These checks happen before allocation or state mutation.
Non-finite values
NaN and infinities are rejected by the encoder with
EncodeError::NonFinite(field_index) and leave encoder state unchanged. Custom
callback predictors must also return finite predictions; check_predictor
checks this property.