#serialization #nuts #binary-format #binary-data #nuts-bytes

macro nuts-bytes-derive

Serialization into a binary data format

23 unstable releases (4 breaking)

new 0.7.5 Nov 8, 2024
0.7.2 Sep 27, 2024
0.6.8 Jul 31, 2024
0.5.0 Mar 5, 2024
0.2.1 Nov 17, 2023

#10 in #nuts

Download history 4/week @ 2024-07-22 152/week @ 2024-07-29 8/week @ 2024-08-05 15/week @ 2024-08-12 3/week @ 2024-08-19 37/week @ 2024-08-26 187/week @ 2024-09-02 8/week @ 2024-09-09 224/week @ 2024-09-16 288/week @ 2024-09-23 42/week @ 2024-09-30 14/week @ 2024-10-07 172/week @ 2024-10-14 156/week @ 2024-10-21 16/week @ 2024-10-28 144/week @ 2024-11-04

489 downloads per month
Used in 5 crates (via nuts-bytes)

MIT license

25KB
422 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

~205–640KB
~15K SLoC