Module common

Module common 

Source
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 A using the Concordium specific serialization Serial/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> represents T as 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 structure T is 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) to source.get(). In the latter case the return type is usually clear from context.
Put
Dual to Get, and the analogue of Serial. It allows writing sink.put(value) in contrast to value.serial(sink). It is less important than Get.
ReadBytesExt
Extends Read with methods for reading numbers. (For std::io.)
SerdeDeserialize
A data structure that can be deserialized from any data format supported by Serde.
SerdeDeserializer
A data format that can deserialize any data structure supported by Serde.
SerdeSerialize
A data structure that can be serialized into any data format supported by Serde.
SerdeSerializer
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.
WriteBytesExt
Extends Write with methods for writing numbers. (For std::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§

ParseResult
Result when deserializing a value. This is a simple wrapper around Result that fixes the error type to be anyhow::Error.
size_t

Derive Macros§

CborDeserialize
Derive CborDeserialize on the type. See the module concordium_base::common::cbor.
CborSerialize
Derive CborSerialize on the type. See the module concordium_base::common::cbor.
Deserial
Derive the Deserial trait. At present this only applies to struct’s.
SerdeBase16IgnoreLengthSerialize
Like SerdeBase16Serialize, but assuming that the concordium_base::Serialize implementation 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.
SerdeBase16Serialize
Derive a serde::Serialize and serde::Deserialize implementations for the type. This differs from serde’s serialization macros. Here the value is first serialized according to its concordium_base::Serialize implementation and then hex encoded into a string.
SerdeDeserialize
SerdeSerialize
Serial
Derive the Serial trait. At present this only applies to struct’s.
Serialize
Derive both Serial and Deserial traits. At present this only applies to struct’s.