Trait BitRead
trait BitRead
A trait for anything that can read a variable number of potentially un-aligned values from an input stream
Required Methods
fn read_bit(self: &mut Self) -> Result<bool>Reads a single bit from the stream.
trueindicates 1,falseindicates 0Errors
Passes along any I/O error from the underlying stream.
fn read<U>(self: &mut Self, bits: u32) -> Result<U> where U: NumericReads an unsigned value from the stream with the given number of bits.
Errors
Passes along any I/O error from the underlying stream. Also returns an error if the output type is too small to hold the requested number of bits.
fn read_signed<S>(self: &mut Self, bits: u32) -> Result<S> where S: SignedNumericReads a twos-complement signed value from the stream with the given number of bits.
Errors
Passes along any I/O error from the underlying stream. Returns an error if the number of bits is 0, since one bit is always needed for the sign. Also returns an error if the output type is too small to hold the requested number of bits.
fn read_to<V>(self: &mut Self) -> Result<V> where V: PrimitiveReads whole value from the stream whose size in bits is equal to its type's size.
Errors
Passes along any I/O error from the underlying stream.
fn read_as_to<F, V>(self: &mut Self) -> Result<V> where F: Endianness, V: PrimitiveReads whole value from the stream whose size in bits is equal to its type's size in an endianness that may be different from the stream's endianness.
Errors
Passes along any I/O error from the underlying stream.
fn skip(self: &mut Self, bits: u32) -> Result<()>Skips the given number of bits in the stream. Since this method does not need an accumulator, it may be slightly faster than reading to an empty variable. In addition, since there is no accumulator, there is no upper limit on the number of bits which may be skipped. These bits are still read from the stream, however, and are never skipped via a
seekmethod.Errors
Passes along any I/O error from the underlying stream.
fn byte_aligned(self: &Self) -> boolReturns true if the stream is aligned at a whole byte.
fn byte_align(self: &mut Self)Throws away all unread bit values until the next whole byte. Does nothing if the stream is already aligned.
Provided Methods
fn read_in<BITS: u32, U>(self: &mut Self) -> Result<U> where U: NumericReads an unsigned value from the stream with the given constant number of bits.
Errors
Passes along any I/O error from the underlying stream. A compile-time error occurs if the given number of bits is larger than the output type.
fn read_signed_in<BITS: u32, S>(self: &mut Self) -> Result<S> where S: SignedNumericReads a twos-complement signed value from the stream with the given constant number of bits.
Errors
Passes along any I/O error from the underlying stream. A compile-time error occurs if the number of bits is 0, since one bit is always needed for the sign. A compile-time error occurs if the given number of bits is larger than the output type.
fn read_bytes(self: &mut Self, buf: &mut [u8]) -> Result<()>Completely fills the given buffer with whole bytes. If the stream is already byte-aligned, it will map to a faster
read_exactcall. Otherwise it will read bytes individually in 8-bit increments.Errors
Passes along any I/O error from the underlying stream.
fn read_to_bytes<SIZE: usize>(self: &mut Self) -> Result<[u8; SIZE]>Completely fills a whole buffer with bytes and returns it. If the stream is already byte-aligned, it will map to a faster
read_exactcall. Otherwise it will read bytes individually in 8-bit increments.Errors
Passes along any I/O error from the underlying stream.
fn read_to_vec(self: &mut Self, bytes: usize) -> Result<Vec<u8>>Completely fills a vector of bytes and returns it. If the stream is already byte-aligned, it will map to a faster
read_exactcall. Otherwise it will read bytes individually in 8-bit increments.Errors
Passes along any I/O error from the underlying stream.
fn read_unary0(self: &mut Self) -> Result<u32>Counts the number of 1 bits in the stream until the next 0 bit and returns the amount read. Because this field is variably-sized and may be large, its output is always a
u32type.Errors
Passes along any I/O error from the underlying stream.
fn read_unary1(self: &mut Self) -> Result<u32>Counts the number of 0 bits in the stream until the next 1 bit and returns the amount read. Because this field is variably-sized and may be large, its output is always a
u32type.Errors
Passes along any I/O error from the underlying stream.
fn parse<F: FromBitStream>(self: &mut Self) -> Result<F, <F as >::Error>Parses and returns complex type
fn parse_with<'a, F: FromBitStreamWith<'a>>(self: &mut Self, context: &<F as >::Context) -> Result<F, <F as >::Error>Parses and returns complex type with context
Implementors
impl<R: io::Read, E: Endianness> BitRead for BitReader<R, E>