Skip to main content

EncodedSize

Trait EncodedSize 

Source
pub trait EncodedSize {
    // Required method
    fn encoded_size(&self) -> usize;
}
Expand description

Predict the exact serialized byte count for pre-allocation.

Required Methods§

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EncodedSize for String

Computes the wire size of a Minecraft protocol string.

The total size is the VarInt-encoded length prefix plus the UTF-8 byte count. This enables exact buffer pre-allocation before encoding.

Source§

fn encoded_size(&self) -> usize

Returns the VarInt prefix size plus the string’s byte length.

Source§

impl EncodedSize for Vec<u8>

Computes the wire size of a Minecraft protocol byte array.

The total size is the VarInt-encoded length prefix plus the byte count. This enables exact buffer pre-allocation before encoding.

Source§

fn encoded_size(&self) -> usize

Returns the VarInt prefix size plus the array’s byte length.

Source§

impl EncodedSize for bool

A boolean always occupies exactly one byte on the wire.

Source§

impl EncodedSize for f32

The encoded size is always 4 bytes, regardless of the value.

Source§

impl EncodedSize for f64

The encoded size is always 8 bytes, regardless of the value.

Source§

impl EncodedSize for i8

The encoded size is always 1 bytes, regardless of the value.

Source§

impl EncodedSize for i16

The encoded size is always 2 bytes, regardless of the value.

Source§

impl EncodedSize for i32

The encoded size is always 4 bytes, regardless of the value.

Source§

impl EncodedSize for i64

The encoded size is always 8 bytes, regardless of the value.

Source§

impl EncodedSize for u8

The encoded size is always 1 bytes, regardless of the value.

Source§

impl EncodedSize for u16

The encoded size is always 2 bytes, regardless of the value.

Source§

impl EncodedSize for u32

The encoded size is always 4 bytes, regardless of the value.

Source§

impl EncodedSize for u64

The encoded size is always 8 bytes, regardless of the value.

Source§

impl<T: EncodedSize + ?Sized> EncodedSize for Box<T>

Implementors§

Source§

impl EncodedSize for Angle

An Angle always occupies exactly 1 byte on the wire.

Source§

impl EncodedSize for BitSet

Computes the wire size of the BitSet.

The total size is the VarInt-encoded length prefix plus 8 bytes per long. This enables exact buffer pre-allocation before encoding.

Source§

impl EncodedSize for Identifier

Computes the wire size of the identifier in namespace:path format.

The total size includes the VarInt length prefix and the full namespace:path UTF-8 byte count (including the colon separator).

Source§

impl EncodedSize for NbtCompound

Computes the wire size of a network NBT root compound.

Includes the compound type byte (1) plus the compound payload size (entries + End tag).

Source§

impl EncodedSize for NbtTag

Computes the wire size of an NbtTag as a network NBT root.

Source§

impl EncodedSize for OpaqueBytes

Source§

impl EncodedSize for Position

A Position always occupies exactly 8 bytes on the wire (one packed i64).

Source§

impl EncodedSize for Slot

Computes the wire size of a Slot.

Source§

impl EncodedSize for TextComponent

Computes the wire size of a TextComponent as network NBT.

Converts to NbtCompound and delegates to its EncodedSize. This involves building the full NBT tree, so it is not free — use sparingly or cache the result when encoding multiple times.

Source§

impl EncodedSize for Uuid

A UUID always occupies exactly 16 bytes on the wire.

Source§

impl EncodedSize for VarInt

Computes the number of bytes this VarInt will occupy when encoded.

Returns 1-5 based on the unsigned magnitude of the value. Small positive values (0-127) take 1 byte, while negative values always take 5 bytes due to two’s complement sign extension.

Source§

impl EncodedSize for VarLong

Computes the number of bytes this VarLong will occupy when encoded.

Returns 1-10 based on the unsigned magnitude. Small positive values (0-127) take 1 byte, i64::MAX takes 9, and negative values always take 10 bytes.

Source§

impl EncodedSize for Vec2f

A Vec2f always occupies 8 bytes (2 × f32).

Source§

impl EncodedSize for Vec3f

A Vec3f always occupies 12 bytes (3 × f32).

Source§

impl EncodedSize for Vec3f64

A Vec3f64 always occupies 24 bytes (3 × f64).

Source§

impl EncodedSize for Vec3i16

A Vec3i16 always occupies 6 bytes (3 × i16).