Crates.io | nuts-bytes-derive |
lib.rs | nuts-bytes-derive |
version | 0.7.5 |
source | src |
created_at | 2023-11-17 12:07:15.704729 |
updated_at | 2024-11-08 06:44:08.807062 |
description | Serialization into a binary data format |
homepage | |
repository | https://github.com/drobin/nuts.git |
max_upload_size | |
id | 1038998 |
size | 24,657 |
The nuts-bytes
crate implements a tool that converts structured data into a
binary format.
The API documentation is located here.
The binary format is specified in docs/format.md.
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)));
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]);
You can check out the full license here.
This project is licensed under the terms of the MIT license.