substrate_data/wire/binary/mod.rs
1//! The binary form — self-describing, compact: what a build compiles
2//! content to, what saves and caches are kept in, what a reader that
3//! doesn't know the schema can still walk. `docs/format.md` ("Binary form")
4//! has the layout: a header (`SDAT`, a version byte), then the root value,
5//! a tag byte and its payload. A string is written where it's first used
6//! and referred to after that, so repeated keys and ids cost one varint
7//! each and the writer never goes back over what it wrote.
8//!
9//! Nothing is aligned, and decoding checks every length against the
10//! input, so malformed bytes are an error, never a panic or a huge
11//! allocation. A [`crate::Schema`] writes itself here straight
12//! ([`crate::Schema::encode`]) and reads itself back the same way
13//! ([`crate::Schema::decode`]) — no value tree on the way.
14
15mod codec;
16mod decode;
17mod layout;
18pub(crate) mod table;
19pub mod tag;
20#[cfg(test)]
21mod tests;
22mod varint;
23mod write;
24
25pub use codec::{decode, decode_ref, encode, encode_into, upgrade};
26pub use decode::{DecodeError, Decoder};
27pub use layout::{
28 INLINE_INT_MAX, INLINE_INT_MIN, LEGACY_VERSION, MAGIC, MAX_DEPTH, NEW_STRING, STR_INDEX_COUNT,
29 STREAM_LEN_BYTES, VERSION,
30};
31pub(crate) use varint::{
32 VARINT_BITS, VARINT_LAST_SHIFT, VARINT_MAX_SHIFT, VARINT_MORE, VARINT_SHIFT, read_varint,
33 unzigzag, varint, zigzag,
34};
35pub use write::Writer;
36pub(crate) use write::writer;