pub struct BitBuf<S> { /* private fields */ }Expand description
The main structure
Keeps track of the data storage and a cursor for automatic operations
Implementations§
Source§impl<S> BitBuf<S>
impl<S> BitBuf<S>
Sourcepub fn bytes_mut(&mut self) -> &mut [u8]where
S: StorageMut,
pub fn bytes_mut(&mut self) -> &mut [u8]where
S: StorageMut,
Get the underlying bytes from the storage
Sourcepub fn pos(&self) -> usize
pub fn pos(&self) -> usize
Get the internal cursor for automatic operations
The cursor may not be within storage bounds
Sourcepub fn byte_pos(&self) -> usize
pub fn byte_pos(&self) -> usize
Get the byte-aligned position of the internal cursor for automatic operations
The cursor may not be within storage bounds
Sourcepub fn advance(&mut self, bits: usize) -> &mut Self
pub fn advance(&mut self, bits: usize) -> &mut Self
Advance the internal cursor for automatic operations
This does not enforce that the cursor stay within storage bounds
Sourcepub fn advance_bytes(&mut self, bytes: usize) -> &mut Self
pub fn advance_bytes(&mut self, bytes: usize) -> &mut Self
Advance the internal cursor for automatic operations by a number of bytes
This does not enforce that the cursor stay within storage bounds
Sourcepub fn seek(&mut self, offset: usize) -> &mut Self
pub fn seek(&mut self, offset: usize) -> &mut Self
Set the internal cursor for automatic operations
This does not enforce that the cursor stay within storage bounds
Sourcepub fn seek_byte(&mut self, byte: usize) -> &mut Self
pub fn seek_byte(&mut self, byte: usize) -> &mut Self
Set the internal cursor for automatic operations to a byte position
This sets the cursor to offset * 8 bits.
This does not enforce that the cursor stay within storage bounds
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Checks if the internal cursor for automatic operations is aligned on the start of a byte
This does not care whether the cursor is outside storage bounds
Source§impl<S: Storage> BitBuf<S>
impl<S: Storage> BitBuf<S>
Sourcepub unsafe fn read_u8_be_aligned_full_at_unchecked(
&self,
byte_offset: usize,
) -> u8
pub unsafe fn read_u8_be_aligned_full_at_unchecked( &self, byte_offset: usize, ) -> u8
Read a BE-bit-order u8 from byte_offset without performing bound checks
§Safety
- This is UB if
byte_offset >= self.bytes().len()
§Panics
- Panics in debug mode if
byte_offset >= self.bytes().len()
Sourcepub unsafe fn read_u8_be_aligned_full_unchecked(&mut self) -> u8
pub unsafe fn read_u8_be_aligned_full_unchecked(&mut self) -> u8
Read the next BE-bit-order u8 without performing bound checks, advancing the internal cursor
§Safety
- The internal cursor must be byte-aligned (
self.is_aligned()) - This is UB if the internal cursor points past the end of storage (
self.byte_pos() >= self.bytes().len())
§Panics
- Panics in debug mode if the internal cursor is not byte-aligned (
!self.is_aligned()) - Panics in debug mode if the internal cursor points past the end of storage (
self.byte_pos() >= self.bytes().len())
Sourcepub unsafe fn read_u8_be_full_at_unchecked(&self, offset: usize) -> u8
pub unsafe fn read_u8_be_full_at_unchecked(&self, offset: usize) -> u8
Read a BE-bit-order u8 from offset without performing bound checks
§Safety
- This is UB if
(offset / 8) >=self.bytes().len() - This is UB if
(offset % 8 != 0) && (offset / 8) + 1 >=self.bytes().len()
§Panics
- Panics in debug mode if
(offset / 8) >=self.bytes().len() - Panics in debug mode if
(offset % 8 != 0) && (offset / 8) + 1 >=self.bytes().len()
Sourcepub fn try_read_u8_be_full_at(&self, offset: usize) -> Result<u8>
pub fn try_read_u8_be_full_at(&self, offset: usize) -> Result<u8>
Read a BE-bit-order u8 from offset while performing bound checks
§Errors
- Returns
Error::OutOfBounds- if
(offset / 8) >=self.bytes().len() - if
(offset % 8 != 0) && (offset / 8) + 1 >=self.bytes().len()
- if
Sourcepub fn read_u8_be_full_at(&self, offset: usize) -> u8
pub fn read_u8_be_full_at(&self, offset: usize) -> u8
Read a BE-bit-order u8 from offset, panicking on out of bounds
§Panics
- Panics if
(offset / 8) >=self.bytes().len() - Panics if
(offset % 8 != 0) && (offset / 8) + 1 >=self.bytes().len()
Source§impl<S: StorageMut> BitBuf<S>
impl<S: StorageMut> BitBuf<S>
Sourcepub unsafe fn write_u8_be_aligned_full_at_unchecked(
&mut self,
byte_offset: usize,
v: u8,
) -> &mut Self
pub unsafe fn write_u8_be_aligned_full_at_unchecked( &mut self, byte_offset: usize, v: u8, ) -> &mut Self
Write a u8 in BE-bit-order at byte_offset without performing bound checks
§Safety
- This is UB if
byte_offset >= self.bytes().len()
§Panics
- Panics in debug mode if
byte_offset >= self.bytes().len()
Sourcepub unsafe fn write_u8_be_aligned_full_unchecked(&mut self, v: u8) -> &mut Self
pub unsafe fn write_u8_be_aligned_full_unchecked(&mut self, v: u8) -> &mut Self
Write a u8 in BE-bit-order without performing bound checks, advancing the internal cursor
§Safety
- The internal cursor must be byte-aligned (
self.is_aligned()) - This is UB if the internal cursor points past the end of storage (
self.byte_pos() >= self.bytes().len())
§Panics
- Panics in debug mode if the internal cursor is not byte-aligned (
!self.is_aligned()) - Panics in debug mode if the internal cursor points past the end of storage (
self.byte_pos() >= self.bytes().len())