Trait strict_encoding::StrictEncode
source · pub trait StrictEncode {
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>;
fn strict_serialize(&self) -> Result<Vec<u8>, Error> { ... }
fn strict_file_save(&self, path: impl AsRef<Path>) -> Result<usize, 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§
sourcefn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
Encode with the given std::io::Write
instance; must return result
with either amount of bytes encoded – or implementation-specific
error type.
Provided Methods§
sourcefn strict_serialize(&self) -> Result<Vec<u8>, Error>
fn strict_serialize(&self) -> Result<Vec<u8>, Error>
Serializes data as a byte array using StrictEncode::strict_encode
function
Implementations on Foreign Types§
source§impl StrictEncode for FlagVec
impl StrictEncode for FlagVec
source§impl StrictEncode for u256
impl StrictEncode for u256
source§impl StrictEncode for u512
impl StrictEncode for u512
source§impl StrictEncode for u1024
impl StrictEncode for u1024
source§impl StrictEncode for i256
impl StrictEncode for i256
source§impl StrictEncode for i512
impl StrictEncode for i512
source§impl StrictEncode for i1024
impl StrictEncode for i1024
source§impl StrictEncode for bf16
impl StrictEncode for bf16
source§impl StrictEncode for Half
impl StrictEncode for Half
source§impl StrictEncode for Quad
impl StrictEncode for Quad
source§impl StrictEncode for Oct
impl StrictEncode for Oct
source§impl StrictEncode for X87DoubleExtended
impl StrictEncode for X87DoubleExtended
source§impl StrictEncode for LeafVersion
impl StrictEncode for LeafVersion
source§impl StrictEncode for FutureLeafVersion
impl StrictEncode for FutureLeafVersion
source§impl StrictEncode for TaprootMerkleBranch
impl StrictEncode for TaprootMerkleBranch
source§impl StrictEncode for SecretKey
impl StrictEncode for SecretKey
source§impl StrictEncode for TweakedKeyPair
impl StrictEncode for TweakedKeyPair
source§impl StrictEncode for KeyPair
impl StrictEncode for KeyPair
source§impl StrictEncode for PublicKey
impl StrictEncode for PublicKey
source§impl StrictEncode for XOnlyPublicKey
impl StrictEncode for XOnlyPublicKey
source§impl StrictEncode for TweakedPublicKey
impl StrictEncode for TweakedPublicKey
source§impl StrictEncode for Signature
impl StrictEncode for Signature
source§impl StrictEncode for Signature
impl StrictEncode for Signature
source§impl StrictEncode for PsbtSighashType
impl StrictEncode for PsbtSighashType
source§impl StrictEncode for EcdsaSighashType
impl StrictEncode for EcdsaSighashType
source§impl StrictEncode for SchnorrSighashType
impl StrictEncode for SchnorrSighashType
source§impl StrictEncode for EcdsaSig
impl StrictEncode for EcdsaSig
source§impl StrictEncode for SchnorrSig
impl StrictEncode for SchnorrSig
source§impl StrictEncode for Payload
impl StrictEncode for Payload
source§impl StrictEncode for Address
impl StrictEncode for Address
source§impl StrictEncode for Amount
impl StrictEncode for Amount
source§impl StrictEncode for Script
impl StrictEncode for Script
source§impl StrictEncode for ControlBlock
impl StrictEncode for ControlBlock
source§impl StrictEncode for ScriptLeaf
impl StrictEncode for ScriptLeaf
source§impl StrictEncode for Network
impl StrictEncode for Network
source§impl StrictEncode for ChildNumber
impl StrictEncode for ChildNumber
source§impl StrictEncode for DerivationPath
impl StrictEncode for DerivationPath
source§impl StrictEncode for ChainCode
impl StrictEncode for ChainCode
source§impl StrictEncode for Fingerprint
impl StrictEncode for Fingerprint
source§impl StrictEncode for ExtendedPubKey
impl StrictEncode for ExtendedPubKey
source§impl StrictEncode for ExtendedPrivKey
impl StrictEncode for ExtendedPrivKey
source§impl StrictEncode for Key
impl StrictEncode for Key
source§impl StrictEncode for Pair
impl StrictEncode for Pair
source§impl StrictEncode for ProprietaryKey
impl StrictEncode for ProprietaryKey
source§impl StrictEncode for TapTree
impl StrictEncode for TapTree
source§impl<T> StrictEncode for Range<T>where
T: StrictEncode,
impl<T> StrictEncode for Range<T>where
T: StrictEncode,
In terms of strict encoding, ranges are encoded as a tuples of two values: start and end.
source§impl<T> StrictEncode for RangeInclusive<T>where
T: StrictEncode,
impl<T> StrictEncode for RangeInclusive<T>where
T: StrictEncode,
In terms of strict encoding, inclusive ranges are encoded as a tuples of two values: start and end.
source§impl<T> StrictEncode for RangeFrom<T>where
T: StrictEncode,
impl<T> StrictEncode for RangeFrom<T>where
T: StrictEncode,
In terms of strict encoding, partial ranges are encoded as a single value.
source§impl<T> StrictEncode for RangeTo<T>where
T: StrictEncode,
impl<T> StrictEncode for RangeTo<T>where
T: StrictEncode,
In terms of strict encoding, partial ranges are encoded as a single value.
source§impl<T> StrictEncode for RangeToInclusive<T>where
T: StrictEncode,
impl<T> StrictEncode for RangeToInclusive<T>where
T: StrictEncode,
In terms of strict encoding, partial ranges are encoded as a single value.
source§impl<T> StrictEncode for Option<T>where
T: StrictEncode,
impl<T> StrictEncode for Option<T>where
T: StrictEncode,
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.
source§impl<T> StrictEncode for [T]where
T: StrictEncode,
impl<T> StrictEncode for [T]where
T: StrictEncode,
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.
source§impl<T> StrictEncode for Vec<T>where
T: StrictEncode,
impl<T> StrictEncode for Vec<T>where
T: StrictEncode,
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.
source§impl<T> StrictEncode for HashSet<T>where
T: StrictEncode + Eq + Ord + Hash + Debug,
impl<T> StrictEncode for HashSet<T>where
T: StrictEncode + Eq + Ord + Hash + Debug,
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
source§impl<T> StrictEncode for BTreeSet<T>where
T: StrictEncode + Eq + Ord + Debug,
impl<T> StrictEncode for BTreeSet<T>where
T: StrictEncode + Eq + Ord + Debug,
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
source§impl<T> StrictEncode for HashMap<usize, T>where
T: StrictEncode + Clone,
impl<T> StrictEncode for HashMap<usize, T>where
T: StrictEncode + Clone,
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>
.
source§impl<K, V> StrictEncode for BTreeMap<K, V>where
K: StrictEncode + Ord + Clone,
V: StrictEncode + Clone,
impl<K, V> StrictEncode for BTreeMap<K, V>where
K: StrictEncode + Ord + Clone,
V: StrictEncode + Clone,
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.
source§impl<K, V> StrictEncode for (K, V)where
K: StrictEncode + Clone,
V: StrictEncode + Clone,
impl<K, V> StrictEncode for (K, V)where
K: StrictEncode + Clone,
V: StrictEncode + Clone,
Two-component tuples are encoded as they were fields in the parent data structure