pub struct BitCursor<'a> { /* private fields */ }Expand description
A big-endian, MSB-first bit reader.
Implementations§
Source§impl<'a> BitCursor<'a>
impl<'a> BitCursor<'a>
Sourcepub const fn seek(&mut self, position: usize)
pub const fn seek(&mut self, position: usize)
Moves the cursor to an absolute bit position.
Positions past the end are allowed; the failure surfaces on the next read. XTCE
LocationInContainerInBits can legitimately seek forward past unparsed padding.
Sourcepub fn skip(&mut self, bits: usize) -> Result<(), BitError>
pub fn skip(&mut self, bits: usize) -> Result<(), BitError>
Advances the cursor without reading.
§Errors
Returns BitError::OutOfBounds if the skip would pass the end of the buffer.
Sourcepub fn read_uint(&mut self, width: u32) -> Result<u64, BitError>
pub fn read_uint(&mut self, width: u32) -> Result<u64, BitError>
Reads width bits as an unsigned integer and advances the cursor.
Width 0 yields 0, matching the reference implementation’s treatment of an empty field. Widths above 64 are rejected.
§Errors
BitError::TooWide above 64 bits, BitError::OutOfBounds past the end.
Sourcepub fn peek_uint(&self, position: usize, width: u32) -> Result<u64, BitError>
pub fn peek_uint(&self, position: usize, width: u32) -> Result<u64, BitError>
Reads width bits as an unsigned integer at an absolute position, without moving
the cursor.
§Errors
BitError::TooWide above 64 bits, BitError::OutOfBounds past the end.
Sourcepub fn read_bytes(&mut self, width: usize) -> Result<Cow<'a, [u8]>, BitError>
pub fn read_bytes(&mut self, width: usize) -> Result<Cow<'a, [u8]>, BitError>
Reads width bits as bytes, right-aligned in the result.
The result is ceil(width / 8) bytes holding the field as a big-endian integer, so a
12-bit field becomes two bytes with four leading zero bits. This is the layout the
reference implementation produces for binary fields, and the layout XTCE implies by
treating a binary field as an integer of that width.
Byte-aligned whole-byte reads borrow from the packet; everything else allocates.
§Errors
BitError::OutOfBounds past the end of the buffer.
Sourcepub fn read_bytes_left_aligned(
&mut self,
width: usize,
) -> Result<Cow<'a, [u8]>, BitError>
pub fn read_bytes_left_aligned( &mut self, width: usize, ) -> Result<Cow<'a, [u8]>, BitError>
Reads width bits as bytes, left-aligned in the result.
The result is ceil(width / 8) bytes holding the field starting at bit 0, with any
slack at the end. This is what a string buffer needs: characters are read from
the front, so padding must not displace them.
§Errors
BitError::OutOfBounds past the end of the buffer.