pub struct FixedBitSet<const N: usize>(pub Vec<u8>);Expand description
A bit set with a fixed length of N bits.
A fixed bit set is encoded as exactly ceil(N / 8) bytes, without a
length prefix. This differs from BitSet, which is prefixed by a VarInt
and stores packed 64-bit words. The packed bytes follow the same bit order
as Java’s BitSet.toByteArray: bit i is set when the following expression
is non-zero:
(data[i / 8] & (1 << (i % 8))) != 0The final byte is padded with zero bits when N is not divisible by eight.
§Examples
use mcproto_types::{TypeCodec, basic::FixedBitSet};
// Bits 0, 7, and 8 are set in a nine-bit set.
let bits = FixedBitSet::<9>(vec![0b1000_0001, 0b0000_0001]);
let mut encoded = Vec::new();
bits.encode(&mut encoded)?;
assert_eq!(encoded, [0b1000_0001, 0b0000_0001]);
let mut input = encoded.as_slice();
assert_eq!(FixedBitSet::<9>::decode(&mut input)?, bits);
assert!(bits.contains(0));
assert!(bits.contains(7));
assert!(bits.contains(8));
assert!(!bits.contains(9));Tuple Fields§
§0: Vec<u8>The packed bytes, in little-endian bit order within each byte.
Implementations§
Trait Implementations§
Source§impl<const N: usize> Clone for FixedBitSet<N>
impl<const N: usize> Clone for FixedBitSet<N>
Source§fn clone(&self) -> FixedBitSet<N>
fn clone(&self) -> FixedBitSet<N>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<const N: usize> Debug for FixedBitSet<N>
impl<const N: usize> Debug for FixedBitSet<N>
Source§impl<const N: usize> Default for FixedBitSet<N>
impl<const N: usize> Default for FixedBitSet<N>
Source§fn default() -> FixedBitSet<N>
fn default() -> FixedBitSet<N>
Returns the “default value” for a type. Read more
impl<const N: usize> Eq for FixedBitSet<N>
Source§impl<const N: usize> Hash for FixedBitSet<N>
impl<const N: usize> Hash for FixedBitSet<N>
Source§impl<const N: usize> PartialEq for FixedBitSet<N>
impl<const N: usize> PartialEq for FixedBitSet<N>
impl<const N: usize> StructuralPartialEq for FixedBitSet<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for FixedBitSet<N>
impl<const N: usize> RefUnwindSafe for FixedBitSet<N>
impl<const N: usize> Send for FixedBitSet<N>
impl<const N: usize> Sync for FixedBitSet<N>
impl<const N: usize> Unpin for FixedBitSet<N>
impl<const N: usize> UnsafeUnpin for FixedBitSet<N>
impl<const N: usize> UnwindSafe for FixedBitSet<N>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.