Skip to content

sto_validate ​

Summary. Check whether a buffer is a well-formed serialized object (STO): parse it field by field and confirm the fields consume exactly the whole buffer.

Signature.

c
int64_t sto_validate(uint32_t tread_ptr, uint32_t tread_len);

Parameters.

NameMeaning
tread_ptr, tread_lenThe candidate serialized object. Must be at least 2 bytes.

Return value.

ResultValueMeaning
valid1Fields parse cleanly and end exactly at the buffer end.
invalid0A field failed to parse, or trailing/short bytes remain.
TOO_SMALL-4tread_len < 2.
OUT_OF_BOUNDS-1Region out of bounds.

Caveats. Validation is structural (well-formed field encoding), not semantic — it does not check that required fields are present for a given object type, nor that values are in range. A maximum of 1024 fields are scanned. The scanner does not recognise the 0x99 NOP byte the ledger's deserializer skips, so a NOP-padded template that emit would accept is reported as invalid (0) here; see NOP Bytes (0x99).

Minimal example.

c
int64_t v = sto_validate(SBUF(blob));
if (v == 1)
    accept(SBUF("well-formed sto"), 0);

Related APIs. sto_subfield, sto_emplace, slot_set.