Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

sharksforarms/deku

Latest VersionRust DocumentationActions Statuscodecov

Declarative binary reading and writing

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

Why use Deku

Productivity: Deku will generate symmetric reader/writer functions for your type!Avoid the requirement of writing redundant, error-prone parsing and writing codefor binary structs or network headers

Usage

Compiler support: requires rustc 1.71+

[dependencies]deku ="0.18"

no_std:

[dependencies]deku = {version ="0.18",default-features =false,features = ["alloc"] }

Example

Seedocumentation orexamples folder for more!

Read big-endian data into a struct, modify a value, and write it

use deku::prelude::*;#[derive(Debug,PartialEq,DekuRead,DekuWrite)]#[deku(endian ="big")]structDekuTest{#[deku(bits =4)]field_a:u8,#[deku(bits =4)]field_b:u8,field_c:u16,}fnmain(){let data:Vec<u8> =vec![0b0110_1001,0xBE,0xEF];let(_rest,mut val) =DekuTest::from_bytes((data.as_ref(),0)).unwrap();assert_eq!(DekuTest{        field_a:0b0110,        field_b:0b1001,        field_c:0xBEEF,}, val);    val.field_c =0xC0FE;let data_out = val.to_bytes().unwrap();assert_eq!(vec![0b0110_1001,0xC0,0xFE], data_out);}

Changelog

SeeCHANGELOG.md

About

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp