Very fast!and flexible, This library used to serialize and deserialize data in binary format.
Inspaired by bincode, But much more flexible.
By default, the library uses little endian.
If you want to use big endian, you can set BE
features flag. And for native endian use NE
. For example:
toml
[dependencies]
bin-layout = { version = "0.1", features = ["BE"] }
The library is very flexible and easy to use. The only trait you need to implement is DataType.
All primitive types implement this trait.
And For collection types, Vec
and String
are supported. They are encoded with their length u32
value first, Following by each entry of the collection.
```rust use bin_layout::{DataType, def};
def!(Car, { name: String, year: u16, is_new: bool, });
def!(Company, { name: String, cars: Vec
let company = Company { name: "Tesla".into(), cars: vec![ Car { name: "Model S".into(), year: 2018, isnew: true }, Car { name: "Model X".into(), year: 2019, isnew: false }, ], };
let mut view = [0; 64].into(); company.serialize(&mut view);
view.offset = 0;
let company = Company::deserialize(&mut view).unwrap(); println!("{:#?}", company); ```