Struct bitter::BitGet
[−]
[src]
pub struct BitGet<'a> { /* fields omitted */ }
Yields consecutive bits as little endian primitive types
Methods
impl<'a> BitGet<'a>
[src]
fn new(data: &'a [u8]) -> BitGet<'a>
[src]
Creates a bitstream from a byte slice
fn read_i8(&mut self) -> Option<i8>
[src]
fn read_u8(&mut self) -> Option<u8>
[src]
fn read_i16(&mut self) -> Option<i16>
[src]
fn read_u16(&mut self) -> Option<u16>
[src]
fn read_i32(&mut self) -> Option<i32>
[src]
fn read_u32(&mut self) -> Option<u32>
[src]
fn read_i64(&mut self) -> Option<i64>
[src]
fn read_u64(&mut self) -> Option<u64>
[src]
fn read_i8_unchecked(&mut self) -> i8
[src]
fn read_u8_unchecked(&mut self) -> u8
[src]
fn read_i16_unchecked(&mut self) -> i16
[src]
fn read_u16_unchecked(&mut self) -> u16
[src]
fn read_i32_unchecked(&mut self) -> i32
[src]
fn read_u32_unchecked(&mut self) -> u32
[src]
fn read_i64_unchecked(&mut self) -> i64
[src]
fn read_u64_unchecked(&mut self) -> u64
[src]
fn read_i32_bits_unchecked(&mut self, bits: i32) -> i32
[src]
fn read_i32_bits(&mut self, bits: i32) -> Option<i32>
[src]
fn read_u32_bits_unchecked(&mut self, bits: i32) -> u32
[src]
Assumes that the number of bits are available in the bitstream and reads them into a u32
fn read_u32_bits(&mut self, bits: i32) -> Option<u32>
[src]
If the number of bits are available from the bitstream, read them into a u32
fn is_empty(&self) -> bool
[src]
Returns if the bitstream has no more bits left
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.is_empty(), false); assert_eq!(bitter.read_u16_unchecked(), 0b0101_0101_1010_1010); assert_eq!(bitter.is_empty(), true);
fn approx_bytes_remaining(&self) -> usize
[src]
Approximately the number of bytes left (an underestimate). This is the preferred method when guarding against multiple unchecked reads. Currently the underestimate is capped at 4 bytes, though this may be subject to change
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.approx_bytes_remaining(), 2); assert_eq!(bitter.read_bit_unchecked(), false); assert_eq!(bitter.approx_bytes_remaining(), 0);
fn bits_remaining(&self) -> usize
[src]
Returns the number of bits left in the bitstream (exact)
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.bits_remaining(), 16); assert_eq!(bitter.read_bit_unchecked(), false); assert_eq!(bitter.bits_remaining(), 15);
fn read_bit(&mut self) -> Option<bool>
[src]
Reads a bit from the bitstream if available
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.read_bit(), Some(false));
fn read_bit_unchecked(&mut self) -> bool
[src]
Assumes there is at least one bit left in the stream.
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.read_bit_unchecked(), false);
fn read_f32(&mut self) -> Option<f32>
[src]
Reads a f32
from the bitstream if available
fn read_f32_unchecked(&mut self) -> f32
[src]
Reads a f32
from the bitstream
fn read_bits_max(&mut self, bits: i32, max: i32) -> Option<u32>
[src]
Reads a value that takes up at most bits
bits and doesn't exceed max
. This function
assumes that max
has the same bitwidth as bits
. It doesn't make sense to call this
function bits = 8
and max = 30
, you'd change your argument to bits = 5
. If bits
are
not available return None
// Reads 5 bits or stops if the 5th bit would send the accumulator over 20 let mut bitter = BitGet::new(&[0b1111_1000]); assert_eq!(bitter.read_bits_max(5, 20), Some(8));
fn read_bits_max_unchecked(&mut self, bits: i32, max: i32) -> u32
[src]
Reads a value that takes up at most bits
bits and doesn't exceed max
. This function
assumes that max
has the same bitwidth as bits
. It doesn't make sense to call this
function bits = 8
and max = 30
, you'd change your argument to bits = 5
// Reads 5 bits or stops if the 5th bit would send the accumulator over 20 let mut bitter = BitGet::new(&[0b1111_1000]); assert_eq!(bitter.read_bits_max(5, 20), Some(8));
fn if_get<T, F>(&mut self, f: F) -> Option<Option<T>> where
F: FnMut(&mut Self) -> Option<T>,
[src]
F: FnMut(&mut Self) -> Option<T>,
If the next bit is available and on, decode the next chunk of data (which can return None). The return value can be one of the following:
- None: Not enough data was available
- Some(None): Bit was off so data not decoded
- Some(x): Bit was on and data was decoded
let mut bitter = BitGet::new(&[0xff, 0x04]); assert_eq!(bitter.if_get(BitGet::read_u8), Some(Some(0x7f))); assert_eq!(bitter.if_get(BitGet::read_u8), Some(None)); assert_eq!(bitter.if_get(BitGet::read_u8), None);
fn if_get_unchecked<T, F>(&mut self, f: F) -> Option<T> where
F: FnMut(&mut Self) -> T,
[src]
F: FnMut(&mut Self) -> T,
If the next bit is available and on, decode the next chunk of data. The return value can be one of the following:
- Some(None): Bit was off so data not decoded
- Some(x): Bit was on and data was decoded
let mut bitter = BitGet::new(&[0xff, 0x04]); assert_eq!(bitter.if_get_unchecked(BitGet::read_u8_unchecked), Some(0x7f)); assert_eq!(bitter.if_get_unchecked(BitGet::read_u8_unchecked), None);
Panics
Will panic if no data is left for the bit or for the data to be decoded.
fn read_bytes(&mut self, bytes: i32) -> Option<Vec<u8>>
[src]
If the number of requested bytes are available return them to the client. Since the current bit position may not be byte aligned, return an owned vector of all the bits shifted appropriately.
let mut bitter = BitGet::new(&[0b1010_1010, 0b0101_0101]); assert_eq!(bitter.read_bit_unchecked(), false); assert_eq!(bitter.read_bytes(1), Some(vec![0b1101_0101]));