[−][src]Struct ontio_std::abi::Sink
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]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,