Expand description
Common types and operations used throughout the Concordium chain development.
Modules§
- cbor
- CBOR serialization
- encryption
- Module that provides a simple API for symmetric encryption in the output formats used by Concordium.
- types
- Common types needed in concordium.
- upward
Structs§
- Encoded
- Encoded data
Ausing the Concordium specific serializationSerial/Deserial. - Version
- Version of the serialization of a data structure. Binary coded as a variable integer represented by bytes, where MSB=1 indicates more bytes follow, and the 7 lower bits in a byte is Big Endian data bits for the value. A version number is bounded by u32 max.
- Versioned
Versioned<T>representsTas a versioned data-structure. The version is a integer number up to the implementation, which is serialized using variable integer encoding. The caller is responsible for ensuring the data structureTis compatible with the version number.
Constants§
- VERSION_
0 - Version 0 as a constant for ease of use.
Traits§
- Buffer
- Trait for writers which will not fail in normal operation with
small amounts of data, e.g.,
Vec<u8>. Moreover having a special trait allows us to implement it for other types, such as the SHA Digest. - Deserial
- Trait for types which can be recovered from byte sources.
- Get
- Analogue of Deserial, but instead this has the type to serialize as a type
parameter, and is implemented once for a source. The reason for this trait
is that it is often more convenient to use since we can rely on the
typechecker to fill in more details. Contrast
A::deserial(source)tosource.get(). In the latter case the return type is usually clear from context. - Put
- Dual to
Get, and the analogue ofSerial. It allows writingsink.put(value)in contrast tovalue.serial(sink). It is less important thanGet. - Read
Bytes Ext - Extends
Readwith methods for reading numbers. (Forstd::io.) - Serde
Deserialize - A data structure that can be deserialized from any data format supported by Serde.
- Serde
Deserializer - A data format that can deserialize any data structure supported by Serde.
- Serde
Serialize - A data structure that can be serialized into any data format supported by Serde.
- Serde
Serializer - A data format that can serialize any data structure supported by Serde.
- Serial
- Trait implemented by types which can be encoded into byte arrays. The intention is that the encoding is binary and not human readable.
- Serialize
- A convenient way to refer to both Serial and Deserial together.
- Write
Bytes Ext - Extends
Writewith methods for writing numbers. (Forstd::io.)
Functions§
- base16_
decode - Dual to base16_encode.
- base16_
decode_ string - Dual to base16_encode_string.
- base16_
encode - Encode the given value into a byte array using its Serial instance, and then encode that byte array as a hex string into the provided serde Serializer.
- base16_
encode_ string - Analogous to base16_encode, but encodes into a string rather than a serde Serializer.
- base16_
ignore_ length_ decode - Dual to base16_ignore_length_encode
- base16_
ignore_ length_ encode - Analogous to base16_encode but after serializing to a byte array it only
encodes the
&[4..]into the serde Serializer. This is intended to use in cases where we are encoding a collection such as a vector into JSON. Since JSON is self-describing we do not need to explicitly record the length, which we do in binary. - deserial_
bytes - Read a vector of the given size. NB: Be aware that this allocates a buffer of the given length, and so this must only be used when the size is bounded, otherwise it will lead to a memory allocation failure, and panic.
- deserial_
map_ no_ length - Deserialize a map from a byte source. This ensures there are no duplicates, as well as that all keys are in strictly increasing order.
- deserial_
set_ no_ length - Analogous to deserial_map_no_length, but for sets. NB: This ensures there are no duplicates, and that all the keys are in strictly increasing order.
- deserial_
string - Read a string of given size. NB: Be aware that this allocates a buffer of the given length, and so this must only be used when the size is bounded, otherwise it will lead to a memory allocation failure, and panic.
- deserial_
vector_ no_ length - Read a vector of a given size. This protects against excessive memory allocation by only pre-allocating a maximum safe size.
- from_
bytes - A small wrapper that is sometimes more convenient than
A::deserial. It is here mostly for historical reasons, for backwards compatibility. - safe_
with_ capacity - As Vec::with_capacity, but only allocate maximum MAX_PREALLOCATED_CAPACITY elements.
- serial_
iter - Serialize all of the elements in the iterator.
- serial_
map_ no_ length - Serialize an ordered map. Serialization is by increasing order of keys.
- serial_
set_ no_ length - Analogous to serial_map_no_length, but for sets.
- serial_
string - Write a string directly to the provided sink (without encoding its length). The string is utf8 encoded.
- serial_
vector_ no_ length - Write an array without including length information.
- to_
bytes - Directly serialize to a vector of bytes.
Type Aliases§
- Parse
Result - Result when deserializing a value. This is a simple wrapper around
Resultthat fixes the error type to be anyhow::Error. - size_t
Derive Macros§
- Cbor
Deserialize - Derive
CborDeserializeon the type. See the moduleconcordium_base::common::cbor. - Cbor
Serialize - Derive
CborSerializeon the type. See the moduleconcordium_base::common::cbor. - Deserial
- Derive the
Deserialtrait. At present this only applies tostruct’s. - Serde
Base16 Ignore Length Serialize - Like
SerdeBase16Serialize, but assuming that theconcordium_base::Serializeimplementation puts the length of the data as 4 bytes in big endian. These 4 bytes are dropped when converting to hex since the JSON format is self-describing so the length is not needed. - Serde
Base16 Serialize - Derive a
serde::Serializeandserde::Deserializeimplementations for the type. This differs fromserde’s serialization macros. Here the value is first serialized according to itsconcordium_base::Serializeimplementation and then hex encoded into a string. - Serde
Deserialize - Serde
Serialize - Serial
- Derive the
Serialtrait. At present this only applies tostruct’s. - Serialize
- Derive both
SerialandDeserialtraits. At present this only applies tostruct’s.