Skip to main content

Module encoding

Module encoding 

Source
Expand description

Canonical binary encoding of signed objects (specification §3.1, ADR-0006).

TypeEncoding
u8…u64fixed width, big-endian
bool0x00 / 0x01; anything else is an error
bytes[N]exactly N bytes
bytes, stringu32 length, then the bytes (strings: valid UTF-8, not normalised)
option<T>0x00, or 0x01 then T
list<T>u32 count, then each element

Every variable field has a limit, enforced by both the Writer and the Reader, so a value that encodes also decodes. A length or count is checked against the limit and the remaining input before anything is allocated. There is exactly one encoding per value.

Structs§

Reader
Reads canonical encodings from a byte slice. Lengths and counts are checked against the field’s limit and the remaining input before anything is allocated.
Writer
Appends canonical encodings to a buffer. Variable fields take their limit and fail above it, mirroring super::Reader.

Enums§

DecodeError
The input is not a canonical encoding (specification §3.1).
EncodeError
A value cannot be encoded canonically: it would not decode.

Traits§

Decode
A type with a canonical decoding.
Encode
A type with a canonical encoding (fixed-size or self-limiting).

Functions§

from_bytes
Decodes a top-level value, rejecting trailing bytes.
to_bytes
Encodes a top-level value.