pub trait Decodable: Sized {
// Provided methods
fn consensus_decode_partial_from_finite_reader<R: Read>(
r: &mut R,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError> { ... }
fn consensus_decode_whole(
slice: &[u8],
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError> { ... }
fn consensus_decode_partial<R: Read>(
r: &mut R,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError> { ... }
fn consensus_decode_hex(
hex: &str,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError> { ... }
}Expand description
Data which can be encoded in a consensus-consistent way
Provided Methods§
Sourcefn consensus_decode_partial_from_finite_reader<R: Read>(
r: &mut R,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError>
fn consensus_decode_partial_from_finite_reader<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Decode Self from a size-limited reader.
Like consensus_decode_partial but relies on the reader being limited
in the amount of data it returns, e.g. by being wrapped in
std::io::Take.
Failing to abide to this requirement might lead to memory exhaustion caused by malicious inputs.
Users should default to consensus_decode_partial, but when data to be
decoded is already in a byte vector of a limited size, calling this
function directly might be marginally faster (due to avoiding extra
checks).
§Rules for trait implementations
- Simple types that that have a fixed size (own and member fields),
don’t have to overwrite this method, or be concern with it, should
only impl
consensus_decode_partial. - Types that deserialize based on decoded untrusted length should
implement
consensus_decode_partial_from_finite_readeronly:- Default implementation of
consensus_decode_partialwill forward toconsensus_decode_partial_from_finite_readerwith the reader wrapped byTake, protecting from readers that keep returning data. - Implementation must make sure to put a cap on things like
Vec::with_capacityand other allocations to avoid oversized allocations, and rely on the reader being finite and running out of data, and collections reallocating on a legitimately oversized input data, instead of trying to enforce arbitrary length limits.
- Default implementation of
- Types that contain other types that might be require limited reader
(thus implementing
consensus_decode_partial_from_finite_reader), should also implement it applying same rules, and in addition make sure to callconsensus_decode_partial_from_finite_readeron all members, to avoid creating redundantTakewrappers (Take<Take<...>>). Failure to do so might result only in a tiny performance hit.
fn consensus_decode_whole( slice: &[u8], modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Sourcefn consensus_decode_partial<R: Read>(
r: &mut R,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError>
fn consensus_decode_partial<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Decode an object with a well-defined format.
This is the method that should be implemented for a typical, fixed sized
type implementing this trait. Default implementation is wrapping the
reader in std::io::Take to limit the input size to
MAX_DECODE_SIZE, and forwards the call to
Self::consensus_decode_partial_from_finite_reader, which is
convenient for types that override
Self::consensus_decode_partial_from_finite_reader instead.
Sourcefn consensus_decode_hex(
hex: &str,
modules: &ModuleDecoderRegistry,
) -> Result<Self, DecodeError>
fn consensus_decode_hex( hex: &str, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Decode an object from hex
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Decodable for Cow<'static, str>
impl Decodable for Cow<'static, str>
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for bool
impl Decodable for bool
fn consensus_decode_partial<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for u8
impl Decodable for u8
fn consensus_decode_partial<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for u16
impl Decodable for u16
fn consensus_decode_partial<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for u32
impl Decodable for u32
fn consensus_decode_partial<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for u64
impl Decodable for u64
fn consensus_decode_partial<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for ()
impl Decodable for ()
fn consensus_decode_partial<D: Read>( _d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for String
impl Decodable for String
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Address<NetworkUnchecked>
impl Decodable for Address<NetworkUnchecked>
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Amount
impl Decodable for Amount
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for BigSize
impl Decodable for BigSize
fn consensus_decode_partial<R: Read>( r: &mut R, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for BlockHash
impl Decodable for BlockHash
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Bolt11Invoice
impl Decodable for Bolt11Invoice
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Ciphertext
impl Decodable for Ciphertext
fn consensus_decode_partial<R: Read>( reader: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
fn consensus_decode_partial<R: Read>( reader: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for G1Affine
impl Decodable for G1Affine
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for G1Projective
impl Decodable for G1Projective
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for G2Affine
impl Decodable for G2Affine
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for G2Projective
impl Decodable for G2Projective
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Hash
impl Decodable for Hash
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Hash
impl Decodable for Hash
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Header
impl Decodable for Header
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Keypair
impl Decodable for Keypair
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Network
impl Decodable for Network
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for OutPoint
impl Decodable for OutPoint
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for PartialMerkleTree
impl Decodable for PartialMerkleTree
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Psbt
impl Decodable for Psbt
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for PublicKey
impl Decodable for PublicKey
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for PublicKey
impl Decodable for PublicKey
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for PublicKey
impl Decodable for PublicKey
fn consensus_decode_partial<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for PublicKeySet
impl Decodable for PublicKeySet
fn consensus_decode_partial<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for RoutingFees
impl Decodable for RoutingFees
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Scalar
impl Decodable for Scalar
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for ScriptBuf
impl Decodable for ScriptBuf
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for SecretKey
impl Decodable for SecretKey
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for SecretKey
impl Decodable for SecretKey
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Signature
impl Decodable for Signature
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Signature
impl Decodable for Signature
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Transaction
impl Decodable for Transaction
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for TxOut
impl Decodable for TxOut
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for Txid
impl Decodable for Txid
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, _modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
fn consensus_decode_hex( hex: &str, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl Decodable for XOnlyPublicKey
impl Decodable for XOnlyPublicKey
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<K> Decodable for BTreeSet<K>
impl<K> Decodable for BTreeSet<K>
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<K> Decodable for Descriptor<K>
impl<K> Decodable for Descriptor<K>
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<K, V> Decodable for BTreeMap<K, V>
impl<K, V> Decodable for BTreeMap<K, V>
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T1: Decodable, T2: Decodable> Decodable for (T1, T2)
impl<T1: Decodable, T2: Decodable> Decodable for (T1, T2)
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T1: Decodable, T2: Decodable, T3: Decodable> Decodable for (T1, T2, T3)
impl<T1: Decodable, T2: Decodable, T3: Decodable> Decodable for (T1, T2, T3)
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable> Decodable for (T1, T2, T3, T4)
impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable> Decodable for (T1, T2, T3, T4)
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable> Decodable for (T1, T2, T3, T4, T5)
impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable> Decodable for (T1, T2, T3, T4, T5)
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable> Decodable for (T1, T2, T3, T4, T5, T6)
impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable> Decodable for (T1, T2, T3, T4, T5, T6)
fn consensus_decode_partial<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T> Decodable for Option<T>where
T: Decodable,
impl<T> Decodable for Option<T>where
T: Decodable,
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T> Decodable for Box<T>where
T: Decodable,
impl<T> Decodable for Box<T>where
T: Decodable,
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T> Decodable for VecDeque<T>where
T: Decodable + 'static,
Uses the same zero-sized element policy as Vec<T>: empty deques are
supported, but nonempty deques of zero-sized types return a decode error.
impl<T> Decodable for VecDeque<T>where
T: Decodable + 'static,
Uses the same zero-sized element policy as Vec<T>: empty deques are
supported, but nonempty deques of zero-sized types return a decode error.
fn consensus_decode_partial_from_finite_reader<D: Read>( d: &mut D, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>
Source§impl<T> Decodable for Vec<T>where
T: Decodable + 'static,
Empty vectors are supported for all element types. Nonempty vectors of
zero-sized types return a decode error without invoking the element decoder.
A finite reader alone cannot bound iteration over elements that consume no
bytes.
impl<T> Decodable for Vec<T>where
T: Decodable + 'static,
Empty vectors are supported for all element types. Nonempty vectors of zero-sized types return a decode error without invoking the element decoder. A finite reader alone cannot bound iteration over elements that consume no bytes.