Module tendermint_proto::serializers

source ·
Expand description

Serde JSON serializers

Serializers and deserializers for a transparent developer experience.

CAUTION: There are no guarantees for backwards compatibility, this module should be considered an internal implementation detail which can vanish without further warning. Use at your own risk.

All serializers are presented in a serializers::<Rust_nickname>::<JSON_representation_name> format.

This example shows how to serialize Vec<u8> into different types of strings:

use serde::{Serialize, Deserialize};
use crate::serializers;

#[derive(Serialize, Deserialize)]
struct ByteTypes {

    #[serde(with="serializers::bytes::hexstring")]
    hexbytes: Vec<u8>,

    #[serde(with="serializers::bytes::base64string")]
    base64bytes: Vec<u8>,

    #[serde(with="serializers::bytes::string")]
    bytes: Vec<u8>,

}

Available serializers:

Field TypeString FormatSerializer
i64e.g. -5from_str
u64e.g. 100from_str
DurationNanoseconds (e.g. 100)time_duration
Vec<u8>Hexadecimal (e.g. 1AF2B3C4)hexstring
Vec<u8>Base64-encodedbase64string
Vec<u8>Raw bytes in stringstring

Notes:

  • Any type that has the “FromStr” trait can be serialized into a string with serializers::primitives::string.
  • serializers::bytes::* deserializes a null value into an empty vec![].

Modules§

  • Serialize/deserialize nilable value into T, where nil turns into the Default value.
  • Serialize/deserialize bytes (Vec<u8>) type
  • Serialize and deserialize any T that implements FromStr and Display to convert from or into string. Note this can be used for all primitive data types.
  • Combines from_str and allow_null.
  • Serialize/deserialize nilable type into T, where nil turns into the default impl.
  • Serialize/deserialize Option<T> type where T has a serializer/deserializer. Deserialize to None if the received value equals the Default value. Serialize None as Some with the Default value for T.
  • De/serialize an optional type that must be converted from/to a string.
  • Serialize and deserialize part_set_header.total (from string or u32), (into u32 in part_set_header.total).
  • Serialize/deserialize core::time::Duration type from and into string:
  • Serialize/deserialize Timestamp type from and into string:
  • Serialize/deserialize Vec<Vec<u8>> type from and into transactions (Base64String array).