dbin: Declarative binary parser
Like regular expression, but for binary data
A lightweight utility for parsing and rendering binary data
It's meant to be a bit quick and dirty and convenient.
Even if it might not exhaustively cover all cases, it should
be able to cover a lot of them with minimal effort. You know,
like regular expressions.
Example
extern crate::dbin;
use dbin::Spec;
use dbin::Data;
fn main() {
let bytes = dbin::render((
1234u64,
50000u16,
));
let spec = Spec::en(vec![
("big", Spec::st(vec![
Spec::be_magic_u64(1234),
Spec::be_uint(1),
Spec::be_uint(1),
])),
("little", Spec::st(vec![
Spec::le_magic_u64(1234),
Spec::le_uint(1),
Spec::le_uint(1),
])),
]);
let data = spec.parse(&bytes).unwrap();
assert_eq!(data, Data::Enum(
"little".into(),
Data::Struct(vec![
Data::Int(1234),
Data::Int(80),
Data::Int(195),
]).into(),
));
}