Struct bitter::BitGet [] [src]

pub struct BitGet<'a> { /* fields omitted */ }

Yields consecutive bits as little endian primitive types

Methods

impl<'a> BitGet<'a>
[src]

[src]

Creates a bitstream from a byte slice

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Assumes that the number of bits are available in the bitstream and reads them into a u32

[src]

If the number of bits are available from the bitstream, read them into a u32

[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);

[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);

[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);

[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));

[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);

[src]

Reads a f32 from the bitstream if available

[src]

Reads a f32 from the bitstream

[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));

[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));

[src]

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);

[src]

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.

[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]));