sto_subarray
Concepts
Section titled “Concepts”Behaviour
Section titled “Behaviour”- Parse a STArray pointed to by
read_ptr
- Find the array index specified by
array_id
- Return the byte offset and length of the serialized field within the STObject, if it is found
- Ask for the STO object (binary encoded ledger data) from which to extract the subarray.
- Find the array index specified by
array_id
- Return a subarray from an STO object.
Definition
Section titled “Definition”int64_t sto_subarray ( uint32_t read_ptr, uint32_t read_len, uint32_t array_id);
function sto_subarray( sto: ByteArray | HexString, array_id: number ): bigint | number
Example
Section titled “Example”#define SUB_OFFSET(x) ((int32_t)(x >> 32))#define SUB_LENGTH(x) ((int32_t)(x & 0xFFFFFFFFULL))
int64_t memo_lookup = sto_subarray(memos, memos_len, 0);
if (memo_lookup < 0){ // sfMemo was not found in the STObject pointed at by memo_ptr}else{ // 0th index of the STArray was found and its location is as follows: uint8_t* memo_ptr = SUB_OFFSET(memo_lookup) + memos; uint32_t memo_len = SUB_LENGTH(memo_lookup);}
const SUB_OFFSET = (x) => Number(x >> 32n)const SUB_LENGTH = (x) => Number(x & 0xFFFFFFFFn)
const memo_lookup = sto_subarray(memos, 0)
if (typeof memo_lookup === 'number'){ // sfMemo was not found in the STObject pointed at}else{ // 0th index of the STArray was found and its location is as follows: const memo_start = SUB_OFFSET(memo_lookup) const memo_len = SUB_LENGTH(memo_lookup) const memo = memos.slice(memo_start, memo_len)}
Parameters
Section titled “Parameters”Name | Type | Description |
---|---|---|
read_ptr | uint32_t | Pointer to the buffer containing the STArray |
read_len | uint32_t | Length of STArray |
array_id | uint32_t | The index of the entry within the STArray you are seeking. Starts from 0. |
Name | Type | Description |
---|---|---|
sto | ByteArray | HexString | The STO object (binary encoded ledger data) from which to extract the subarray. |
array_id | number | The ID of the array to be extracted. |
Return Code
Section titled “Return Code”Type | Description |
---|---|
int64_t | The location of the field within the specified buffer: |
Type | Description |
---|---|
bigint / ErrorCode | The location of the field within the specified buffer: |