Crate bitsparrow [] [src]

For implementations in other languages, and more detailed information on the types check out

BitSparrow in Rust


use bitsparrow::Encoder;

let buffer = Encoder::new()

assert_eq!(buffer, &[0x64,0x03,0x46,0x6f,0x6f])

Each method on the Encoder will return a mutable borrow of the encoder. If you need to break the monad chain, store the owned encoder as a variable before writing to it, e.g.:

use bitsparrow::Encoder;

let mut encoder = Encoder::new();

 * Many codes here

let buffer = encoder.string("Foo").end();

assert_eq!(buffer, &[0x64_u8,0x03,0x46,0x6f,0x6f]);


use bitsparrow::Decoder;

let buffer = &[0x64,0x03,0x46,0x6f,0x6f];
let mut decoder = Decoder::new(buffer);

assert_eq!(100u8, decoder.uint8().unwrap());
assert_eq!("Foo", decoder.string().unwrap());
assert_eq!(true, decoder.end());

Decoder allows you to retrieve the values in order they were encoded. Calling the end method is optional - it will return true if you have read the entire buffer, ensuring the entire buffer has been read.



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.


Encoder takes in typed data and produces a binary buffer represented as Vec<u8>.



Simple error type returned either by the Decoder or Encoder