10 unstable releases (3 breaking)

0.5.0 Mar 5, 2024
0.4.3 Jan 22, 2024
0.2.2 Dec 5, 2023
0.2.1 Nov 17, 2023
0.1.0 Jun 9, 2023

#1864 in Encoding

Download history 17/week @ 2024-01-08 58/week @ 2024-01-15 29/week @ 2024-01-22 56/week @ 2024-02-12 13/week @ 2024-02-19 36/week @ 2024-02-26 153/week @ 2024-03-04 39/week @ 2024-03-11 4/week @ 2024-03-18 60/week @ 2024-04-01

61 downloads per month
Used in 6 crates (5 directly)

MIT license

59KB
955 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

~0.4–0.8MB
~19K SLoC