[][src]Module tendermint_proto::serializers

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 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: i64 <-> string: #[serde(with="serializers::from_str")] u64 <-> string: #[serde(with="serializers::from_str")] std::time::Duration <-> nanoseconds as string #[serde(with="serializers::time_duration")] Vec <-> HexString: #[serde(with="serializers::bytes::hexstring")] Vec <-> Base64String: #[serde(with="serializers::bytes::base64string")] Vec <-> String: #[serde(with="serializers::bytes::string")]

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

bytes

Serialize/deserialize bytes (Vec) type

evidence
from_str

Serialize and deserialize any T that implements [std::str::FromStr] and [std::fmt::Display] from or into string. Note this can be used for all primitive data types.

nullable

Serialize/deserialize nilable type into T, where nil turns into the default impl.

optional

Serialize/deserialize Option type where T has a serializer/deserializer. Use null if the received value equals the Default implementation.

part_set_header_total

Serialize and deserialize part_set_header.total (from string or u32), (into u32 in part_set_header.total).

time_duration

Serialize/deserialize std::time::Duration type from and into string:

timestamp

Serialize/deserialize Timestamp type from and into string:

txs

Serialize/deserialize Vec<Vec> type from and into transactions (Base64String array).