Skip to content

Latest commit

 

History

History
157 lines (72 loc) · 4.05 KB

bcs.md

File metadata and controls

157 lines (72 loc) · 4.05 KB

Module 0x2::bcs

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 that it is not safe to define a generic public from_bytes function because this can violate implicit struct invariants, therefore only primitive types are offerred. If a general conversion back-and-force is needed, consider the moveos_std::Any type which preserves invariants.

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 private_generics ensure only the MoveValue's owner module can call this function

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

Function from_bytes_option

Function to deserialize a type T. Note the private_generics ensure only the MoveValue's owner module can call this function If the bytes are invalid, it will return None.

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

Function native_from_bytes

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