tendermint_proto/serializers.rs
1//! Serde JSON serializers
2//!
3//! Serializers and deserializers for a transparent developer experience.
4//!
5//! CAUTION: There are no guarantees for backwards compatibility, this module should be considered
6//! an internal implementation detail which can vanish without further warning. Use at your own
7//! risk.
8//!
9//! All serializers are presented in a serializers::<Rust_nickname>::<JSON_representation_name>
10//! format.
11//!
12//! This example shows how to serialize `Vec<u8>` into different types of strings:
13//! ```ignore
14//! use serde::{Serialize, Deserialize};
15//! use crate::serializers;
16//!
17//! #[derive(Serialize, Deserialize)]
18//! struct ByteTypes {
19//!
20//! #[serde(with="serializers::bytes::hexstring")]
21//! hexbytes: Vec<u8>,
22//!
23//! #[serde(with="serializers::bytes::base64string")]
24//! base64bytes: Vec<u8>,
25//!
26//! #[serde(with="serializers::bytes::string")]
27//! bytes: Vec<u8>,
28//!
29//! }
30//! ```
31//!
32//! Available serializers:
33//!
34//! | Field Type | String Format | Serializer |
35//! |--------------|-------------------------------|-------------------|
36//! | `i64` | e.g. `-5` | [`from_str`] |
37//! | `u64` | e.g. `100` | [`from_str`] |
38//! | [`Duration`] | Nanoseconds (e.g. `100`) | [`time_duration`] |
39//! | `Vec<u8>` | Hexadecimal (e.g. `1AF2B3C4`) | [`hexstring`] |
40//! | `Vec<u8>` | Base64-encoded | [`base64string`] |
41//! | `Vec<u8>` | Raw bytes in string | [`string`] |
42//!
43//! Notes:
44//! * Any type that has the "FromStr" trait can be serialized into a string with
45//! serializers::primitives::string.
46//! * serializers::bytes::* deserializes a null value into an empty vec![].
47//!
48//! [`Duration`]: core::time::Duration
49//! [`hexstring`]: bytes::hexstring
50//! [`base64string`]: bytes::base64string
51//! [`string`]: bytes::string
52
53// Todo: remove dead_code allowance as soon as more types are implemented
54#![allow(dead_code)]
55
56pub mod allow_null;
57pub mod bytes;
58pub mod cow_str;
59pub mod evidence;
60pub mod from_str;
61pub mod from_str_allow_null;
62pub mod nullable;
63pub mod optional;
64pub mod optional_from_str;
65pub mod part_set_header_total;
66pub mod time_duration;
67pub mod timestamp;
68pub mod txs;
69
70mod public_key;