Expand description
The binary form — self-describing, compact: what a build compiles
content to, what saves and caches are kept in, what a reader that
doesn’t know the schema can still walk. docs/format.md (“Binary form”)
has the layout: a header (SDAT, a version byte), then the root value,
a tag byte and its payload. A string is written where it’s first used
and referred to after that, so repeated keys and ids cost one varint
each and the writer never goes back over what it wrote.
Nothing is aligned, and decoding checks every length against the
input, so malformed bytes are an error, never a panic or a huge
allocation. A crate::Schema writes itself here straight
(crate::Schema::encode) and reads itself back the same way
(crate::Schema::decode) — no value tree on the way.
Modules§
- tag
- A value’s first byte: what it is.
Structs§
- Decode
Error - Malformed binary data.
- Decoder
- Reads the binary form. The step-by-step reads (
Decoder::int,Decoder::map…) answerNonefor anything but whatcrate::Schema::encodewrites there — the schema then reads the slow way, which says what’s wrong. - Writer
- Writes the binary form piece by piece, from data that isn’t a
Value— nothing is built or copied on the way. A map or list is given its length, then that many entries (keythen a value) or values.
Constants§
- MAGIC
- What a binary file starts with.
- MAX_
DEPTH - Nested deeper than this is malformed.
- NEW_
STRING - A string’s varint: a new one’s (odd, its length) or a reference to the table (even, its index).
- STREAM_
LEN_ BYTES - A stream’s length: fixed width, so the writer fills it in after its items.
- VERSION
- The version of the form after the magic.
Functions§
- decode
- Reads the binary form.
- decode_
ref - Reads the binary form borrowed: every string points into
bytes, lists and maps go inarena— nothing is copied. - encode
valuein the binary form.- encode_
into valuein the binary form, appended toout(a whole document, header first): a buffer that is kept and reused grows once.