Skip to main content

Module traits

Module traits 

Source
Expand description

Core traits implemented by every encodable value.

Encode writes a value into a WriteBuf; Decode reads one out of a ReadBuf. The traits are deliberately minimal so callers can compose them with any framing strategy in the framing module.

§Provided implementations

TypeWire form
u8, i8one byte
boolone byte, 0 or 1; any other byte decodes as Error::InvalidEncoding
[u8; N]N raw bytes (copied on decode)
&'de [u8; N]N raw bytes (zero-copy decode)
[u8]raw bytes, encode only (the length must be framed separately)
Be<T> / Le<T>T in big / little endian, for every integer from u16 to i128, and f32 / f64
Varint<T>LEB128 varint for u16, u32, u64, usize; zigzag varint for i32, i64
(A, B) up to (A, B, C, D, E, F)the elements in order

Multi-byte integers have no plain Encode impl on purpose: the byte order is part of the wire format, so it must be chosen explicitly with a wrapper.

Tuples restore the cursor to where the tuple started if any element fails. They check the total encoded_size against the remaining room first, so a short buffer is reported as Error::BufferFull before anything is written, and before any element gets the chance to report a different error. If a later element fails for another reason (a packed field out of range, say), the bytes of the earlier elements remain behind the restored cursor.

Structs§

Be
Big-endian wrapper: encodes and decodes T most significant byte first.
Le
Little-endian wrapper: encodes and decodes T least significant byte first.
Varint
LEB128 varint wrapper. Signed integers use the zigzag mapping, matching protobuf’s sint32 / sint64.

Traits§

Decode
A value that can be read from a ReadBuf.
Encode
A value that can be written to a WriteBuf.