pub trait Decodable: Sized {
// Provided methods
fn consensus_decode_from_finite_reader<R: Read + ?Sized>(
reader: &mut R,
) -> Result<Self, Error> { ... }
fn consensus_decode<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Error> { ... }
}
Expand description
Data which can be encoded in a consensus-consistent way.
Provided Methods§
Sourcefn consensus_decode_from_finite_reader<R: Read + ?Sized>(
reader: &mut R,
) -> Result<Self, Error>
fn consensus_decode_from_finite_reader<R: Read + ?Sized>( reader: &mut R, ) -> Result<Self, Error>
Decode Self
from a size-limited reader.
Like consensus_decode
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
, 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.
- Types that deserialize using externally provided length should implement it:
- Make
consensus_decode
forward toconsensus_decode_bytes_from_finite_reader
with the reader wrapped byTake
. Failure to do so, without other forms of memory exhaustion protection might lead to resource exhaustion vulnerability. - Put a max cap on things like
Vec::with_capacity
to avoid oversized allocations, and rely on the reader running out of data, and collections reallocating on a legitimately oversized input data, instead of trying to enforce arbitrary length limits.
- Make
- Types that contain other types that implement custom
consensus_decode_from_finite_reader
, should also implement it applying same rules, and in addition make sure to callconsensus_decode_from_finite_reader
on all members, to avoid creating redundantTake
wrappers. Failure to do so might result only in a tiny performance hit.
Sourcefn consensus_decode<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Error>
fn consensus_decode<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Error>
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 crate::io::Take
to limit the input size to MAX_VEC_SIZE
, and forwards the call to
Self::consensus_decode_from_finite_reader
, which is convenient
for types that override Self::consensus_decode_from_finite_reader
instead.
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 Vec<PrefilledTransaction>
impl Decodable for Vec<PrefilledTransaction>
Source§impl Decodable for Vec<AddrV2Message>
impl Decodable for Vec<AddrV2Message>
Source§impl Decodable for Vec<FilterHash>
impl Decodable for Vec<FilterHash>
Source§impl Decodable for Vec<FilterHeader>
impl Decodable for Vec<FilterHeader>
Source§impl Decodable for Vec<TapLeafHash>
impl Decodable for Vec<TapLeafHash>
Source§impl Decodable for Vec<Transaction>
impl Decodable for Vec<Transaction>
Source§impl Decodable for Vec<TxMerkleNode>
impl Decodable for Vec<TxMerkleNode>
Source§impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable> Decodable for (T0, T1, T2, T3)
impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable> Decodable for (T0, T1, T2, T3)
Source§impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable> Decodable for (T0, T1, T2, T3, T4)
impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable> Decodable for (T0, T1, T2, T3, T4)
Source§impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable> Decodable for (T0, T1, T2, T3, T4, T5)
impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable> Decodable for (T0, T1, T2, T3, T4, T5)
Source§impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable> Decodable for (T0, T1, T2, T3, T4, T5, T6)
impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable> Decodable for (T0, T1, T2, T3, T4, T5, T6)
Source§impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable> Decodable for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable> Decodable for (T0, T1, T2, T3, T4, T5, T6, T7)
Implementors§
impl Decodable for LockTime
impl Decodable for AddrV2
std
only.impl Decodable for Inventory
std
only.impl Decodable for BloomFlags
std
only.impl Decodable for RejectReason
std
only.impl Decodable for BlockTransactions
impl Decodable for BlockTransactionsRequest
impl Decodable for HeaderAndShortIds
impl Decodable for PrefilledTransaction
impl Decodable for ShortId
impl Decodable for Header
impl Decodable for bitcoin::block::Version
impl Decodable for PartialMerkleTree
impl Decodable for AddrV2Message
std
only.impl Decodable for CommandString
std
only.impl Decodable for RawNetworkMessage
std
only.impl Decodable for GetBlocksMessage
std
only.impl Decodable for GetHeadersMessage
std
only.impl Decodable for FilterAdd
std
only.impl Decodable for FilterLoad
std
only.impl Decodable for BlockTxn
std
only.impl Decodable for CmpctBlock
std
only.impl Decodable for GetBlockTxn
std
only.impl Decodable for SendCmpct
std
only.impl Decodable for CFCheckpt
std
only.impl Decodable for CFHeaders
std
only.impl Decodable for CFilter
std
only.impl Decodable for GetCFCheckpt
std
only.impl Decodable for GetCFHeaders
std
only.impl Decodable for GetCFilters
std
only.impl Decodable for Reject
std
only.impl Decodable for VersionMessage
std
only.impl Decodable for Address
std
only.