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
- Function
to_bytes
- Function
to_bool
- Function
to_u8
- Function
to_u64
- Function
to_u128
- Function
to_address
- Function
from_bytes
- Function
from_bytes_option
- Function
native_from_bytes
use 0x1::bcs;
use 0x1::option;
const ErrorInvalidBytes: u64 = 2;
The request Move type is not match with input Move type.
const ErrorTypeNotMatch: u64 = 1;
public fun to_address(v: vector<u8>): address
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 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>
public(friend) fun native_from_bytes<T>(bytes: vector<u8>): option::Option<T>