sto_subfield
Concepts
Section titled “Concepts”Behaviour
Section titled “Behaviour”- Parse a STObject pointed to by
read_ptr
- Find the field specified by
field_id
- If the field is found, and:
-
- It is an array, then return the start and length of the array including the leadin/leadout bytes, or
-
- It is not an array, then return the start and length of the PAYLOAD of the field (excluding the leadin bytes).
- Parse a STObject into
sto
variable - Find the field specified by
field_id
Definition
Section titled “Definition”int64_t sto_subfield ( uint32_t read_ptr, uint32_t read_len, uint32_t field_id);
function sto_subfield( sto: ByteArray | HexString, field_id: number ): ErrorCode | bigint
Example
Section titled “Example”#define SUB_OFFSET(x) ((int32_t)(x >> 32))#define SUB_LENGTH(x) ((int32_t)(x & 0xFFFFFFFFULL))int64_t memos_lookup = sto_subfield(txn_ptr, txn_len, sfMemos);if (memos_lookup < 0){ // sfMemos was not found in the STObject pointed at by memo_ptr}else{ // sfMemos was found and its location is as follows: uint8_t* memos_ptr = SUB_OFFSET(memos_lookup) + memos_ptr; int64_t memos_len = SUB_LENGTH(memos_lookup);}
const SUB_OFFSET = (x) => Number(x >> 32n)const SUB_LENGTH = (x) => Number(x & 0xFFFFFFFFn)const memos_lookup = sto_subfield(txn, sfMemos);if (typeof memos_lookup === 'number'){ // sfMemos was not found in the STObject pointed at by memo_ptr}else{ // sfMemos was found and its location is as follows: const memo_start = SUB_OFFSET(memos_lookup) const memo_len = SUB_LENGTH(memos_lookup) const memo = txn.slice(memo_start, memo_len)}
Parameters
Section titled “Parameters”Name | Type | Description |
---|---|---|
read_ptr | uint32_t | Pointer to the buffer containing the STObject |
read_len | uint32_t | Length of STObject |
field_id | uint32_t | The |
Name | Type | Description |
---|---|---|
sto | ByteArray or HexString | The STO object (binary encoded ledger data) from which to extract the subfield. |
field_id | number | The ID of the field 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: or an error code if the extraction fails. |