#data-encoding #mavryk #serialization #binary #type #dynamic #binary-format

mavryk_data_encoding

Utilities for encoding/decoding data compatible with mavryk data encoding

2 unstable releases

0.6.0 Jul 2, 2024
0.5.2 Jul 2, 2024

#1480 in Encoding

Download history 272/week @ 2024-07-01 19/week @ 2024-07-22 93/week @ 2024-07-29 66/week @ 2024-08-05 147/week @ 2024-08-12 39/week @ 2024-08-19 50/week @ 2024-08-26

306 downloads per month
Used in 9 crates (7 directly)

MIT license

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

~7.5MB
~149K SLoC