pub struct BitSet { /* private fields */ }Expand description
A variable-length bit array encoded as a VarInt-prefixed array of i64 values.
BitSet is used in the Minecraft protocol for chunk light masks, section bitmasks, and other bitfield data where an arbitrary number of boolean flags need to be packed efficiently. Each i64 holds 64 bits, and the array grows as needed to accommodate the highest set bit.
Wire format: VarInt(number of longs) followed by that many big-endian i64 values. An empty BitSet has zero longs.
Implementations§
Source§impl BitSet
impl BitSet
Sourcepub fn from_longs(data: Vec<i64>) -> Self
pub fn from_longs(data: Vec<i64>) -> Self
Creates a BitSet from a pre-existing vector of i64 words.
Each i64 holds 64 bits. The first element contains bits 0-63, the second 64-127, and so on. This is useful when constructing a BitSet from data received outside the protocol decoding path.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bits this BitSet can currently hold without growing (i.e., the number of longs × 64).
Sourcepub fn get(&self, index: usize) -> bool
pub fn get(&self, index: usize) -> bool
Returns the value of the bit at the given index.
Returns false for indices beyond the current capacity — bits
outside the allocated range are implicitly zero.
Sourcepub fn set(&mut self, index: usize, value: bool)
pub fn set(&mut self, index: usize, value: bool)
Sets or clears the bit at the given index.
If the index is beyond the current capacity and value is true,
the internal storage is automatically extended with zero-filled
longs. Setting a bit to false beyond the current capacity is
a no-op (the bit is already implicitly zero).
Trait Implementations§
Source§impl Decode for BitSet
Decodes a BitSet from a VarInt-prefixed array of big-endian i64 values.
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.
Source§impl Encode for BitSet
Encodes the BitSet as a VarInt-prefixed array of big-endian i64 values.
impl Encode for BitSet
Encodes the BitSet as a VarInt-prefixed array of big-endian i64 values.
The VarInt indicates the number of longs in the array, followed by each long encoded as 8 big-endian bytes. An empty BitSet encodes as a single VarInt(0) byte.
Source§impl EncodedSize for BitSet
Computes the wire size of the BitSet.
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§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Returns VarInt prefix size + (number of longs × 8).
impl Eq for BitSet
impl StructuralPartialEq for BitSet
Auto Trait Implementations§
impl Freeze for BitSet
impl RefUnwindSafe for BitSet
impl Send for BitSet
impl Sync for BitSet
impl Unpin for BitSet
impl UnsafeUnpin for BitSet
impl UnwindSafe for BitSet
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.