pub struct BitCursor<T: AsRef<[u8]>> { /* private fields */ }Expand description
A no-copy cursor wrapper for a bitstream.
Any type that implements AsRef<[u8]> can be used with BitCursor.
Implementations§
Source§impl<T: AsRef<[u8]>> BitCursor<T>
impl<T: AsRef<[u8]>> BitCursor<T>
Sourcepub fn new_with_len(inner: T, byte_len: usize) -> Result<Self, Error>
pub fn new_with_len(inner: T, byte_len: usize) -> Result<Self, Error>
Create a new BitCursor for the inner buffer, limiting to byte_len bytes.
Returns an error if byte_len exceeds inner’s range.
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
Return the length of the data wrapped by this cursor, in bytes.
Sourcepub fn exhausted(&self) -> bool
pub fn exhausted(&self) -> bool
Return whether the underlying data is “exhausted”, i.e. whether it’s impossible to read any further from the cursor’s current position.
Sourcepub fn seek_bit(&mut self, pos: usize) -> Result<(), Error>
pub fn seek_bit(&mut self, pos: usize) -> Result<(), Error>
Seek to the given bit-granular position in the bitstream.
NOTE: This is a bit-granular absolute seek. If you only need byte granularity
or would like to do a relative (start or end) seek, use the Seek
implementation.
Sourcepub fn read(&mut self, nbits: usize) -> Result<u64, Error>
pub fn read(&mut self, nbits: usize) -> Result<u64, Error>
Read nbits bits of data at the current position. The data is returned
as a u64.
Returns an error if the requested read is invalid (e.g. EOF or not enough data)
or if nbits is invalid (zero, or >= u64::BITS).
Sourcepub fn read_as<Int: NumCast>(&mut self, nbits: usize) -> Result<Int, Error>
pub fn read_as<Int: NumCast>(&mut self, nbits: usize) -> Result<Int, Error>
Read a nbits of data at the current position into the given scalar type.
Returns an error under all of the same conditions as read,
as well as if the read value doesn’t fit into the given scalar.
Sourcepub fn read_exact<Int: NumCast>(&mut self) -> Result<Int, Error>
pub fn read_exact<Int: NumCast>(&mut self) -> Result<Int, Error>
Read exactly the size of Int at the current position.
Returns an error under all of the same conditions as read.
Sourcepub fn read_vbr(&mut self, width: usize) -> Result<u64, Error>
pub fn read_vbr(&mut self, width: usize) -> Result<u64, Error>
Read a width-wide VBR-encoded integer.
This function returns only unsigned integers. For signed integers,
use read_svbr.
Trait Implementations§
Source§impl<T: AsRef<[u8]>> Seek for BitCursor<T>
A Seek implementation for BitCursor.
impl<T: AsRef<[u8]>> Seek for BitCursor<T>
A Seek implementation for BitCursor.
Seeking past the end of a BitCursor is always invalid, and always returns
an error.
NOTE: This is a byte-granular implementation of Seek.
For bit-granular seeking, use seek_bit.