Trait Packer

Source
pub trait Packer {
    // Required methods
    fn size(&self) -> usize;
    fn pack(&self, enc: &mut Encoder) -> usize;
    fn unpack(&mut self, data: &[u8]) -> usize;
}
Expand description

The Packer trait provides methods for packing and unpacking values to and from byte arrays.

§Examples

use crate::rust_chain::serializer::{Encoder, Decoder, Packer};

let mut encoder = Encoder::new(4);
let value = 123u32;
value.pack(&mut encoder);

let mut decoder = Decoder::new(&encoder.get_bytes());
let mut unpacked_value = 0u32;
decoder.unpack(&mut unpacked_value);

assert_eq!(value, unpacked_value);

Required Methods§

Source

fn size(&self) -> usize

Returns the size of the packed representation of this value in bytes.

Source

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given Encoder.

§Arguments
  • enc - The encoder to pack this value into.
§Returns

The number of bytes written to the encoder.

Source

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given byte array.

§Arguments
  • data - The byte array to unpack this value from.
§Returns

The number of bytes read from the byte array.

Implementations on Foreign Types§

Source§

impl Packer for bool

ImplementPacker for bool type.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

fn size(&self) -> usize

Source§

impl Packer for f32

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for f64

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for i8

Implement Packer for i8 type.

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for i16

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for i32

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for i64

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for i128

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for u8

Implement Packer for u8 type.

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for u16

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for u32

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for u64

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl Packer for u128

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Source§

impl<T> Packer for Option<T>
where T: Packer + Default,

Implement Packer for Option<T> type.

Source§

fn size(&self) -> usize

Returns the size of this value in bytes.

Source§

fn pack(&self, enc: &mut Encoder) -> usize

Packs this value into the given encoder.

Source§

fn unpack(&mut self, data: &[u8]) -> usize

Unpacks this value from the given data.

Implementors§

Source§

impl Packer for BlockSigningAuthority

Source§

impl Packer for PublicKey

Source§

impl Packer for UserPresence

Source§

impl Packer for Action

Implements the Packer trait for Action to enable serialization and deserialization.

Source§

impl Packer for GetCodeHashResult

Source§

impl Packer for PermissionLevel

Implements the Packer trait for PermissionLevel to enable serialization and deserialization.

Source§

impl Packer for Asset

Source§

impl Packer for ExtendedAsset

Source§

impl Packer for Symbol

Source§

impl Packer for SymbolCode

Source§

impl Packer for Name

Source§

impl Packer for String

Implement Packer for String type.

Source§

impl Packer for BlockSigningAuthorityV0

Source§

impl Packer for BlockTimeStampType

Source§

impl Packer for Checksum160

Source§

impl Packer for Checksum256

Source§

impl Packer for Checksum512

Source§

impl Packer for ECCPublicKey

Source§

impl Packer for Float128

Source§

impl Packer for KeyWeight

Source§

impl Packer for ProducerAuthority

Source§

impl Packer for ProducerKey

Source§

impl Packer for Signature

Source§

impl Packer for TimePoint

Source§

impl Packer for TimePointSec

Source§

impl Packer for Uint256

Source§

impl Packer for WebAuthNPublicKey

Source§

impl Packer for Transaction

Source§

impl Packer for TransactionExtension

Source§

impl Packer for VarUint32

Source§

impl<T> Packer for BinaryExtension<T>
where T: Packer + Default,

Source§

impl<T> Packer for Vec<T>
where T: Packer + Default,

Implement Packer for Vec<T> type.