Struct bitsparrow::Decoder [] [src]

pub struct Decoder<'a> {
    // some fields omitted
}

Decoder reads from a binary slice buffer (&[u8]) and exposes methods to read BitSparrow types from it in the same order they were encoded by the Encoder.

Methods

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

fn new(data: &[u8]) -> Decoder

Create a new Decoder reading from a &[u8] slice buffer.

fn uint8(&mut self) -> Result<u8Error>

Read a u8 from the buffer and progress the internal index.

fn uint16(&mut self) -> Result<u16Error>

Read a u16 from the buffer and progress the internal index.

fn uint32(&mut self) -> Result<u32Error>

Read a u32 from the buffer and progress the internal index.

fn uint64(&mut self) -> Result<u64Error>

Read a u64 from the buffer and progress the internal index.

fn int8(&mut self) -> Result<i8Error>

Read an i8 from the buffer and progress the internal index.

fn int16(&mut self) -> Result<i16Error>

Read an i16 from the buffer and progress the internal index.

fn int32(&mut self) -> Result<i32Error>

Read an i32 from the buffer and progress the internal index.

fn int64(&mut self) -> Result<i64Error>

Read an i64 from the buffer and progress the internal index.

fn float32(&mut self) -> Result<f32Error>

Read a float32 from the buffer and progress the internal index.

fn float64(&mut self) -> Result<f64Error>

Read a float64 from the buffer and progress the internal index.

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

Read a bool from the buffer and progress the internal index. If a bool was previously read from the buffer, calling bool() on the Decoder again will read a boolean from the same index without progressing, but instead shifting to read the next bit. This behavior is symmetric to how the Encoder stores the bools, and is completely transparent when using the API.

use bitsparrow::Decoder;

// Reading `bools` from a single byte.
let buffer = &[0b11100001];
let mut decoder = Decoder::new(buffer);

assert_eq!(true, decoder.bool().unwrap());
assert_eq!(false, decoder.bool().unwrap());
assert_eq!(false, decoder.bool().unwrap());
assert_eq!(false, decoder.bool().unwrap());
assert_eq!(false, decoder.bool().unwrap());
assert_eq!(true, decoder.bool().unwrap());
assert_eq!(true, decoder.bool().unwrap());
assert_eq!(true, decoder.bool().unwrap());

// Ensure we've read the entire buffer
assert_eq!(true, decoder.end());

fn size(&mut self) -> Result<usizeError>

Read a usize from the buffer and progress the index. Detailed explanation on how BitSparrow stores size can be found on the homepage.

fn bytes(&mut self) -> Result<&[u8]Error>

Read an arbitary sized binary data from the buffer and progress the index.

Note: BitSparrow internally prefixes bytes with size so you don't have to worry about how many bytes you need to read.

fn string(&mut self) -> Result<&strError>

Read an arbitary sized owned String from the buffer and progress the index.

Note: Analog to bytes, BitSparrow internally prefixes string with size so you don't have to worry about how many bytes you need to read.

fn end(&self) -> bool

Returns true if the entire buffer has been read, otherwise returns false.