Crate mavryk_data_encoding

Source
Expand description

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>
}

Modules§

binary_reader
Mavryk binary data reader.
binary_writer
Mavryk binary data writer.
enc
encoding
Schema used for serialization and deserialization.
nom
types
Defines types of the intermediate data format.

Macros§

has_encoding
Creates impl HasEncoding for given struct backed by lazy_static ref instance with encoding.