Class MoveVector<T>

This class is the Aptos Typescript SDK representation of a Move vector<T>, where T represents either a primitive type (bool, u8, u64, ...) or a BCS-serializable struct itself.

It is a BCS-serializable, array-like type that contains an array of values of type T, where T is a class that implements Serializable.

The purpose of this class is to facilitate easy construction of BCS-serializable Move vector<T> types.

Example

// in Move: `vector<u8> [1, 2, 3, 4];`
const vecOfU8s = new MoveVector<U8>([new U8(1), new U8(2), new U8(3), new U8(4)]);
// in Move: `std::bcs::to_bytes(vector<u8> [1, 2, 3, 4]);`
const bcsBytes = vecOfU8s.toUint8Array();

// vector<vector<u8>> [ vector<u8> [1], vector<u8> [1, 2, 3, 4], vector<u8> [5, 6, 7, 8] ];
const vecOfVecs = new MoveVector<MoveVector<U8>>([
new MoveVector<U8>([new U8(1)]),
MoveVector.U8([1, 2, 3, 4]),
MoveVector.U8([5, 6, 7, 8]),
]);

// vector<Option<u8>> [ std::option::some<u8>(1), std::option::some<u8>(2) ];
const vecOfOptionU8s = new MoveVector<MoveOption<U8>>([
MoveOption.U8(1),
MoveOption.U8(2),
]);

// vector<MoveString> [ std::string::utf8(b"hello"), std::string::utf8(b"world") ];
const vecOfStrings = new MoveVector([new MoveString("hello"), new MoveString("world")]);
const vecOfStrings2 = MoveVector.MoveString(["hello", "world"]);

Params

values: an Array of values where T is a class that implements Serializable

Returns

a MoveVector<T> with the values values

Type Parameters

Hierarchy (view full)

Implements

Constructors

Properties

values: T[]

Methods

  • Factory method to generate a MoveVector of Bools from an array of booleans.

    Parameters

    • values: boolean[]

    Returns MoveVector<Bool>

    a MoveVector<Bool>

    Example

    const v = MoveVector.Bool([true, false, true, false]);
    

    Params

    values: an array of bools to convert to Bools

  • Deserialize a MoveVector of type T, specifically where T is a Serializable and Deserializable type.

    NOTE: This only works with a depth of one. Generics will not work.

    NOTE: This will not work with types that aren't of the Serializable class.

    If you're looking for a more flexible deserialization function, you can use the deserializeVector function in the Deserializer class.

    Type Parameters

    Parameters

    Returns MoveVector<T>

    a MoveVector of the corresponding class T *

    Example

    const vec = MoveVector.deserialize(deserializer, U64);
    

    Params

    deserializer: the Deserializer instance to use, with bytes loaded into it already. cls: the class to typecast the input values to, must be a Serializable and Deserializable type.

Generated using TypeDoc