Emplace a field into an existing STObject at its canonical placement



  • Parse an STObject S (source object) pointed to by sread_ptr
  • Parse an STObject F (to inject/emplace) pointed to by fread_ptr
  • Write a new STObject to write_ptr which places F into S at the canonical position field_id


Field ID encoding

The sto_ apis accept a field_id parameter encoded as follows: (type << 16U) + field
Thus type 1 field 2 would be 0x10002U.


int64_t sto_emplace (
    uint32_t write_ptr,
    uint32_t write_len,
    uint32_t sread_ptr,
    uint32_t sread_len,
    uint32_t fread_ptr,
    uint32_t fread_len,
    uint32_t field_id


uint8_t tx_out[1024];

int64_t tx_len =
    sto_emplace(tx_out, sizeof(tx_out),
                tx_in, tx_len,
                sequence_field, 5, sfSequence);

if (tx_len <= 0)
    rollback("Emplacing failed.", 17, 1);


write_ptruint32_tThe buffer to write the modified STObject to
write_lenuint32_tThe length of the output buffer
sread_ptruint32_tThe buffer to read the source STObject from
sread_lenuint32_tThe Length of the source object
fread_ptruint32_tThe buffer to read the field to be emplaced/injected from
fread_lenuint32_tThe length of the field to be emplaced/injected
field_iduint32_tThe sf code (location) to form the emplacement. If this already exists in the source object then the existing field is overriden. If it doesn't exist it is inserted.

Return Code

int64_tThe number of bytes written to write_ptr

If negative, an error:
- pointers/lengths specified outside of hook memory.

- Output buffer must be at least as large as the source object + the injected field, even if the field is only being overriden.

- Field you are attempting to emplace is too large

- The supplied STObject is malformed or not an STObject.