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

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

Provided Methods§

fn consensus_decode_from_finite_reader<R>(reader: &mut R) -> Result<Self, Error>where R: Read + ?Sized,

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.

Failling to obide 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.

fn consensus_decode<R>(reader: &mut R) -> Result<Self, Error>where R: Read + ?Sized,

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.

Implementations on Foreign Types§

§

impl Decodable for Vec<u8, Global>

§

impl Decodable for u64

§

fn consensus_decode<R>(r: &mut R) -> Result<u64, Error>where R: Read + ?Sized,

§

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

§

impl Decodable for [u8; 32]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 32], Error>where R: Read + ?Sized,

§

impl Decodable for [u8; 2]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 2], Error>where R: Read + ?Sized,

§

impl<T0, T1, T2, T3, T4, T5, T6> Decodable for (T0, T1, T2, T3, T4, T5, T6)where T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable,

§

impl Decodable for Vec<TxIn, Global>

§

impl Decodable for Vec<Transaction, Global>

§

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

§

impl Decodable for Vec<BlockHash, Global>

§

impl Decodable for [u8; 33]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 33], Error>where R: Read + ?Sized,

§

impl Decodable for [u8; 6]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 6], Error>where R: Read + ?Sized,

§

impl Decodable for Vec<Vec<u8, Global>, Global>

§

impl Decodable for i8

§

fn consensus_decode<R>(r: &mut R) -> Result<i8, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<VarInt, Global>

§

impl Decodable for [u8; 8]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 8], Error>where R: Read + ?Sized,

§

impl Decodable for Cow<'static, str>

§

fn consensus_decode<R>(r: &mut R) -> Result<Cow<'static, str>, Error>where R: Read + ?Sized,

§

impl Decodable for [u8; 4]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 4], Error>where R: Read + ?Sized,

§

impl Decodable for bool

§

fn consensus_decode<R>(r: &mut R) -> Result<bool, Error>where R: Read + ?Sized,

§

impl Decodable for Box<[u8], Global>

§

impl Decodable for u32

§

fn consensus_decode<R>(r: &mut R) -> Result<u32, Error>where R: Read + ?Sized,

§

impl Decodable for i16

§

fn consensus_decode<R>(r: &mut R) -> Result<i16, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<TapLeafHash, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<TapLeafHash, Global>, Error>where R: Read + ?Sized,

§

impl Decodable for u8

§

fn consensus_decode<R>(r: &mut R) -> Result<u8, Error>where R: Read + ?Sized,

§

impl Decodable for [u8; 12]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 12], Error>where R: Read + ?Sized,

§

impl Decodable for [u8; 10]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 10], Error>where R: Read + ?Sized,

§

impl<T0, T1, T2, T3, T4, T5, T6, T7> Decodable for (T0, T1, T2, T3, T4, T5, T6, T7)where T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable,

§

impl<T0, T1, T2, T3, T4, T5> Decodable for (T0, T1, T2, T3, T4, T5)where T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable,

§

impl Decodable for Vec<TxMerkleNode, Global>

§

impl Decodable for [u8; 16]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u8; 16], Error>where R: Read + ?Sized,

§

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

§

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

§

impl Decodable for Vec<PrefilledTransaction, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<PrefilledTransaction, Global>, Error>where R: Read + ?Sized,

§

impl Decodable for i64

§

fn consensus_decode<R>(r: &mut R) -> Result<i64, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<TxOut, Global>

§

impl Decodable for i32

§

fn consensus_decode<R>(r: &mut R) -> Result<i32, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<ShortId, Global>

§

impl Decodable for Vec<FilterHash, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<FilterHash, Global>, Error>where R: Read + ?Sized,

§

impl Decodable for [u16; 8]

§

fn consensus_decode<R>(r: &mut R) -> Result<[u16; 8], Error>where R: Read + ?Sized,

§

impl Decodable for Vec<(u32, Address), Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<(u32, Address), Global>, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<AddrV2Message, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<AddrV2Message, Global>, Error>where R: Read + ?Sized,

§

impl Decodable for u16

§

fn consensus_decode<R>(r: &mut R) -> Result<u16, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<FilterHeader, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<FilterHeader, Global>, Error>where R: Read + ?Sized,

§

impl Decodable for Vec<u64, Global>

§

impl Decodable for String

§

impl Decodable for Vec<Inventory, Global>

§

fn consensus_decode_from_finite_reader<R>( r: &mut R ) -> Result<Vec<Inventory, Global>, Error>where R: Read + ?Sized,

Implementors§

§

impl Decodable for LockTime

§

impl Decodable for bitcoin::key::secp256k1::hashes::sha256::Hash

§

impl Decodable for bitcoin::key::secp256k1::hashes::sha256d::Hash

§

impl Decodable for Block

§

impl Decodable for BlockHash

§

impl Decodable for Header

§

impl Decodable for OutPoint

§

impl Decodable for PartialMerkleTree

§

impl Decodable for Transaction

§

impl Decodable for TxIn

§

impl Decodable for TxMerkleNode

§

impl Decodable for TxOut

§

impl Decodable for Txid

§

impl Decodable for VarInt

§

impl Decodable for CheckedData

§

impl Decodable for AddrV2

§

impl Decodable for AddrV2Message

§

impl Decodable for Address

§

impl Decodable for BlockTransactions

§

impl Decodable for BlockTransactionsRequest

§

impl Decodable for BlockTxn

§

impl Decodable for BloomFlags

§

impl Decodable for CFCheckpt

§

impl Decodable for CFHeaders

§

impl Decodable for CFilter

§

impl Decodable for CmpctBlock

§

impl Decodable for CommandString

§

impl Decodable for CompactTarget

§

impl Decodable for FilterAdd

§

impl Decodable for FilterHash

§

impl Decodable for FilterHeader

§

impl Decodable for FilterLoad

§

impl Decodable for GetBlockTxn

§

impl Decodable for GetBlocksMessage

§

impl Decodable for GetCFCheckpt

§

impl Decodable for GetCFHeaders

§

impl Decodable for GetCFilters

§

impl Decodable for GetHeadersMessage

§

impl Decodable for HeaderAndShortIds

§

impl Decodable for Inventory

§

impl Decodable for Magic

§

impl Decodable for MerkleBlock

§

impl Decodable for PrefilledTransaction

§

impl Decodable for RawNetworkMessage

§

impl Decodable for Reject

§

impl Decodable for RejectReason

§

impl Decodable for ScriptBuf

§

impl Decodable for SendCmpct

§

impl Decodable for Sequence

§

impl Decodable for ServiceFlags

§

impl Decodable for ShortId

§

impl Decodable for TapLeafHash

§

impl Decodable for Version

§

impl Decodable for VersionMessage

§

impl Decodable for Witness

§

impl Decodable for WitnessMerkleNode

§

impl Decodable for Wtxid

§

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