#data-encoding #serialization #mavryk #binary-format #deserialize #codec #compatible

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

#2112 in Encoding

Download history 17/week @ 2024-07-21 91/week @ 2024-07-28 67/week @ 2024-08-04 146/week @ 2024-08-11 35/week @ 2024-08-18 43/week @ 2024-08-25 37/week @ 2024-09-01 9/week @ 2024-09-08 48/week @ 2024-09-15 33/week @ 2024-09-22 23/week @ 2024-09-29 13/week @ 2024-10-13 9/week @ 2024-10-20 38/week @ 2024-10-27 69/week @ 2024-11-03

129 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

~4.5–7MB
~132K SLoC