pub trait StrictEncode {
    fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>;

    fn strict_serialize(&self) -> Result<Vec<u8>, Error> { ... }
}
Expand description

Binary encoding according to the strict rules that usually apply to consensus-critical data structures. May be used for network communications; in some circumstances may be used for commitment procedures; however it must be kept in mind that sometime commitment may follow “fold” scheme (Merklization or nested commitments) and in such cases this trait can’t be applied. It is generally recommended for consensus-related commitments to utilize CommitVerify, TryCommitVerify and EmbedCommitVerify traits
from commit_verify module.

Required Methods

Encode with the given std::io::Write instance; must return result with either amount of bytes encoded – or implementation-specific error type.

Provided Methods

Serializes data as a byte array using StrictEncode::strict_encode function

Implementations on Foreign Types

In terms of strict encoding, ranges are encoded as a tuples of two values: start and end.

In terms of strict encoding, inclusive ranges are encoded as a tuples of two values: start and end.

In terms of strict encoding, partial ranges are encoded as a single value.

In terms of strict encoding, partial ranges are encoded as a single value.

In terms of strict encoding, partial ranges are encoded as a single value.

In terms of strict encoding, Option (optional values) are
represented by a significator byte, which MUST be either 0 (for no value present) or 1, followed by the value strict encoding.

In terms of strict encoding, a slice is stored in form of usize-encoded length (see StrictEncode implementation for usize type for encoding platform-independent constant-length encoding rules) followed by a consequently-encoded vec items, according to their type.

In terms of strict encoding, Vec is stored in form of usize-encoded length (see StrictEncode implementation for usize type for encoding platform-independent constant-length encoding rules) followed by a consequently-encoded vec items, according to their type.

Strict encoding for a unique value collection represented by a rust HashSet type is performed in the same way as Vec encoding. NB: Array members must are ordered with the sort operation, so type T must implement Ord trait in such a way that it produces deterministically-sorted result

Strict encoding for a unique value collection represented by a rust BTreeSet type is performed in the same way as Vec encoding. NB: Array members must are ordered with the sort operation, so type T must implement Ord trait in such a way that it produces deterministically-sorted result

LNP/BP library uses HashMap<usize, T: StrictEncode>s to encode ordered lists, where the position of the list item must be fixed, since the item is referenced from elsewhere by its index. Thus, the library does not supports and recommends not to support strict encoding of any other HashMap variants.

Strict encoding of the HashMap<usize, T> type is performed by converting into a fixed-order Vec<T> and serializing it according to the Vec strict encoding rules. This operation is internally performed via conversion into BTreeMap<usize, T: StrictEncode>.

LNP/BP library uses BTreeMap<usize, T: StrictEncode>s to encode ordered lists, where the position of the list item must be fixed, since the item is referenced from elsewhere by its index. Thus, the library does not supports and recommends not to support strict encoding of any other BTreeMap variants.

Strict encoding of the BTreeMap<usize, T> type is performed by converting into a fixed-order Vec<T> and serializing it according to the Vec strict encoding rules.

Two-component tuples are encoded as they were fields in the parent data structure

Implementors