Skip to content

Latest commit

 

History

History
156 lines (71 loc) · 3.78 KB

bcs.md

File metadata and controls

156 lines (71 loc) · 3.78 KB

Module 0x2::bcs

Part source from https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-stdlib/sources/from_bcs.move This module provides a number of functions to convert primitive types from their representation in std::bcs to values. This is the opposite of bcs::to_bytes. Note we provie a generic public from_bytes function and protected it with #[data_struct(T)].

Constants

const ErrorInvalidBytes: u64 = 2;

The request Move type is not match with input Move type.

const ErrorTypeNotMatch: u64 = 1;

Function to_bytes

public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>

Function to_bool

public fun to_bool(v: vector<u8>): bool

Function to_u8

public fun to_u8(v: vector<u8>): u8

Function to_u64

public fun to_u64(v: vector<u8>): u64

Function to_u128

public fun to_u128(v: vector<u8>): u128

Function to_address

public fun to_address(v: vector<u8>): address

Function from_bytes

Function to deserialize a type T. Note the data_struct ensure the T must be a #[data_struct] type

#[data_struct(#[T])]
public fun from_bytes<T>(bytes: vector<u8>): T

Function from_bytes_option

Function to deserialize a type T. Note the data_struct ensure the T must be a #[data_struct] type If the bytes are invalid, it will return None.

#[data_struct(#[T])]
public fun from_bytes_option<T>(bytes: vector<u8>): option::Option<T>

Function native_from_bytes

public(friend) fun native_from_bytes<T>(bytes: vector<u8>): option::Option<T>