Skip to main content

Module frame

Module frame 

Source
Expand description

Frames: data packed for messages — both sides know the schema, so nothing says what a value is or what it’s called. A record’s fields go in the order they’re declared, after the record’s length (so a reader that knows fewer fields skips the rest; one that knows more takes their defaults: fields are only ever appended). Strings go in a table at the end, each once; the body refers to them by index. docs/format.md (“Frames”) has the layout of every value.

Nothing is aligned, every value takes at least a byte (a count is checked against the bytes left), and a malformed frame reads as None, never a panic.

#[derive(substrate_data::Schema, Debug, PartialEq)]
struct Hit { id: String, count: u32, ratio: f32, next: Option<Box<Hit>> }

let hit = Hit { id: "docs/intro".into(), count: 3, ratio: 0.5, next: None };
let frame = substrate_data::frame::to_frame(&hit);
assert_eq!(substrate_data::frame::read_frame::<Hit>(&frame), Some(hit));

Modules§

floats
A frame’s lists of floats, four at a time: whether a list of f64 is f32 exactly (then it’s kept as f32s, half the bytes), the narrowing and the widening back — AVX2 where the processor has it, chosen once; the same bytes either way.
lanes
Numbers bit-packed in lanes: what a frame’s list of ints is made of.

Structs§

Floats
A list of floats, read in place.
Ints
A packed list of ints, read in place: Ints::get takes one out of the bits.
List
A list of anything but numbers, read lazily: its bytes and how many items — each viewed as it’s reached (List::iter), nothing allocated.
ListIter
List::iter.
Packer
Writes a frame.
Unpacker
Reads a frame. Every read answers None for bytes that aren’t what Packer writes there.

Traits§

FromF64
A float out of a f64 (a f32 rounds).
View
A type read as a view of a frame: what it is borrowed (View), and what a list of it is (ListView).

Functions§

list
A list (super::Packer::begin_list) as a List: stepped over, read later.
read_frame
A T out of a frame; None if the frame isn’t one.
read_shaped
The frame bytes read as a value of shape.
read_view
T’s view of the frame bytes.
to_frame
v as a frame.
unpack_shaped
The next value, of shape.