2 unstable releases
0.6.0 | Jul 2, 2024 |
---|---|
0.5.2 | Jul 2, 2024 |
#2112 in Encoding
129 downloads per month
Used in 9 crates
(7 directly)
99KB
2.5K
SLoC
Mavryk data encoding
Helpers for (de)serialization of rust structures, to match the binary format produced by the Data_encoding
libary
used by mavkit.
lib.rs
:
This crate provides serialization and deserialization functionality for the data types used by the Mavryk shell.
You can either implement NomReader
and BinWriter
manually, or derive them.
Examples
Let's create encodings for a struct containing two arrays - one of fixed size, and one dynamic.
Derivation is supported across generic structs.
use mavryk_data_encoding::nom::NomReader;
use mavryk_data_encoding::enc::BinWriter;
use mavryk_data_encoding::encoding::HasEncoding;
const INNER_SIZE: usize = 10;
#[derive(Debug, PartialEq, HasEncoding, NomReader, BinWriter)]
struct Inner {
#[encoding(sized = "INNER_SIZE", bytes)]
fixed_size: Vec<u8>
}
#[derive(Debug, PartialEq, HasEncoding, NomReader, BinWriter)]
struct Outer<T>
where T: Debug + PartialEq + HasEncoding + for<'a> NomReader<'a> + BinWriter {
#[encoding(dynamic)]
dynamic_size: Vec<T>
}
#
#
#
#
#
Dependencies
~4.5–7MB
~132K SLoC