Private
bufferPrivate
offsetThe BCS-deserializable class to deserialize the buffered bytes into.
the deserialized value of class type T
const deserializer = new Deserializer(new Uint8Array([1, 2, 3]));
const value = deserializer.deserialize(MyClass); // where MyClass has a `deserialize` function
// value is now an instance of MyClass
// equivalent to `const value = MyClass.deserialize(deserializer)`
Deserializes a string. UTF8 string is supported. Reads the string's bytes length "l" first, and then reads "l" bytes of content. Decodes the byte array into a string.
BCS layout for "string": string_length | string_content where string_length is a u32 integer encoded as a uleb128 integer, equal to the number of bytes in string_content.
const deserializer = new Deserializer(new Uint8Array([8, 49, 50, 51, 52, 97, 98, 99, 100]));
assert(deserializer.deserializeStr() === "1234abcd");
Deserializes a uint64 number.
BCS layout for "uint64": Eight bytes. Binary format in little-endian representation.
const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
assert(deserializer.deserializeU64() === 1311768467750121216);
Deserializes an array of BCS Deserializable values given an existing Deserializer instance with a loaded byte buffer.
The BCS-deserializable class to deserialize the buffered bytes into.
an array of deserialized values of type T
// serialize a vector of addresses
const addresses = new Array<AccountAddress>(
AccountAddress.from("0x1"),
AccountAddress.from("0x2"),
AccountAddress.from("0xa"),
AccountAddress.from("0xb"),
);
const serializer = new Serializer();
serializer.serializeVector(addresses);
const serializedBytes = serializer.toUint8Array();
// deserialize the bytes into an array of addresses
const deserializer = new Deserializer(serializedBytes);
const deserializedAddresses = deserializer.deserializeVector(AccountAddress);
// deserializedAddresses is now an array of AccountAddress instances
Private
readGenerated using TypeDoc
Helper function that primarily exists to support alternative syntax for deserialization. That is, if we have a
const deserializer: new Deserializer(...)
, instead of having to useMyClass.deserialize(deserializer)
, we can calldeserializer.deserialize(MyClass)
.