Trait fedimint_core::encoding::Decodable

source ·
pub trait Decodable: Sized {
    // Provided methods
    fn consensus_decode_from_finite_reader<R: Read>(
        r: &mut R,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode<R: Read>(
        r: &mut R,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode_hex(
        hex: &str,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode_vec(
        bytes: Vec<u8>,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
}
Expand description

Data which can be encoded in a consensus-consistent way

Provided Methods§

source

fn consensus_decode_from_finite_reader<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

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, should only impl consensus_decode.
  • Types that deserialize based on decoded untrusted length should implement consensus_decode_from_finite_reader only:
    • Default implementation of consensus_decode will forward to consensus_decode_bytes_from_finite_reader with the reader wrapped by Take, protecting from readers that keep returning data.
    • Implementation must make sure to put a cap on things like Vec::with_capacity and 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.
  • Types that contain other types that might be require limited reader (thus implementing 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 (Take<Take<...>>). Failure to do so might result only in a tiny performance hit.
source

fn consensus_decode<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_from_finite_reader, which is convenient for types that override Self::consensus_decode_from_finite_reader instead.

source

fn consensus_decode_hex( hex: &str, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

Decode an object from hex

source

fn consensus_decode_vec( bytes: Vec<u8>, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

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 u8

source§

impl Decodable for u16

source§

impl Decodable for u32

source§

impl Decodable for u64

source§

impl Decodable for ()

source§

impl Decodable for String

source§

impl Decodable for Duration

source§

impl Decodable for SystemTime

source§

impl Decodable for Address<NetworkUnchecked>

source§

impl Decodable for Amount

source§

impl Decodable for BlockHash

source§

impl Decodable for Bolt11Invoice

source§

impl Decodable for Ciphertext

source§

impl Decodable for DecryptionShare

source§

impl Decodable for G1Affine

source§

impl Decodable for G2Affine

source§

impl Decodable for Hash

source§

impl Decodable for Header

source§

impl Decodable for KeyPair

source§

impl Decodable for Magic

source§

impl Decodable for Network

source§

impl Decodable for OutPoint

source§

impl Decodable for PartialMerkleTree

source§

impl Decodable for PartiallySignedTransaction

source§

impl Decodable for PublicKey

source§

impl Decodable for PublicKey

source§

impl Decodable for PublicKeySet

source§

impl Decodable for RoutingFees

source§

impl Decodable for Scalar

source§

impl Decodable for ScriptBuf

source§

impl Decodable for SecretKey

source§

impl Decodable for Signature

source§

impl Decodable for Signature

source§

impl Decodable for Transaction

source§

impl Decodable for Txid

source§

impl<K> Decodable for BTreeSet<K>
where K: Decodable + Ord,

source§

impl<K> Decodable for Descriptor<K>
where Self: FromStr, <Self as FromStr>::Err: ToString + Error + Send + Sync + 'static, K: MiniscriptKey,

source§

impl<K, V> Decodable for BTreeMap<K, V>
where K: Decodable + Ord, V: Decodable,

source§

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

source§

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

source§

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

source§

impl<T> Decodable for Option<T>
where T: Decodable,

source§

impl<T> Decodable for Box<T>
where T: Decodable,

source§

impl<T> Decodable for Vec<T>
where T: Decodable + 'static,

source§

impl<T, E> Decodable for Result<T, E>
where T: Decodable, E: Decodable,

source§

impl<T, const SIZE: usize> Decodable for [T; SIZE]
where T: Decodable + Debug + Default + Copy + 'static,

Implementors§

source§

impl Decodable for ConsensusItem

source§

impl Decodable for InviteCodePart

source§

impl Decodable for SessionStatus

source§

impl Decodable for TransactionError

source§

impl Decodable for TransactionSignature

source§

impl Decodable for ClientBackupKey

source§

impl Decodable for ClientBackupKeyPrefix

source§

impl Decodable for ClientBackupSnapshot

source§

impl Decodable for ClientConfig

source§

impl Decodable for ClientModuleConfig

source§

impl Decodable for FederationId

source§

impl Decodable for FederationIdPrefix

source§

impl Decodable for GlobalClientConfig

source§

impl Decodable for PeerUrl

source§

impl Decodable for ServerModuleConsensusConfig

source§

impl Decodable for BackupRequest

source§

impl Decodable for DynClientConfig

source§

impl Decodable for DynInput

source§

impl Decodable for DynInputError

source§

impl Decodable for DynModuleConsensusItem

source§

impl Decodable for DynOutput

source§

impl Decodable for DynOutputError

source§

impl Decodable for DynOutputOutcome

source§

impl Decodable for ModuleKind

source§

impl Decodable for OperationId

source§

impl Decodable for DatabaseVersion

source§

impl Decodable for DatabaseVersionKey

source§

impl Decodable for DatabaseVersionKeyV0

source§

impl Decodable for AltDbPrefixTestPrefix

source§

impl Decodable for AltTestKey

source§

impl Decodable for DbPrefixTestPrefix

source§

impl Decodable for DbPrefixTestPrefixV0

source§

impl Decodable for PercentPrefixTestPrefix

source§

impl Decodable for PercentTestKey

source§

impl Decodable for TestKey

source§

impl Decodable for TestKeyV0

source§

impl Decodable for TestVal

source§

impl Decodable for BitcoinRpcConfig

source§

impl Decodable for InviteCode

source§

impl Decodable for InviteCodeV2

source§

impl Decodable for ApiVersion

source§

impl Decodable for CoreConsensusVersion

source§

impl Decodable for ModuleConsensusVersion

source§

impl Decodable for MultiApiVersion

source§

impl Decodable for SupportedApiVersionsSummary

source§

impl Decodable for SupportedCoreApiVersions

source§

impl Decodable for SupportedModuleApiVersions

source§

impl Decodable for AcceptedItem

source§

impl Decodable for SchnorrSignature

source§

impl Decodable for SessionOutcome

source§

impl Decodable for SignedSessionOutcome

source§

impl Decodable for fedimint_core::Amount

source§

impl Decodable for Feerate

source§

impl Decodable for fedimint_core::OutPoint

source§

impl Decodable for PeerId

source§

impl Decodable for TransactionId

source§

impl Decodable for fedimint_core::transaction::Transaction

source§

impl Decodable for TransactionSubmissionOutcome

source§

impl Decodable for TxOutProof

source§

impl Decodable for SafeUrl

source§

impl Decodable for BigSize

source§

impl<C> Decodable for Tiered<C>
where C: Decodable,

source§

impl<C> Decodable for TieredMulti<C>
where C: Decodable + 'static,

source§

impl<T> Decodable for DynRawFallback<T>
where T: Decodable + 'static,

source§

impl<T> Decodable for IntoDynNever<T>