Skip to main content

Module binary

Module binary 

Source
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§

DecodeError
Malformed binary data.
Decoder
Reads the binary form. The step-by-step reads (Decoder::int, Decoder::map …) answer None for anything but what crate::Schema::encode writes 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 (key then 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 in arena — nothing is copied.
encode
value in the binary form.
encode_into
value in the binary form, appended to out (a whole document, header first): a buffer that is kept and reused grows once.