Skip to main content

DecodeMessageExt

Trait DecodeMessageExt 

Source
pub trait DecodeMessageExt: DecodeMessage {
    // Provided methods
    fn decode_and_verify(
        self,
    ) -> Result<<Self::Decoded as Verify>::Verified, ConversionError>
       where Self::Decoded: Verify { ... }
    fn decode_and_verify_with<C>(
        self,
        context: C,
    ) -> Result<<Self::Decoded as VerifyWith<C>>::Verified, ConversionError>
       where Self::Decoded: VerifyWith<C> { ... }
    fn decode_and_build_unchecked(
        self,
    ) -> Result<<Self::Decoded as BuildUnchecked>::Output, ConversionError>
       where Self::Decoded: BuildUnchecked { ... }
}
Expand description

Combines field decoding with an explicitly selected domain construction capability.

Implemented for every DecodeMessage, including oneofs and handwritten adapters. Each method requires only its corresponding capability on the decoded representation. These methods consume an already parsed wire message; they do not decode Protobuf bytes.

All methods return ConversionError with a stage prefix: failed to decode, failed to verify, or failed to build unchecked. The original error, including any field path, is preserved in the source chain. Stage labels are separate from wire paths. Call DecodeMessage::decode_fields and the construction method separately when typed domain errors are needed directly.

Provided Methods§

Source

fn decode_and_verify( self, ) -> Result<<Self::Decoded as Verify>::Verified, ConversionError>
where Self::Decoded: Verify,

Decodes fields, then checks domain invariants using Verify::verify.

use miden_protobuf::{ConversionError, DecodeMessageExt, Verify};

fn decode<P>(message: P) -> Result<<P::Decoded as Verify>::Verified, ConversionError>
where
    P: DecodeMessageExt,
    P::Decoded: Verify,
{
    message.decode_and_verify()
}
Source

fn decode_and_verify_with<C>( self, context: C, ) -> Result<<Self::Decoded as VerifyWith<C>>::Verified, ConversionError>
where Self::Decoded: VerifyWith<C>,

Decodes fields, then verifies with borrowed or owned caller-supplied context.

The context must satisfy the trust requirements of the decoded type’s VerifyWith implementation.

use miden_protobuf::{ConversionError, DecodeMessageExt, VerifyWith};

fn decode<P, C>(
    message: P,
    context: C,
) -> Result<<P::Decoded as VerifyWith<C>>::Verified, ConversionError>
where
    P: DecodeMessageExt,
    P::Decoded: VerifyWith<C>,
{
    message.decode_and_verify_with(context)
}
Source

fn decode_and_build_unchecked( self, ) -> Result<<Self::Decoded as BuildUnchecked>::Output, ConversionError>
where Self::Decoded: BuildUnchecked,

Decodes fields, then constructs with BuildUnchecked::build_unchecked.

Structural decoding checks still run, and construction can still fail.

§Warning

The output is not guaranteed to be verified. Callers must ensure the invariants documented by the decoded type’s BuildUnchecked implementation, including any nested checks it skips.

use miden_protobuf::{BuildUnchecked, ConversionError, DecodeMessageExt};

fn decode<P>(message: P) -> Result<<P::Decoded as BuildUnchecked>::Output, ConversionError>
where
    P: DecodeMessageExt,
    P::Decoded: BuildUnchecked,
{
    message.decode_and_build_unchecked()
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§