pub trait Decode: Sized {
// Required method
fn decode(buf: &mut &[u8]) -> Result<Self>;
}Expand description
Deserialize a value from a byte slice, advancing the cursor.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Decode for bool
Decodes a boolean from a single byte in the Minecraft protocol.
impl Decode for bool
Decodes a boolean from a single byte in the Minecraft protocol.
Any non-zero byte is interpreted as true, matching the Minecraft
server behavior. This is intentionally lenient — the protocol spec
says 0x01 for true, but servers may send other non-zero values.
Source§impl Decode for f32
Decodes from a fixed-size big-endian value.
impl Decode for f32
Decodes from a fixed-size big-endian value.
Reads exactly 4 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for f64
Decodes from a fixed-size big-endian value.
impl Decode for f64
Decodes from a fixed-size big-endian value.
Reads exactly 8 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for i8
Decodes from a fixed-size big-endian value.
impl Decode for i8
Decodes from a fixed-size big-endian value.
Reads exactly 1 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for i16
Decodes from a fixed-size big-endian value.
impl Decode for i16
Decodes from a fixed-size big-endian value.
Reads exactly 2 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for i32
Decodes from a fixed-size big-endian value.
impl Decode for i32
Decodes from a fixed-size big-endian value.
Reads exactly 4 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for i64
Decodes from a fixed-size big-endian value.
impl Decode for i64
Decodes from a fixed-size big-endian value.
Reads exactly 8 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for u8
Decodes from a fixed-size big-endian value.
impl Decode for u8
Decodes from a fixed-size big-endian value.
Reads exactly 1 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for u16
Decodes from a fixed-size big-endian value.
impl Decode for u16
Decodes from a fixed-size big-endian value.
Reads exactly 2 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for u32
Decodes from a fixed-size big-endian value.
impl Decode for u32
Decodes from a fixed-size big-endian value.
Reads exactly 4 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for u64
Decodes from a fixed-size big-endian value.
impl Decode for u64
Decodes from a fixed-size big-endian value.
Reads exactly 8 bytes from the buffer and interprets them as big-endian.
Source§impl Decode for String
Decodes a Minecraft protocol string into a Rust String.
impl Decode for String
Decodes a Minecraft protocol string into a Rust String.
Reads a VarInt byte length, validates it against the 32767-byte limit, then reads that many bytes and validates them as UTF-8. Multi-byte UTF-8 characters (accented letters, emoji, CJK) are handled correctly since the length prefix counts bytes, not characters.
Source§fn decode(buf: &mut &[u8]) -> Result<Self>
fn decode(buf: &mut &[u8]) -> Result<Self>
Reads the VarInt length prefix, then the UTF-8 payload.
Fails with Error::StringTooLong if the declared length exceeds
32767 bytes, Error::BufferUnderflow if the buffer is shorter than
the declared length, or Error::InvalidUtf8 if the bytes are not
valid UTF-8.
Source§impl Decode for Vec<u8>
Decodes a Minecraft protocol byte array into a Vec<u8>.
impl Decode for Vec<u8>
Decodes a Minecraft protocol byte array into a Vec<u8>.
Reads a VarInt byte length, then reads exactly that many bytes from the buffer. No validation is performed on the byte content — the caller is responsible for interpreting the data.
Implementors§
impl Decode for NbtTag
Decodes an NbtTag from network NBT format.
The root is always expected to be a Compound tag. This delegates to
NbtCompound::decode and wraps the result in NbtTag::Compound.
impl Decode for NbtCompound
Decodes an NbtCompound from network NBT format.
Since Minecraft 1.20.3, network NBT uses a simplified root format: a compound tag type byte (0x0A) followed directly by the compound payload (no root tag name). This differs from the traditional NBT format which includes a root tag name.
Fails if the root tag type is not Compound (0x0A).
impl Decode for Angle
Decodes an Angle from a single unsigned byte.
Reads exactly one byte. Any byte value is valid — the full 0-255 range maps to 0-360 degrees.
impl Decode for BitSet
Decodes a BitSet from a VarInt-prefixed array of big-endian i64 values.
Reads the VarInt count, then that many 8-byte big-endian i64 values. Fails if the buffer doesn’t contain enough bytes for the declared number of longs.
impl Decode for Identifier
Decodes an Identifier from a VarInt-prefixed UTF-8 string.
Reads the string using the standard Minecraft string decoding, then
parses it as namespace:path. If no colon is present, the namespace
defaults to minecraft. Validates that all characters are in the
allowed sets for namespace and path.
impl Decode for OpaqueBytes
impl Decode for Position
Decodes a Position from a packed 64-bit big-endian integer.
Reads 8 bytes as a big-endian i64, then unpacks x (26 bits),
z (26 bits), and y (12 bits) with proper sign extension for
negative coordinates.
impl Decode for Slot
Decodes a Slot from the Minecraft protocol format.
Reads the item count. If zero, returns an empty slot. Otherwise reads
the item ID and component counts. Items with zero components decode
cleanly, allowing correct Vec<Slot> support. Items with components
store the raw component data as opaque bytes until a full component
parser is implemented.
impl Decode for TextComponent
Decodes a TextComponent from network NBT (compound tag).
Reads a network NBT compound, then parses it into a TextComponent tree. Handles all content types (text, translate, keybind, score, selector), all style fields, click/hover events, and recursive extra children.
impl Decode for Uuid
Decodes a UUID from two consecutive big-endian u64 values (16 bytes).
Reads the most significant 64 bits first, then the least significant 64 bits. Fails if fewer than 16 bytes remain in the buffer.
impl Decode for VarInt
Decodes a VarInt by reading 1-5 bytes from the buffer.
Reads bytes one at a time, accumulating 7-bit groups until a byte
without the continuation bit is found. If more than 5 bytes have
the continuation bit set, the value would exceed 32 bits and the
decoder returns Error::VarIntTooLarge. If the buffer runs out
mid-VarInt, returns Error::BufferUnderflow.
impl Decode for VarLong
Decodes a VarLong by reading 1-10 bytes from the buffer.
Same algorithm as VarInt decoding but allowing up to 10 bytes
(64 bits). Returns Error::VarIntTooLarge if more than 10 bytes
carry continuation bits, Error::BufferUnderflow if the buffer
ends mid-value.
impl Decode for Vec2f
Decodes a Vec2f from two consecutive big-endian f32 values.
impl Decode for Vec3f64
Decodes a Vec3f64 from three consecutive big-endian f64 values.
impl Decode for Vec3f
Decodes a Vec3f from three consecutive big-endian f32 values.
impl Decode for Vec3i16
Decodes a Vec3i16 from three consecutive big-endian i16 values.