27 releases

new 0.7.7 Dec 18, 2024
0.7.5 Nov 8, 2024
0.6.8 Jul 31, 2024
0.5.0 Mar 5, 2024
0.1.0 Jun 9, 2023

#1887 in Encoding

Download history 191/week @ 2024-08-31 16/week @ 2024-09-07 198/week @ 2024-09-14 252/week @ 2024-09-21 77/week @ 2024-09-28 15/week @ 2024-10-05 158/week @ 2024-10-12 136/week @ 2024-10-19 34/week @ 2024-10-26 105/week @ 2024-11-02 50/week @ 2024-11-09 10/week @ 2024-11-16 11/week @ 2024-11-23 14/week @ 2024-11-30 182/week @ 2024-12-07 168/week @ 2024-12-14

376 downloads per month
Used in 4 crates (2 directly)

MIT license

59KB
957 lines

nuts-bytes: Conversion into a binary data format.

The nuts-bytes crate implements a tool that converts structured data into a binary format.

API documentation

The API documentation is located here.

Format specification

The binary format is specified in docs/format.md.

Deserialization example

use nuts_bytes::{Error, Reader, TakeBytesError};

// deserialize a primitive (u32)
let mut reader = Reader::new([0x00, 0x00, 0x02, 0x9A].as_slice());
let n: u32 = reader.read().unwrap();

assert_eq!(n, 666);

// Not enough data available
let mut reader = Reader::new([0; 3].as_slice());
let err = reader.read::<u32>().unwrap_err();

assert!(matches!(err, Error::TakeBytes(TakeBytesError::Eof)));

Serialization example

use nuts_bytes::Writer;

// serialize a primitive (u32)
let mut writer = Writer::new(vec![]);
writer.write(&666u32).unwrap();

assert_eq!(writer.into_target(), [0x00, 0x00, 0x02, 0x9A]);

License

You can check out the full license here.

This project is licensed under the terms of the MIT license.

Dependencies

~235–690KB
~16K SLoC