pub struct VarInt(pub i32);Expand description
A variable-length encoded 32-bit signed integer, occupying 1 to 5 bytes.
VarInt is the most common type in the Minecraft protocol. It is used for packet IDs, packet lengths, string length prefixes, array lengths, enum discriminants, and many field values. The encoding uses the MSB of each byte as a continuation bit (1 = more bytes follow, 0 = last byte), with the lower 7 bits carrying the value in little-endian order (least significant group first). Negative values use two’s complement and always require 5 bytes.
Tuple Fields§
§0: i32Implementations§
Trait Implementations§
Source§impl Decode for VarInt
Decodes a VarInt by reading 1-5 bytes from 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.
Source§impl Encode for VarInt
Encodes the VarInt as 1-5 bytes using MSB continuation bit encoding.
impl Encode for VarInt
Encodes the VarInt as 1-5 bytes using MSB continuation bit encoding.
Each byte carries 7 bits of the value (least significant first). The MSB is set to 1 if more bytes follow, 0 on the final byte. Negative values are encoded as their unsigned two’s complement representation and always produce 5 bytes.
Source§impl EncodedSize for VarInt
Computes the number of bytes this VarInt will occupy when encoded.
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.
fn encoded_size(&self) -> usize
impl Copy for VarInt
impl Eq for VarInt
impl StructuralPartialEq for VarInt
Auto Trait Implementations§
impl Freeze for VarInt
impl RefUnwindSafe for VarInt
impl Send for VarInt
impl Sync for VarInt
impl Unpin for VarInt
impl UnsafeUnpin for VarInt
impl UnwindSafe for VarInt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.