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_error;
17mod decoder;
18mod decoder_ref;
19mod decoder_straight;
20pub(crate) mod interner;
21mod layout;
22pub mod tag;
23#[cfg(test)]
24mod tests;
25mod varint;
26pub(crate) mod writer;
27
28pub use codec::{decode, decode_ref, encode};
29pub use decode_error::DecodeError;
30pub use decoder::Decoder;
31pub use layout::{MAGIC, MAX_DEPTH, VERSION};
32pub(crate) use layout::{NEW_STRING, STREAM_LEN_BYTES};
33pub(crate) use varint::{
34 VARINT_BITS, VARINT_LAST_SHIFT, VARINT_MAX_SHIFT, VARINT_MORE, VARINT_SHIFT, read_varint,
35 unzigzag, varint, zigzag,
36};
37pub use writer::Writer;