bin_io
is a crate inspired greatly by nom
and
other parser combinator libraries.
But bin_io
differs from those crates since
it aims at providing both reading and writing
facilities at the same time, with fewer code.
Add bin_io = "0.1"
to your Cargo.toml
```rust use std::io::Cursor; use binio::{ boilerplate, seq, read, write }; use binio::numbers::{ beu8, beu16 };
struct Thing { a: u8, b: u16 }
boilerplate!( fn thingparser() -> Thing { seq!( Thing { a, b }, a: beu8() => b: be_u16() => ) } );
let mut vec = Vec::new(); let mut cursor = Cursor::new(vec);
let my_thing = Thing { a: 0x10, b: 0x20 };
write(&mut cursor, mything.clone(), thingparser()) .unwrap();
cursor.set_position(0);
let otherthing = read(&mut cursor, thingparser()) .unwrap();
asserteq!(otherthing, my_thing); ```