Expand description
Serde serialization implementation for 256-bit integer types.
This implementation is very JSON-centric in that it serializes the integer
types as QUANTITIES
as specified in the Ethereum RPC. That is, integers
are encoded as "0x"
prefixed strings without extrenuous leading 0
s. For
negative signed integers, the string is prefixed with a "-"
sign.
Note that this module contains alternative serialization schemes that can
be used with #[serde(with = "...")]
.
Examples
Basic usage:
#[derive(Deserialize, Serialize)]
struct Example {
a: U256, // "0x2a"
#[serde(with = "ethnum::serde::decimal")]
b: I256, // "-42"
#[serde(with = "ethnum::serde::prefixed")]
c: U256, // "0x2a" or "42"
#[serde(with = "ethnum::serde::permissive")]
d: I256, // "-0x2a" or "-42" or -42
#[serde(with = "ethnum::serde::bytes::be")]
e: U256, // [0x2a, 0x00, ..., 0x00]
#[serde(with = "ethnum::serde::bytes::le")]
f: I256, // [0xd6, 0xff, ..., 0xff]
#[serde(with = "ethnum::serde::compressed_bytes::be")]
g: U256, // [0x2a]
#[serde(with = "ethnum::serde::compressed_bytes::le")]
h: I256, // [0xd6]
}
Modules
- Serde byte serialization for 256-bit integer types.
- Serde compressed byte serialization for 256-bit integer types.
- Module for use with
#[serde(with = "ethnum::serde::decimal")]
to specify decimal string serialization for 256-bit integer types. - Module for use with
#[serde(with = "ethnum::serde::permissive")]
to specify extremely permissive serialization for 256-bit integer types. - Module for use with
#[serde(with = "ethnum::serde::prefixed")]
to specify prefixed string serialization for 256-bit integer types.