3 releases (unstable)
Uses old Rust 2015
2.0.0-rc2 | Feb 23, 2017 |
---|---|
0.1.1 | Feb 16, 2017 |
0.1.0 | Feb 16, 2017 |
#62 in #bar
10KB
166 lines
Derive macros for BitSparrow in Rust
Usage
#[macro_use]
extern crate bitsparrow_derive;
extern crate bitsparrow;
use bitsparrow::*;
#[derive(BitEncode, BitDecode, PartialEq, Debug)]
struct Foo {
bar: Vec<Bar>,
baz: String,
derp: bool,
}
#[derive(BitEncode, BitDecode, PartialEq, Debug)]
struct Bar(u16);
fn main() {
let foo = Foo {
bar: vec![Bar(10), Bar(1337)],
baz: "Hello world".into(),
derp: true,
};
let expect = vec![
2, // Vec length
0x00,0x0A, // |-> 10
0x05,0x39, // `-> 1337
11, // String length
b'H',b'e',b'l',b'l',b'o',b' ',b'w',b'o',b'r',b'l',b'd', // `-> String data
1 // bool
];
let buffer = Encoder::encode(&foo);
let decoded: Foo = Decoder::decode(&buffer).unwrap();
assert_eq!(buffer, expect);
assert_eq!(decoded, foo);
}
Dependencies
~2MB
~42K SLoC