Module concordium_base::common

source ·
Expand description

Common types and operations used throughout the Concordium chain development.

Modules§

  • Module that provides a simple API for symmetric encryption in the output formats used by Concordium.
  • Common types needed in concordium.

Structs§

  • 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<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 as a constant for ease of use.

Traits§

  • 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.
  • Trait for types which can be recovered from byte sources.
  • 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.
  • 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.
  • Extends Read with methods for reading numbers. (For std::io.)
  • Derive macro to derive serde::Deserialize instances. A data structure that can be deserialized from any data format supported by Serde.
  • Derive macro to derive serde::Serialize instances. A data structure that can be serialized into any data format supported by Serde.
  • Trait implemented by types which can be encoded into byte arrays. The intention is that the encoding is binary and not human readable.
  • A convenient way to refer to both Serial and Deserial together.
  • Extends Write with methods for writing numbers. (For std::io.)

Functions§

  • Dual to 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.
  • Analogous to base16_encode, but encodes into a string rather than a serde Serializer.
  • 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.
  • 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.
  • Deserialize a map from a byte source. This ensures there are no duplicates, as well as that all keys are in strictly increasing order.
  • 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.
  • 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.
  • Read a vector of a given size. This protects against excessive memory allocation by only pre-allocating a maximum safe size.
  • A small wrapper that is sometimes more convenient than A::deserial. It is here mostly for historical reasons, for backwards compatibility.
  • As Vec::with_capacity, but only allocate maximum MAX_PREALLOCATED_CAPACITY elements.
  • Serialize all of the elements in the iterator.
  • Serialize an ordered map. Serialization is by increasing order of keys.
  • Analogous to serial_map_no_length, but for sets.
  • Write a string directly to the provided sink (without encoding its length). The string is utf8 encoded.
  • Write an array without including length information.
  • Directly serialize to a vector of bytes.

Type Aliases§

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

Derive Macros§