simple_parse

crates.io mio Lines of Code

A declarative converter for Rust type to and 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 types !

For bit level control or more advanced features, take a look at deku.

Usage

```Rust use ::simple_parse::{SpRead, SpWrite};

[derive(SpRead, SpWrite)]

pub struct SomeStruct { pub some_field: u8, #[sp(endian="big")] pub items: Vec, }

let mut cursor: &[u8] = &[ 1, // some_field 2,0,0,0,0,0,0,0, // items.len() 0xDE,0xAD,0xBE,0xEF, // items[0] 0xBA,0xDC,0x0F,0xFE // items[1] ];

// Decode bytes into a struct let mut mystruct = SomeStruct::fromreader(&mut cursor)?;

/// Modify the struct my_struct.items.push(0xFFFFFFFF);

/// Encode modified struct into bytes let mut dstbuf: Vec = Vec::new(); mystruct.towriter(&mut dstbuf)?; //dst_buf == [1,3,0,0,0,0,0,0,0,0xDE,0xAD,0xBE,0xEF,0xBA,0xDC,0x0F,0xFE,0xFF,0xFF,0xFF,0xFF] ```

For complete examples see : examples

Features

| Feature | Description | |:----:|:----| | No-Copy parsing | simpleparse is able to generate references into byte slices (see struct.rs) | | count | Annotating a dynamically sized field with count allows it's number of items to live somewhere else in the struct. The default is to simply prepend the number of items as a u64| | endian | Annotating structs/fields with endian gives control over how numbers will be parsed | |Custom read/write | Custom parsers can be writen for individual fields when simpleparse doesnt have the adequate default implementation|