simple_parse is a declarative encoder/decoder for Rust structs to/from binary.
It provides basic implementations for most standard Rust types and also provides a derive macro to automatically implement the trait on your own Rust types !
For lower level control, take a look at deku.
```Rust use ::simple_parse::{SpRead, SpWrite};
pub struct SomeStruct {
pub some_field: u8,
nitems: u16,
#[sp(count="nitems", endian="big")]
pub items: Vec
let mut cursor: &[u8] = &[ 0x01, // some_field 0x00,0x02, // nitems (Field holding the number of Vec items) 0xDE,0xAD,0xBE,0xEF, // items[0] 0xBA,0xDC,0x0F,0xFE // items[1] ];
// Decode bytes into a struct let mut mystruct = SomeStruct::frombytes(&mut cursor)?;
/// Modify the struct my_struct.items.push(0xFFFFFFFF);
/// Encode modified struct into bytes
let mut dstbuf: Vec
For complete examples see : examples
| Type | Encoded size |
|:------:|:------:|
|u8\|u16\|u32\|u64\|u128\|usize| 1,2,4,8,16,sizeof(usize) |
|i8\|i16\|i32\|i64\|i128\|isize| 1,2,4,8,16,sizeof(usize) |
|raw ptr| sizeof(usize) |
|bool| 1 |
| String | sizeof(u64) + str.len()|
| CString | str.len() + 1 |
| Vec\