Expand description
Canonical binary encoding of signed objects (specification §3.1, ADR-0006).
| Type | Encoding |
|---|---|
u8…u64 | fixed width, big-endian |
bool | 0x00 / 0x01; anything else is an error |
bytes[N] | exactly N bytes |
bytes, string | u32 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§
- Decode
Error - The input is not a canonical encoding (specification §3.1).
- Encode
Error - 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.