Struct bitbit::reader::BitReader [] [src]

pub struct BitReader<R: Read, B: Bit> {
    // some fields omitted
}

A BitReader gives a way to read single bits from a stream.

Methods

impl<R: Read, B: Bit> BitReader<R, B>
[src]

fn new(reader: R) -> BitReader<R, B>

Constructs a new BitReader. Requires an implementation of Bit type to determine which end of bytes to read bits from.

Arguments

  • reader - an existing open file or stream (implementing Read).

Examples

let r = try!(File::open("somefile"));
let mut br: BitReader<_,MSB> = BitReader::new(r);

fn read_bit(&mut self) -> Result<bool>

Reads a single bit from a BitReader. Returns true for a 1 bit, false for a 0 bit.

Examples

let is_one = try!(br.read_bit());

fn read_byte(&mut self) -> Result<u8>

Reads 8 bits from a BitReader and returns them as a single byte.

Examples

let byte = try!(br.read_byte());

fn read_bits(&mut self, nbits: usize) -> Result<u32>

Read a number of bits from a BitReader and return them in a u32. Will not read more than 32 bits.

Arguments

  • bits - number of bits to read

Examples

let num = try!(br.read_bits(5));

fn get_ref(&mut self) -> &R

Gets a reference to the underlying stream.