Trait bitcoin::consensus::encode::Decodable

source ·
pub trait Decodable: Sized {
    // Provided methods
    fn consensus_decode_from_finite_reader<R: BufRead + ?Sized>(
        reader: &mut R
    ) -> Result<Self, Error> { ... }
    fn consensus_decode<R: BufRead + ?Sized>(
        reader: &mut R
    ) -> Result<Self, Error> { ... }
}
Expand description

Data which can be encoded in a consensus-consistent way.

Provided Methods§

source

fn consensus_decode_from_finite_reader<R: BufRead + ?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 to consensus_decode_bytes_from_finite_reader with the reader wrapped by Take. 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.
  • 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 call consensus_decode_from_finite_reader on all members, to avoid creating redundant Take wrappers. Failure to do so might result only in a tiny performance hit.
source

fn consensus_decode<R: BufRead + ?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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Decodable for Cow<'static, str>

source§

impl Decodable for bool

source§

impl Decodable for i8

source§

impl Decodable for i16

source§

impl Decodable for i32

source§

impl Decodable for i64

source§

impl Decodable for u8

source§

impl Decodable for u16

source§

impl Decodable for u32

source§

impl Decodable for u64

source§

impl Decodable for Box<[u8]>

source§

impl Decodable for String

source§

impl Decodable for Vec<(u32, Address)>

source§

impl Decodable for Vec<Inventory>

source§

impl Decodable for Vec<u8>

source§

impl Decodable for Vec<u64>

source§

impl Decodable for Vec<PrefilledTransaction>

source§

impl Decodable for Vec<ShortId>

source§

impl Decodable for Vec<Header>

source§

impl Decodable for Vec<AddrV2Message>

source§

impl Decodable for Vec<BlockHash>

source§

impl Decodable for Vec<FilterHash>

source§

impl Decodable for Vec<FilterHeader>

source§

impl Decodable for Vec<TapLeafHash>

source§

impl Decodable for Vec<Transaction>

source§

impl Decodable for Vec<TxIn>

source§

impl Decodable for Vec<TxMerkleNode>

source§

impl Decodable for Vec<TxOut>

source§

impl Decodable for Vec<VarInt>

source§

impl Decodable for Vec<Vec<u8>>

source§

impl Decodable for Hash

source§

impl Decodable for Hash

source§

impl Decodable for [u8; 2]

source§

impl Decodable for [u8; 4]

source§

impl Decodable for [u8; 6]

source§

impl Decodable for [u8; 8]

source§

impl Decodable for [u8; 10]

source§

impl Decodable for [u8; 12]

source§

impl Decodable for [u8; 16]

source§

impl Decodable for [u8; 32]

source§

impl Decodable for [u8; 33]

source§

impl Decodable for [u16; 8]

source§

impl<T0: Decodable, T1: Decodable> Decodable for (T0, T1)

source§

impl<T0: Decodable, T1: Decodable, T2: Decodable> Decodable for (T0, T1, T2)

source§

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)

source§

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)

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)

Implementors§

source§

impl Decodable for LockTime

source§

impl Decodable for AddrV2

Available on crate feature std only.
source§

impl Decodable for Inventory

Available on crate feature std only.
source§

impl Decodable for BloomFlags

Available on crate feature std only.
source§

impl Decodable for RejectReason

Available on crate feature std only.
source§

impl Decodable for BlockTransactions

source§

impl Decodable for BlockTransactionsRequest

source§

impl Decodable for HeaderAndShortIds

source§

impl Decodable for PrefilledTransaction

source§

impl Decodable for ShortId

source§

impl Decodable for Header

source§

impl Decodable for bitcoin::block::Version

source§

impl Decodable for ScriptBuf

source§

impl Decodable for MerkleBlock

source§

impl Decodable for PartialMerkleTree

source§

impl Decodable for AddrV2Message

Available on crate feature std only.
source§

impl Decodable for CommandString

Available on crate feature std only.
source§

impl Decodable for RawNetworkMessage

Available on crate feature std only.
source§

impl Decodable for GetBlocksMessage

Available on crate feature std only.
source§

impl Decodable for GetHeadersMessage

Available on crate feature std only.
source§

impl Decodable for FilterAdd

Available on crate feature std only.
source§

impl Decodable for FilterLoad

Available on crate feature std only.
source§

impl Decodable for BlockTxn

Available on crate feature std only.
source§

impl Decodable for CmpctBlock

Available on crate feature std only.
source§

impl Decodable for GetBlockTxn

Available on crate feature std only.
source§

impl Decodable for SendCmpct

Available on crate feature std only.
source§

impl Decodable for CFCheckpt

Available on crate feature std only.
source§

impl Decodable for CFHeaders

Available on crate feature std only.
source§

impl Decodable for CFilter

Available on crate feature std only.
source§

impl Decodable for GetCFCheckpt

Available on crate feature std only.
source§

impl Decodable for GetCFHeaders

Available on crate feature std only.
source§

impl Decodable for GetCFilters

Available on crate feature std only.
source§

impl Decodable for Reject

Available on crate feature std only.
source§

impl Decodable for VersionMessage

Available on crate feature std only.
source§

impl Decodable for Address

Available on crate feature std only.
source§

impl Decodable for Magic

source§

impl Decodable for ServiceFlags

source§

impl Decodable for Amount

source§

impl Decodable for Block

source§

impl Decodable for BlockHash

source§

impl Decodable for CompactTarget

source§

impl Decodable for FilterHash

source§

impl Decodable for FilterHeader

source§

impl Decodable for OutPoint

source§

impl Decodable for Sequence

source§

impl Decodable for TapLeafHash

source§

impl Decodable for Transaction

source§

impl Decodable for TxIn

source§

impl Decodable for TxMerkleNode

source§

impl Decodable for TxOut

source§

impl Decodable for Txid

source§

impl Decodable for VarInt

source§

impl Decodable for Witness

source§

impl Decodable for WitnessMerkleNode

source§

impl Decodable for Wtxid

source§

impl Decodable for bitcoin::transaction::Version

source§

impl Decodable for CheckedData

source§

impl<Subtype> Decodable for ProprietaryKey<Subtype>
where Subtype: Copy + From<u8> + Into<u8>,