#[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);
}
-
Notifications
You must be signed in to change notification settings - Fork 1
Derive `BitEncode` and `BitDecode` for the Rust implementation
License
bitsparrow/bitsparrow-derive
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Derive `BitEncode` and `BitDecode` for the Rust implementation
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published