Struct bitsparrow::Decoder [] [src]

pub struct Decoder<'src> { /* 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<'src> Decoder<'src>
[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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.

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