Skip to main content

Module codec

Module codec 

Source
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§

Reader
Bounds-checked read cursor over a Bytes buffer.

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 i16 count prefix.
count_i32
Converts a collection length into an i32 count prefix.
count_u8
Converts a collection length into a u8 count 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 v as a VarInt into a fixed buffer; returns the buffer and the used length.
varint_len
Number of bytes the VarInt encoding of v takes (1..=5).

Type Aliases§

DecodeResult
Result alias for decoding.
EncodeResult
Result alias for encoding.