starcoin-framework

Module 0x1::TypeInfo

use 0x1::BCS;
use 0x1::Token;

Struct TypeInfo

struct TypeInfo has copy, drop, store
Fields
account_address: address
module_name: vector<u8>
struct_name: vector<u8>

Function account_address

public fun account_address(type_info: &TypeInfo::TypeInfo): address
Implementation
public fun account_address(type_info: &TypeInfo): address {
    type_info.account_address
}

Function module_name

public fun module_name(type_info: &TypeInfo::TypeInfo): vector<u8>
Implementation
public fun module_name(type_info: &TypeInfo): vector<u8> {
    *&type_info.module_name
}

Function struct_name

public fun struct_name(type_info: &TypeInfo::TypeInfo): vector<u8>
Implementation
public fun struct_name(type_info: &TypeInfo): vector<u8> {
    *&type_info.struct_name
}

Function type_of

public fun type_of<T>(): TypeInfo::TypeInfo
Implementation
public fun type_of<T>(): TypeInfo {
    let (account_address, module_name, struct_name) = Token::type_of<T>();
    TypeInfo {
        account_address,
        module_name,
        struct_name
    }
}

Function size_of_val

Return the BCS size, in bytes, of value at val_ref.

See the BCS spec

See test_size_of_val() for an analysis of common types and nesting patterns, as well as test_size_of_val_vectors() for an analysis of vector size dynamism.

public fun size_of_val<T: store>(val_ref: &T): u64
Implementation
public fun size_of_val<T: store>(val_ref: &T): u64 {
    // Return vector length of vectorized BCS representation.
    Vector::length(&BCS::to_bytes<T>(val_ref))
}