Trait scrypto::prelude::Decoder

source ·
pub trait Decoder<X>: Sized
where X: CustomValueKind,
{
Show 20 methods // Required methods fn decode_deeper_body_with_value_kind<T>( &mut self, value_kind: ValueKind<X> ) -> Result<T, DecodeError> where T: Decode<X, Self>; fn check_end(&self) -> Result<(), DecodeError>; fn read_byte(&mut self) -> Result<u8, DecodeError>; fn read_slice(&mut self, n: usize) -> Result<&[u8], DecodeError>; fn peek_remaining(&self) -> &[u8] ; fn get_depth_limit(&self) -> usize; fn get_stack_depth(&self) -> usize; fn get_offset(&self) -> usize; fn peek_byte(&self) -> Result<u8, DecodeError>; // Provided methods fn decode_payload<T>(self, expected_prefix: u8) -> Result<T, DecodeError> where T: Decode<X, Self> { ... } fn decode<T>(&mut self) -> Result<T, DecodeError> where T: Decode<X, Self> { ... } fn read_value_kind(&mut self) -> Result<ValueKind<X>, DecodeError> { ... } fn read_discriminator(&mut self) -> Result<u8, DecodeError> { ... } fn read_size(&mut self) -> Result<usize, DecodeError> { ... } fn check_preloaded_value_kind( &self, value_kind: ValueKind<X>, expected: ValueKind<X> ) -> Result<ValueKind<X>, DecodeError> { ... } fn read_expected_discriminator( &mut self, expected_discriminator: u8 ) -> Result<(), DecodeError> { ... } fn read_and_check_payload_prefix( &mut self, expected_prefix: u8 ) -> Result<(), DecodeError> { ... } fn read_and_check_value_kind( &mut self, expected: ValueKind<X> ) -> Result<ValueKind<X>, DecodeError> { ... } fn read_and_check_size( &mut self, expected: usize ) -> Result<(), DecodeError> { ... } fn peek_value_kind(&self) -> Result<ValueKind<X>, DecodeError> { ... }
}

Required Methods§

source

fn decode_deeper_body_with_value_kind<T>( &mut self, value_kind: ValueKind<X> ) -> Result<T, DecodeError>
where T: Decode<X, Self>,

Decodes the SBOR body of a child value as part of a larger payload.

In many cases, you may wish to directly call T::decode_body_with_value_kind instead of this method. See the below section for details.

§Direct calls and SBOR Depth

In order to avoid SBOR depth differentials and disagreement about whether a payload is valid, typed codec implementations should ensure that the SBOR depth as measured during the encoding/decoding process agrees with the SBOR Value codec.

Each layer of the SBOR Value counts as one depth.

If the decoder you’re writing is embedding a child type (and is represented as such in the SBOR Value type), then you should call decoder.decode_body_with_value_kind to increment the SBOR depth tracker.

You should call T::decode_body_with_value_kind directly when the decoding of that type into an SBOR Value doesn’t increase the SBOR depth in the decoder, that is:

  • When the wrapping type is invisible to the SBOR Value, ie:
    • Smart pointers
    • Transparent wrappers
  • Where the use of the inner type is invisible to SBOR Value, ie:
    • Where the use of T::decode_body_with_value_kind is coincidental / code re-use
source

fn check_end(&self) -> Result<(), DecodeError>

source

fn read_byte(&mut self) -> Result<u8, DecodeError>

source

fn read_slice(&mut self, n: usize) -> Result<&[u8], DecodeError>

source

fn peek_remaining(&self) -> &[u8]

source

fn get_depth_limit(&self) -> usize

source

fn get_stack_depth(&self) -> usize

source

fn get_offset(&self) -> usize

source

fn peek_byte(&self) -> Result<u8, DecodeError>

Provided Methods§

source

fn decode_payload<T>(self, expected_prefix: u8) -> Result<T, DecodeError>
where T: Decode<X, Self>,

Consumes the Decoder and decodes the value as a full payload

This includes a check of the payload prefix byte: It’s the intention that each version of SBOR or change to the custom codecs should be given its own prefix

source

fn decode<T>(&mut self) -> Result<T, DecodeError>
where T: Decode<X, Self>,

Decodes the value as part of a larger payload

This method decodes the SBOR value’s kind, and then its body.

source

fn read_value_kind(&mut self) -> Result<ValueKind<X>, DecodeError>

source

fn read_discriminator(&mut self) -> Result<u8, DecodeError>

source

fn read_size(&mut self) -> Result<usize, DecodeError>

source

fn check_preloaded_value_kind( &self, value_kind: ValueKind<X>, expected: ValueKind<X> ) -> Result<ValueKind<X>, DecodeError>

source

fn read_expected_discriminator( &mut self, expected_discriminator: u8 ) -> Result<(), DecodeError>

source

fn read_and_check_payload_prefix( &mut self, expected_prefix: u8 ) -> Result<(), DecodeError>

source

fn read_and_check_value_kind( &mut self, expected: ValueKind<X> ) -> Result<ValueKind<X>, DecodeError>

source

fn read_and_check_size(&mut self, expected: usize) -> Result<(), DecodeError>

source

fn peek_value_kind(&self) -> Result<ValueKind<X>, DecodeError>

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'de, X> Decoder<X> for VecDecoder<'de, X>
where X: CustomValueKind,