Skip to main content

Deserializable

Trait Deserializable 

Source
pub trait Deserializable: Sized {
    // Required method
    fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>
       where R: ByteReader;

    // Provided methods
    fn min_serialized_size() -> usize { ... }
    fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError> { ... }
    fn read_from_bytes_with_budget(
        bytes: &[u8],
        budget: usize,
    ) -> Result<Self, DeserializationError> { ... }
}
Expand description

Defines how to deserialize Self from bytes.

Required Methods§

Source

fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result.

§Errors

Returns an error if:

  • The source does not contain enough bytes to deserialize Self.
  • Bytes read from the source do not represent a valid value for Self.

Provided Methods§

Source

fn min_serialized_size() -> usize

Returns the minimum serialized size for one instance of this type.

This is used by ByteReader::max_alloc to estimate how many elements can be deserialized from the remaining budget, preventing denial-of-service attacks from malicious length prefixes.

The default implementation returns size_of::<Self>(), which is conservative: it may reject valid input for types where the serialized size is smaller than the in-memory size (e.g., structs with computed/cached fields that aren’t serialized).

Override this method for types where the serialized representation is smaller than the in-memory representation to allow more elements to be deserialized.

Source

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result.

§Errors

Returns an error if:

  • The bytes do not contain enough information to deserialize Self.
  • The bytes do not represent a valid value for Self.

Note: if bytes contains more data than needed to deserialize self, no error is returned.

Source

fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>

Deserializes Self from bytes with a byte budget limit.

This is the recommended method for deserializing untrusted input. The budget limits how many bytes can be consumed during deserialization, preventing denial-of-service attacks that exploit length fields to cause huge allocations.

§Errors

Returns an error if:

  • The budget is exhausted before deserialization completes.
  • The bytes do not contain enough information to deserialize Self.
  • The bytes do not represent a valid value for Self.

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 Deserializable for HashFunction

Source§

impl Deserializable for SealingKey

Source§

impl Deserializable for UnsealingKey

Source§

impl Deserializable for NodeMutation

Source§

impl Deserializable for SmtLeaf

Source§

impl Deserializable for u8

Source§

impl Deserializable for u16

Source§

impl Deserializable for u32

Source§

impl Deserializable for u64

Source§

impl Deserializable for u128

Source§

impl Deserializable for ()

Source§

impl Deserializable for usize

Source§

impl Deserializable for String

Source§

impl Deserializable for PublicInputs

Source§

impl Deserializable for ExecutionProof

Source§

impl Deserializable for EncryptedData

Source§

impl Deserializable for Nonce

Source§

impl Deserializable for SecretKey

Source§

impl Deserializable for EncryptedData

Source§

impl Deserializable for Nonce

Source§

impl Deserializable for SecretKey

Source§

impl Deserializable for EphemeralPublicKey

Source§

impl Deserializable for EphemeralPublicKey

Source§

impl Deserializable for SealedMessage

Source§

impl Deserializable for Forest

Source§

impl Deserializable for InOrderIndex

Source§

impl Deserializable for PartialMmr

Source§

impl Deserializable for MerkleProof

Source§

impl Deserializable for RootPath

Source§

impl Deserializable for PartialSmt

Source§

impl Deserializable for SparseMerklePath

Source§

impl Deserializable for SourceSpan

Source§

impl<K, V> Deserializable for BTreeMap<K, V>

Source§

impl<T1> Deserializable for (T1,)
where T1: Deserializable,

Source§

impl<T1, T2> Deserializable for (T1, T2)

Source§

impl<T1, T2, T3> Deserializable for (T1, T2, T3)

Source§

impl<T1, T2, T3, T4> Deserializable for (T1, T2, T3, T4)

Source§

impl<T1, T2, T3, T4, T5> Deserializable for (T1, T2, T3, T4, T5)

Source§

impl<T1, T2, T3, T4, T5, T6> Deserializable for (T1, T2, T3, T4, T5, T6)

Source§

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

Source§

fn min_serialized_size() -> usize

Returns 1 (just the bool discriminator).

The Some variant would be 1 + T::min_serialized_size(), but we use the minimum to allow more elements through the early check.

Source§

fn read_from<R>(source: &mut R) -> Result<Option<T>, DeserializationError>
where R: ByteReader,

Source§

impl<T> Deserializable for BTreeSet<T>
where T: Deserializable + Ord,

Source§

impl<T> Deserializable for Vec<T>
where T: Deserializable,

Source§

fn min_serialized_size() -> usize

Returns 1 (the minimum vint length prefix size).

The actual serialized size depends on the number of elements, which we don’t know at the point this is called. Using the minimum allows more elements through the early check; budget enforcement during actual reads provides the real protection.

Source§

fn read_from<R>(source: &mut R) -> Result<Vec<T>, DeserializationError>
where R: ByteReader,

Source§

impl<T> Deserializable for LexicographicWord<T>
where T: Into<Word> + From<Word>,

Source§

impl<T> Deserializable for Span<T>
where T: Deserializable,

Source§

impl<T, const C: usize> Deserializable for [T; C]
where T: Deserializable,

Source§

impl<const DEPTH: u8, K, V> Deserializable for MutationSet<DEPTH, K, V>

Source§

fn read_from<R>( source: &mut R, ) -> Result<MutationSet<DEPTH, K, V>, DeserializationError>
where R: ByteReader,

Implementors§

Source§

impl Deserializable for Operation

Source§

impl Deserializable for AdviceInputs

Source§

impl Deserializable for AdviceMap

Source§

impl Deserializable for miden_processor::crypto::dsa::ecdsa_k256_keccak::PublicKey

Source§

impl Deserializable for miden_processor::crypto::dsa::ecdsa_k256_keccak::SecretKey

Source§

impl Deserializable for miden_processor::crypto::dsa::ecdsa_k256_keccak::Signature

Source§

impl Deserializable for miden_processor::crypto::dsa::eddsa_25519_sha512::PublicKey

Source§

impl Deserializable for miden_processor::crypto::dsa::eddsa_25519_sha512::SecretKey

Source§

impl Deserializable for miden_processor::crypto::dsa::eddsa_25519_sha512::Signature

Source§

impl Deserializable for miden_processor::crypto::dsa::falcon512_poseidon2::Nonce

Source§

impl Deserializable for miden_processor::crypto::dsa::falcon512_poseidon2::PublicKey

Source§

impl Deserializable for miden_processor::crypto::dsa::falcon512_poseidon2::SecretKey

Source§

impl Deserializable for miden_processor::crypto::dsa::falcon512_poseidon2::Signature

Source§

impl Deserializable for SignatureHeader

Source§

impl Deserializable for SignaturePoly

Source§

impl Deserializable for MerklePath

Source§

impl Deserializable for MerkleStore

Source§

impl Deserializable for Mmr

Source§

impl Deserializable for NodeIndex

Source§

impl Deserializable for PartialMerkleTree

Source§

impl Deserializable for Smt

Source§

impl Deserializable for SmtProof

Source§

impl Deserializable for StoreNode

Source§

impl Deserializable for RpoRandomCoin

Source§

impl Deserializable for RpxRandomCoin

Source§

impl Deserializable for EventId

Source§

impl Deserializable for EventName

Source§

impl Deserializable for AsmOpId

Source§

impl Deserializable for DebugInfo

Source§

impl Deserializable for DecoratorId

Source§

impl Deserializable for MastForest

Source§

impl Deserializable for UntrustedMastForest

Source§

impl Deserializable for PrecompileRequest

Source§

impl Deserializable for Goldilocks

Source§

impl Deserializable for Kernel

Source§

impl Deserializable for Program

Source§

impl Deserializable for ProgramInfo

Source§

impl Deserializable for StackInputs

Source§

impl Deserializable for StackOutputs

Source§

impl Deserializable for Word

Source§

impl<I, D> Deserializable for CsrMatrix<I, D>
where I: Idx, D: Deserializable,

Source§

impl<I, T> Deserializable for IndexVec<I, T>
where I: Idx, T: Deserializable,

Source§

impl<const DEPTH: u8> Deserializable for LeafIndex<DEPTH>

Source§

impl<const N: usize> Deserializable for Blake3Digest<N>