Deku

Latest Version Rust Documentation Actions Status codecov

Declarative binary reading and writing

This crate provides bit-level, symmetric, serialization/deserialization implementations for structs and enums

Why use Deku

Productivity: Focus and declare your types that represent the data, Deku will generate symmetric reader/writer functions for your type! Avoid the requirement of writing redundant, error-prone parsing and writing code for binary structs or network headers

no_std: Compatible with #![no_std]

Usage

toml [dependencies] deku = "0.3"

no_std: toml [dependencies] deku = { version = "0.3", default-features = false, features = ["alloc"] }

Example

See documentation or examples folder for more!

Simple example, let's read big-endian data into a struct, with fields containing different sizes, modify a value, and write it back

```rust use deku::prelude::*;

[derive(Debug, PartialEq, DekuRead, DekuWrite)]

[deku(endian = "big")]

struct DekuTest { #[deku(bits = "4")] fielda: u8, #[deku(bits = "4")] fieldb: u8, field_c: u16, }

let data: Vec = vec![0b01101001, 0xBE, 0xEF]; let (rest, mut val) = DekuTest::frombytes((data.asref(), 0)).unwrap(); asserteq!(DekuTest { fielda: 0b0110, fieldb: 0b1001, fieldc: 0xBEEF, }, val);

val.field_c = 0xC0FE;

let dataout = val.tobytes().unwrap(); asserteq!(vec![0b01101001, 0xC0, 0xFE], data_out); ```