Expand description
Low-level reading and writing of protocol primitives.
Reader is a bounds-checked cursor over a Bytes buffer: every read returns
Result, and variable-length data (Reader::read_bytes, strings) is returned as
zero-copy slices of the underlying buffer. McWrite adds the protocol’s primitive
encodings to BytesMut.
The Decode / Encode traits are implemented by every packet and shared type.
Structs§
Constants§
- PREALLOC_
LIMIT - Upper bound on the capacity reserved up front for a decoded array; larger arrays grow as elements are actually decoded, so a hostile count cannot force a big allocation.
- ZERO_
SIZE_ ELEMENT_ LIMIT - Largest count accepted for arrays whose elements can be zero bytes long.
Traits§
- Decode
- A value that can be decoded from protocol bytes.
- Encode
- A value that can be encoded to protocol bytes.
- McWrite
- Protocol primitive encodings on top of
BytesMut.
Functions§
- count_
i16 - Converts a collection length into an
i16count prefix. - count_
i32 - Converts a collection length into an
i32count prefix. - count_
u8 - Converts a collection length into a
u8count prefix. - decode_
exact - Decodes a complete value from
buf, failing if any bytes are left over. - encode_
to_ bytes - Encodes a value into a fresh buffer.
- read_
varint_ prefix - Decodes a VarInt from the start of a plain slice. Returns the value and its length.
- varint_
bytes - Encodes
vas a VarInt into a fixed buffer; returns the buffer and the used length. - varint_
len - Number of bytes the VarInt encoding of
vtakes (1..=5).
Type Aliases§
- Decode
Result - Result alias for decoding.
- Encode
Result - Result alias for encoding.