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
f64isf32exactly (then it’s kept asf32s, 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::gettakes 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. - List
Iter List::iter.- Packer
- Writes a frame.
- Unpacker
- Reads a frame. Every read answers
Nonefor bytes that aren’t whatPackerwrites there.
Traits§
- FromF64
- A float out of a
f64(af32rounds). - 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 aList: stepped over, read later. - read_
frame - A
Tout of a frame;Noneif the frame isn’t one. - read_
shaped - The frame
bytesread as a value ofshape. - read_
view T’s view of the framebytes.- to_
frame vas a frame.- unpack_
shaped - The next value, of
shape.