[][src]Struct ontio_std::abi::Sink

pub struct Sink { /* fields omitted */ }

Encoding different types of data into byte array.

Methods

impl Sink[src]

pub fn new(cap: usize) -> Self[src]

Create a new sink entity, Specify initial capacity. For indefinite length parameters, the length of the parameter will be serialized first, and then the content of the parameter will be serialized.

Example

 let mut sink = Sink::new(0);
 sink.write("123");
 assert_eq!(sink.bytes(),[3,49,50,51]);

pub fn write<T: Encoder>(&mut self, val: T)[src]

All data types that implement the encode interface can be serialized by calling the write method

Example

   let mut sink = Sink::new(0);
   let addr = Address::repeat_byte(1u8);
   sink.write(addr);
   sink.write("123");
   sink.write(123 as U128);

pub fn write_neovm_address(&mut self, address: &Address)[src]

pub fn write_native_varuint(&mut self, val: u64)[src]

pub fn bytes(&self) -> &[u8][src]

Used to get the serialized result in bytearray format

Example

#![feature(proc_macro_hygiene)]
use ontio_std::macros::base58;
use ontio_std::types::Address;
use ontio_std::abi::Sink;
const ONT_CONTRACT_ADDRESS: Address = base58!("AFmseVrdL9f9oyCzZefL9tG6UbvhUMqNMV");
let mut sink = Sink::new(0);
sink.write(&ONT_CONTRACT_ADDRESS);
assert_eq!(sink.into(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].to_vec())

pub fn into(self) -> Vec<u8>[src]

Used to get the serialized result in Vec format

Example

fn main() {

}

Auto Trait Implementations

impl Send for Sink

impl Sync for Sink

impl Unpin for Sink

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.