Skip to main content

SerializationHelper

Struct SerializationHelper 

Source
pub struct SerializationHelper;
Expand description

Helper functions for serialization

Implementations§

Source§

impl SerializationHelper

Source

pub fn pack_u64(value: u64, data: &mut [u8], offset: &mut usize)

Pack a u64 value into a byte slice

Source

pub fn unpack_u64(data: &[u8], offset: &mut usize) -> Result<u64, ProgramError>

Unpack a u64 value from a byte slice

Source

pub fn pack_u32(value: u32, data: &mut [u8], offset: &mut usize)

Pack a u32 value into a byte slice

Source

pub fn unpack_u32(data: &[u8], offset: &mut usize) -> Result<u32, ProgramError>

Unpack a u32 value from a byte slice

Source

pub fn pack_u16(value: u16, data: &mut [u8], offset: &mut usize)

Pack a u16 value into a byte slice

Source

pub fn unpack_u16(data: &[u8], offset: &mut usize) -> Result<u16, ProgramError>

Unpack a u16 value from a byte slice

Source

pub fn pack_i64(value: i64, data: &mut [u8], offset: &mut usize)

Pack an i64 value into a byte slice

Source

pub fn unpack_i64(data: &[u8], offset: &mut usize) -> Result<i64, ProgramError>

Unpack an i64 value from a byte slice

Source

pub fn pack_pubkey(value: &Pubkey, data: &mut [u8], offset: &mut usize)

Pack a Pubkey into a byte slice

Source

pub fn pack_bytes_fixed<const N: usize>( value: &[u8; N], data: &mut [u8], offset: &mut usize, ) -> Result<(), ProgramError>

Pack fixed-length bytes into a byte slice

Source

pub fn unpack_bytes_fixed<const N: usize>( data: &[u8], offset: &mut usize, ) -> Result<[u8; N], ProgramError>

Unpack fixed-length bytes from a byte slice

Source

pub fn unpack_pubkey( data: &[u8], offset: &mut usize, ) -> Result<Pubkey, ProgramError>

Unpack a Pubkey from a byte slice

Source

pub fn pack_string_fixed<const N: usize>( value: &str, data: &mut [u8], offset: &mut usize, ) -> Result<(), ProgramError>

Pack a fixed-length string (zero-padded)

Source

pub fn unpack_string_fixed<const N: usize>( data: &[u8], offset: &mut usize, ) -> Result<String, ProgramError>

Unpack a fixed-length string (trim trailing zeroes)

Source

pub fn pack_string( value: &str, data: &mut [u8], offset: &mut usize, ) -> Result<(), ProgramError>

Pack a string with length prefix into a byte slice

Source

pub fn unpack_string( data: &[u8], offset: &mut usize, ) -> Result<String, ProgramError>

Unpack a string with length prefix from a byte slice

Source

pub fn pack_vec( value: &[u8], data: &mut [u8], offset: &mut usize, ) -> Result<(), ProgramError>

Pack a vector with length prefix into a byte slice

Source

pub fn unpack_vec( data: &[u8], offset: &mut usize, ) -> Result<Vec<u8>, ProgramError>

Unpack a vector with length prefix from a byte slice

Source

pub fn pack_u8(value: u8, data: &mut [u8], offset: &mut usize)

Pack a u8 value into a byte slice

Source

pub fn unpack_u8(data: &[u8], offset: &mut usize) -> Result<u8, ProgramError>

Unpack a u8 value from a byte slice

Source

pub fn pack_i8(value: i8, data: &mut [u8], offset: &mut usize)

Pack an i8 value into a byte slice

Source

pub fn unpack_i8(data: &[u8], offset: &mut usize) -> Result<i8, ProgramError>

Unpack an i8 value from a byte slice

Source

pub fn pack_i16(value: i16, data: &mut [u8], offset: &mut usize)

Pack an i16 value into a byte slice

Source

pub fn unpack_i16(data: &[u8], offset: &mut usize) -> Result<i16, ProgramError>

Unpack an i16 value from a byte slice

Source

pub fn pack_i32(value: i32, data: &mut [u8], offset: &mut usize)

Pack an i32 value into a byte slice

Source

pub fn unpack_i32(data: &[u8], offset: &mut usize) -> Result<i32, ProgramError>

Unpack an i32 value from a byte slice

Source

pub fn pack_bool(value: bool, data: &mut [u8], offset: &mut usize)

Pack a bool value into a byte slice

Source

pub fn unpack_bool( data: &[u8], offset: &mut usize, ) -> Result<bool, ProgramError>

Unpack a bool value from a byte slice

Source

pub fn pack_u128(value: u128, data: &mut [u8], offset: &mut usize)

Pack a u128 value into a byte slice

Source

pub fn unpack_u128( data: &[u8], offset: &mut usize, ) -> Result<u128, ProgramError>

Unpack a u128 value from a byte slice

Source

pub fn pack_i128(value: i128, data: &mut [u8], offset: &mut usize)

Pack an i128 value into a byte slice

Source

pub fn unpack_i128( data: &[u8], offset: &mut usize, ) -> Result<i128, ProgramError>

Unpack an i128 value from a byte slice

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.