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]
fn new(data: &[u8]) -> Decoder
Create a new Decoder
reading from a &[u8]
slice buffer.
fn decode<D: BitDecode<'src>>(data: &'src [u8]) -> Result<D, Error>
fn read<D: BitDecode<'src>>(&mut self) -> Result<D, Error>
fn uint8(&mut self) -> Result<u8, Error>
Read a u8
from the buffer and progress the internal index.
fn uint16(&mut self) -> Result<u16, Error>
Read a u16
from the buffer and progress the internal index.
fn uint32(&mut self) -> Result<u32, Error>
Read a u32
from the buffer and progress the internal index.
fn uint64(&mut self) -> Result<u64, Error>
Read a u64
from the buffer and progress the internal index.
fn int8(&mut self) -> Result<i8, Error>
Read an i8
from the buffer and progress the internal index.
fn int16(&mut self) -> Result<i16, Error>
Read an i16
from the buffer and progress the internal index.
fn int32(&mut self) -> Result<i32, Error>
Read an i32
from the buffer and progress the internal index.
fn int64(&mut self) -> Result<i64, Error>
Read an i64
from the buffer and progress the internal index.
fn float32(&mut self) -> Result<f32, Error>
Read a float32
from the buffer and progress the internal index.
fn float64(&mut self) -> Result<f64, Error>
Read a float64
from the buffer and progress the internal index.
fn bool(&mut self) -> Result<bool, Error>
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 bool
s,
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<usize, Error>
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<&'src [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<&'src str, Error>
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
.