Trait fuel_types::canonical::Serialize

source ·
pub trait Serialize {
    // Required methods
    fn size_static(&self) -> usize;
    fn size_dynamic(&self) -> usize;
    fn encode_static<O: Output + ?Sized>(
        &self,
        buffer: &mut O,
    ) -> Result<(), Error>;

    // Provided methods
    fn size(&self) -> usize { ... }
    fn encode<O: Output + ?Sized>(&self, buffer: &mut O) -> Result<(), Error> { ... }
    fn encode_dynamic<O: Output + ?Sized>(
        &self,
        _buffer: &mut O,
    ) -> Result<(), Error> { ... }
    fn to_bytes(&self) -> Vec<u8> { ... }
}
Expand description

Allows serialize the type into the Output. https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/tx_format.md#transaction

Required Methods§

source

fn size_static(&self) -> usize

Size of the static part of the serialized object, in bytes. Saturates to usize::MAX on overflow.

source

fn size_dynamic(&self) -> usize

Size of the dynamic part, in bytes. Saturates to usize::MAX on overflow.

source

fn encode_static<O: Output + ?Sized>(&self, buffer: &mut O) -> Result<(), Error>

Encodes staticly-sized part of Self.

Provided Methods§

source

fn size(&self) -> usize

Total size of the serialized object, in bytes. Saturates to usize::MAX on overflow.

source

fn encode<O: Output + ?Sized>(&self, buffer: &mut O) -> Result<(), Error>

Encodes Self into the buffer.

It is better to not implement this function directly, instead implement encode_static and encode_dynamic.

source

fn encode_dynamic<O: Output + ?Sized>( &self, _buffer: &mut O, ) -> Result<(), Error>

Encodes dynamically-sized part of Self. The default implementation does nothing. Dynamically-sized contains should override this.

source

fn to_bytes(&self) -> Vec<u8>

Encodes Self into bytes vector. Required known size.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Serialize for u8

source§

impl Serialize for u16

source§

impl Serialize for u32

source§

impl Serialize for u64

source§

impl Serialize for u128

source§

impl Serialize for ()

source§

fn size_static(&self) -> usize

source§

fn size_dynamic(&self) -> usize

source§

fn encode_static<O: Output + ?Sized>( &self, _buffer: &mut O, ) -> Result<(), Error>

source§

impl Serialize for usize

source§

impl<T: Serialize> Serialize for Vec<T>

source§

fn size_static(&self) -> usize

source§

fn size_dynamic(&self) -> usize

source§

fn encode_static<O: Output + ?Sized>(&self, buffer: &mut O) -> Result<(), Error>

source§

fn encode_dynamic<O: Output + ?Sized>( &self, buffer: &mut O, ) -> Result<(), Error>

source§

impl<const N: usize, T: Serialize> Serialize for [T; N]

source§

fn size_static(&self) -> usize

source§

fn size_dynamic(&self) -> usize

source§

fn encode_static<O: Output + ?Sized>(&self, buffer: &mut O) -> Result<(), Error>

source§

fn encode_dynamic<O: Output + ?Sized>( &self, buffer: &mut O, ) -> Result<(), Error>

Implementors§