Documents

The example parses the people document in your selected format. It then reads Ada's age through the document nodes. Typed reads give you these values without serializing the document.

Example

Read Ada's age

people_text holds this document:

dust232 B
#_ada {name Ada
       role engineer
       age  36}
#_bob {name   Bob
       role   engineer
       age    41
       mentor {#link #_ada}}
#_cy  {name Cy
       role designer
       age  29}
#_tx  {author smoke
       reason seed}
c647 B
stardust_document *people = NULL;
int64_t root = 0, ada = 0, age = 0;
int64_t result = 0;
int64_t status = stardust_parse(people_text, STARDUST_DUST, &people);
if (status == STARDUST_OK) status = stardust_document_root(people, &root);
if (status == STARDUST_OK) status = stardust_document_member(people, root, (stardust_bytes){(const uint8_t *)"#_ada", 5}, &ada);
if (status == STARDUST_OK) status = stardust_document_member(people, ada, (stardust_bytes){(const uint8_t *)"age", 3}, &age);
if (status == STARDUST_OK) status = stardust_document_i64(people, age, &result);
stardust_document_release(people);
if (status != STARDUST_OK) return status;
Result / 2 B
36

Numbers

A document number is an i64 integer or a finite f64 value. The number type defines both.

  • An integer read requires an integer node. A floating-point node can cause the read to fail.
  • Choose the typed read that matches the node that you read.

Operations

OperationReturnsSummary
stardust_schema_validateStatus. none through outputvalidate_schema(bundle, instance, node) validates a native subtree with JSON Schema Draft 7.
stardust_parseStatus. document through outputparse(text, format) returns an owned document.
stardust_document_rootStatus. node through outputdocument.root() returns the root node ID.
stardust_document_countStatus. count through outputdocument.count() returns the number of nodes.
readUnavailabledocument.read(id) returns a node view: kind, boolean, parent, position, first_child, next_sibling, key and text.
stardust_document_read_manyStatus. node_views through outputdocument.read_many(start, capacity) reads consecutive node views.
stardust_document_memberStatus. node through outputdocument.member(id, key) returns the first matching object member ID.
stardust_document_pointerStatus. found_node through outputdocument.pointer(id, path) returns the node that a path array or JSON Pointer text selects from id, or no node when the path misses.
stardust_pointer_parseStatus. path through outputpointer.parse(text) returns the path array of JSON Pointer text.
stardust_pointer_formatStatus. name through outputpointer.format(path) returns the JSON Pointer text of a path array.
childrenUnavailabledocument.children(id) iterates the node views of a node's children in order.
membersUnavailabledocument.members(id) iterates the members of an object node in order, each with its key.
stardust_document_i64Status. integer through outputRead an exact signed integer.
stardust_document_f64Status. real through outputRead a finite floating-point number.
stardust_document_releasevoidRelease the document handle.

stardust_schema_validate

c141 B
int64_t stardust_schema_validate(const stardust_document *bundle, const stardust_document *instance, int64_t node, stardust_result **output);
c95 B
int64_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_schema_validate

ParameterTypeOwnershipDefaultMeaning
bundleconst stardust_document *Borrowed handleRequiredThe document containing the root schema name, schema resources and optional schemaPath.
instanceconst stardust_document *Borrowed handleRequiredThe native document containing the value to validate.
nodeint64_tValueRequiredThe node ID within instance to validate. Zero selects its root.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe bundle, schemaPath or node is invalid or an input exceeds its limit
STARDUST_INVALID_DEFINITIONa schema cannot compile or a reference cannot resolve
STARDUST_SCHEMA_VIOLATIONthe selected instance does not match the schema
STARDUST_EVALUATION_FAILEDthe validation work limit is exceeded
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Examples

Validate a document against an authored schema

c512 B
stardust_document *bundle = NULL;
stardust_document *instance = NULL;
stardust_result *validated = NULL;
int64_t status = stardust_parse(bundle_text, STARDUST_DUST, &bundle);
if (status == STARDUST_OK) status = stardust_parse(instance_text, STARDUST_DUST, &instance);
if (status == STARDUST_OK) status = stardust_schema_validate(bundle, instance, 0, &validated);
stardust_result_release(validated);
stardust_document_release(instance);
stardust_document_release(bundle);
if (status != STARDUST_OK) return status;

Validate a document against an authored schema

c512 B
stardust_document *bundle = NULL;
stardust_document *instance = NULL;
stardust_result *validated = NULL;
int64_t status = stardust_parse(bundle_text, STARDUST_JSON, &bundle);
if (status == STARDUST_OK) status = stardust_parse(instance_text, STARDUST_JSON, &instance);
if (status == STARDUST_OK) status = stardust_schema_validate(bundle, instance, 0, &validated);
stardust_result_release(validated);
stardust_document_release(instance);
stardust_document_release(bundle);
if (status != STARDUST_OK) return status;

Validate a document against an authored schema

c510 B
stardust_document *bundle = NULL;
stardust_document *instance = NULL;
stardust_result *validated = NULL;
int64_t status = stardust_parse(bundle_text, STARDUST_EDN, &bundle);
if (status == STARDUST_OK) status = stardust_parse(instance_text, STARDUST_EDN, &instance);
if (status == STARDUST_OK) status = stardust_schema_validate(bundle, instance, 0, &validated);
stardust_result_release(validated);
stardust_document_release(instance);
stardust_document_release(bundle);
if (status != STARDUST_OK) return status;

Validate a document against an authored schema

c512 B
stardust_document *bundle = NULL;
stardust_document *instance = NULL;
stardust_result *validated = NULL;
int64_t status = stardust_parse(bundle_text, STARDUST_TRON, &bundle);
if (status == STARDUST_OK) status = stardust_parse(instance_text, STARDUST_TRON, &instance);
if (status == STARDUST_OK) status = stardust_schema_validate(bundle, instance, 0, &validated);
stardust_result_release(validated);
stardust_document_release(instance);
stardust_document_release(bundle);
if (status != STARDUST_OK) return status;

Also calls: stardust_result_error, stardust_result_release

stardust_parse

c90 B
int64_t stardust_parse(stardust_bytes source, int64_t format, stardust_document **output);
c96 B
int64_t stardust_document_error(const stardust_document *doc, stardust_diagnostic_view *output);

Parameters

stardust_parse

ParameterTypeOwnershipDefaultMeaning
sourcestardust_bytesValueRequiredValue passed to the call.
formatint64_tValueRequiredThe codec to use for this operation.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_error

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_INVALID_JSONJSON text is malformed
STARDUST_INVALID_ARGUMENTthe text is malformed, the format is unknown or a number is outside i64 or finite f64
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Examples

Parse the shared DUST expression fixture

expression_text holds these bytes:

text278 B
// One expression built once and evaluated against several inputs. The
// evaluate examples load this file, build `expression`, evaluate it with each
// of `inputs` in order and compare each result with `expected`.
expression [+ ?x 1]
inputs     [{x 1} {x 41}]
expected   [2 42]
c186 B
stardust_document *result = NULL;
int64_t status = stardust_parse(expression_text, STARDUST_DUST, &result);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
Result / 293 B
{
  // One expression built once and evaluated against several inputs. The
  // evaluate examples load this file, build `expression`, evaluate it with each
  // of `inputs` in order and compare each result with `expected`.
  expression [+ ?x 1]
  inputs     [{x 1} {x 41}]
  expected   [2 42]}

Report a malformed byte at offset zero

malformed_text holds these bytes:

text1 B
]
c187 B
stardust_document *failed = NULL;
int64_t status = stardust_parse(malformed_text, STARDUST_DUST, &failed);
stardust_diagnostic_view result = {0};
stardust_document_error(failed, &result);
Result / 175 B
{violations null
 code       invalid_dust
 message    Invalid_Syntax at offset 0
 path       null
 field      null
 entity     null
 offset     0
 status     invalid_argument}

Report malformed DUST

malformed_text holds these bytes:

text1 B
[
c187 B
stardust_document *failed = NULL;
int64_t status = stardust_parse(malformed_text, STARDUST_DUST, &failed);
stardust_diagnostic_view result = {0};
stardust_document_error(failed, &result);
Result / 175 B
{violations null
 code       invalid_dust
 message    Unexpected_End at offset 2
 path       null
 field      null
 entity     null
 offset     2
 status     invalid_argument}

Also calls: stardust_document_error

stardust_document_root

c76 B
int64_t stardust_document_root(const stardust_document *doc, int64_t *node);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeint64_t *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Examples

document/root

input_text holds this document:

dust5 B
x 41
c295 B
stardust_document *source = NULL;
int64_t root = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
int64_t result = root;
Result / 1 B
0

stardust_document_count

c78 B
int64_t stardust_document_count(const stardust_document *doc, int64_t *count);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
countint64_t *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Examples

document/count

input_text holds this document:

dust5 B
x 41
c277 B
stardust_document *source = NULL;
int64_t result = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_count(source, &result);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
Result / 1 B
2

read

Call stardust_document_read_many with capacity 1.

Also calls: stardust_document_read_many

stardust_document_read_many

c145 B
int64_t stardust_document_read_many(const stardust_document *doc, int64_t start, int64_t capacity, stardust_node_view *output, int64_t *written);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
startint64_tValueRequiredThe first node ID of the consecutive read.
capacityint64_tValueRequiredThe maximum number of node views to read. For output slices, the call uses the caller's slice length.
outputstardust_node_view *Caller-owned arrayNULLWrites at most capacity elements and reports their count in written.
writtenint64_t *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTstart is past the last node or capacity is negative

Examples

document/read_many

input_text holds this document:

dust5 B
x 41
c525 B
stardust_document *source = NULL;
int64_t root = 0;
stardust_node_view view = {0};
int64_t written = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK) status = stardust_document_read_many(source, root, 1, &view, &written);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
// The root object has no key or text, so the view borrows nothing.
stardust_node_view result = view;
Result / 145 B
{kind         object
 boolean      false
 parent       null
 position     0
 first_child  1
 next_sibling null
 key          ""
 text         ""}

document/read_many

input_text holds this document:

dust5 B
x 41
c525 B
stardust_document *source = NULL;
int64_t root = 0;
stardust_node_view view = {0};
int64_t written = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK) status = stardust_document_read_many(source, root, 1, &view, &written);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
// The root object has no key or text, so the view borrows nothing.
stardust_node_view result = view;
Result / 145 B
{kind         object
 boolean      false
 parent       null
 position     0
 first_child  1
 next_sibling null
 key          ""
 text         ""}

stardust_document_member

c115 B
int64_t stardust_document_member(const stardust_document *doc, int64_t object, stardust_bytes name, int64_t *node);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
objectint64_tValueRequiredValue passed to the call.
namestardust_bytesValueRequiredValue passed to the call.
nodeint64_t *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_NOT_FOUNDthe object has no member with the key
STARDUST_INVALID_ARGUMENTid is not an object node of the document

Examples

document/member

input_text holds this document:

dust5 B
x 41
c431 B
stardust_document *source = NULL;
int64_t root = 0, node = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK) status = stardust_document_member(source, root, (stardust_bytes){(const uint8_t *)"x", 1}, &node);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
int64_t result = node;
Result / 1 B
1

stardust_document_pointer

c144 B
int64_t stardust_document_pointer(const stardust_document *doc, int64_t start, const stardust_document *path, int64_t path_node, int64_t *node);
c120 B
int64_t stardust_document_pointer_text(const stardust_document *doc, int64_t start, stardust_bytes text, int64_t *node);
c77 B
int64_t stardust_document_builder_create(stardust_document_builder **output);
c128 B
int64_t stardust_document_builder_add_many(stardust_document_builder *builder, const stardust_node_input *nodes, int64_t count);
c103 B
int64_t stardust_document_builder_seal(stardust_document_builder *builder, stardust_document **output);
c75 B
void stardust_document_builder_release(stardust_document_builder *builder);
c55 B
void stardust_document_release(stardust_document *doc);

Parameters

stardust_document_pointer

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
startint64_tValueRequiredValue passed to the call.
pathconst stardust_document *Borrowed handleRequiredThe stored definition path.
path_nodeint64_tValueRequiredValue passed to the call.
nodeint64_t *Caller-owned outputRequiredReceives the scalar result.

stardust_document_pointer_text

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
startint64_tValueRequiredValue passed to the call.
textstardust_bytesValueRequiredValue passed to the call.
nodeint64_t *Caller-owned outputRequiredReceives the scalar result.

stardust_document_builder_create

ParameterTypeOwnershipDefaultMeaning
outputstardust_document_builder **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_builder_add_many

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Borrowed handleRequiredKeep the handle alive until the call returns.
nodesconst stardust_node_input *Borrowed arrayNULLReads count elements during the call.
countint64_tValueRequiredValue passed to the call.

stardust_document_builder_seal

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_builder_release

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Consumed handleNULLEnds ownership. Do not use the handle after this call.

stardust_document_release

ParameterTypeOwnershipDefaultMeaning
docstardust_document *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_POINTERthe text is not a JSON Pointer or the array is not a canonical path array
STARDUST_INVALID_ARGUMENTid is not a node of the document
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Notes

A miss is not a failure: a missing key, an index past the end, a string token such as - on an array, or a step into a scalar. An integer token on an object selects the member named by its decimal text. Duplicate keys select the first member, as member does. A malformed path fails even after a step that misses.

Examples

document/pointer

expression_text holds these bytes:

text278 B
// One expression built once and evaluated against several inputs. The
// evaluate examples load this file, build `expression`, evaluate it with each
// of `inputs` in order and compare each result with `expected`.
expression [+ ?x 1]
inputs     [{x 1} {x 41}]
expected   [2 42]
c481 B
stardust_document *source = NULL;
int64_t root = 0, node = STARDUST_DOCUMENT_NO_NODE;
int64_t status = stardust_parse(expression_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK)
    status = stardust_document_pointer_text(source, root, (stardust_bytes){(const uint8_t *)"/inputs/1/x", 11}, &node);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
int64_t result = node;
Result / 1 B
9

Also calls: stardust_document_pointer_text, stardust_document_builder_create, stardust_document_builder_add_many, stardust_document_builder_seal, stardust_document_builder_release, stardust_document_release

stardust_pointer_parse

c80 B
int64_t stardust_pointer_parse(stardust_bytes text, stardust_document **output);
c96 B
int64_t stardust_document_error(const stardust_document *doc, stardust_diagnostic_view *output);
c145 B
int64_t stardust_document_read_many(const stardust_document *doc, int64_t start, int64_t capacity, stardust_node_view *output, int64_t *written);
c91 B
int64_t stardust_document_i64(const stardust_document *doc, int64_t node, int64_t *output);
c55 B
void stardust_document_release(stardust_document *doc);

Parameters

stardust_pointer_parse

ParameterTypeOwnershipDefaultMeaning
textstardust_bytesValueRequiredEncoded input bytes in the selected format. TRON is binary.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_error

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_document_read_many

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
startint64_tValueRequiredValue passed to the call.
capacityint64_tValueRequiredValue passed to the call.
outputstardust_node_view *Caller-owned arrayNULLWrites at most capacity elements and reports their count in written.
writtenint64_t *Caller-owned outputRequiredReceives the scalar result.

stardust_document_i64

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeint64_tValueRequiredValue passed to the call.
outputint64_t *Caller-owned outputRequiredReceives the scalar result.

stardust_document_release

ParameterTypeOwnershipDefaultMeaning
docstardust_document *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_POINTERthe text is not empty and does not start with /, or holds ~ not followed by 0 or 1
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Notes

The empty text is the root path []. ~1 decodes to / and ~0 to ~. A canonical array index token becomes an integer, including a key such as 2024; every other token stays a string, such as 01 or -. No target document is needed.

Examples

pointer_parse

c226 B
stardust_document *result = NULL;
int64_t status = stardust_pointer_parse((stardust_bytes){(const uint8_t *)"/inputs/1/x", 11}, &result);
if (status != STARDUST_OK) {
    stardust_document_release(result);
    return status;
}
Result / 12 B
[inputs 1 x]

Also calls: stardust_document_error, stardust_document_read_many, stardust_document_i64, stardust_document_release

stardust_pointer_format

c101 B
int64_t stardust_pointer_format(const stardust_document *path, int64_t node, stardust_text **output);
c77 B
int64_t stardust_document_builder_create(stardust_document_builder **output);
c128 B
int64_t stardust_document_builder_add_many(stardust_document_builder *builder, const stardust_node_input *nodes, int64_t count);
c103 B
int64_t stardust_document_builder_seal(stardust_document_builder *builder, stardust_document **output);
c75 B
void stardust_document_builder_release(stardust_document_builder *builder);
c55 B
void stardust_document_release(stardust_document *doc);
c63 B
stardust_bytes stardust_text_data(const stardust_text *result);
c91 B
int64_t stardust_text_error(const stardust_text *result, stardust_diagnostic_view *output);
c50 B
void stardust_text_release(stardust_text *result);

Parameters

stardust_pointer_format

ParameterTypeOwnershipDefaultMeaning
pathconst stardust_document *Borrowed handleRequiredThe database file path.
nodeint64_tValueRequiredValue passed to the call.
outputstardust_text **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_builder_create

ParameterTypeOwnershipDefaultMeaning
outputstardust_document_builder **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_builder_add_many

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Borrowed handleRequiredKeep the handle alive until the call returns.
nodesconst stardust_node_input *Borrowed arrayNULLReads count elements during the call.
countint64_tValueRequiredValue passed to the call.

stardust_document_builder_seal

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_document_builder_release

ParameterTypeOwnershipDefaultMeaning
builderstardust_document_builder *Consumed handleNULLEnds ownership. Do not use the handle after this call.

stardust_document_release

ParameterTypeOwnershipDefaultMeaning
docstardust_document *Consumed handleNULLEnds ownership. Do not use the handle after this call.

stardust_text_data

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_text *Borrowed handleNULLKeep the handle alive until the call returns.

stardust_text_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_text *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_text_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_text *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_POINTERa token is a negative or non-integral number, an index-shaped string such as "0", or neither a number nor a string
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Notes

The root path [] formats as empty text. / encodes as ~1 and ~ as ~0. pointer.parse of the result returns the same path.

Examples

pointer_format

c350 B
stardust_document *path = NULL;
stardust_text *result = NULL;
int64_t status = stardust_pointer_parse((stardust_bytes){(const uint8_t *)"/inputs/1/x", 11}, &path);
if (status == STARDUST_OK) status = stardust_pointer_format(path, 0, &result);
stardust_document_release(path);
if (status != STARDUST_OK) {stardust_text_release(result); return status;}
Result / 18 B
{text /inputs/1/x}

Also calls: stardust_document_builder_create, stardust_document_builder_add_many, stardust_document_builder_seal, stardust_document_builder_release, stardust_document_release, stardust_text_data, stardust_text_error, stardust_text_release

children

Read the first child, then follow next_sibling with stardust_document_read_many.

Also calls: stardust_document_read_many

members

Follow the children of an object node; each node view carries its key.

Also calls: stardust_document_read_many

stardust_document_i64

c91 B
int64_t stardust_document_i64(const stardust_document *doc, int64_t node, int64_t *output);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeint64_tValueRequiredValue passed to the call.
outputint64_t *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe node is not an integer number

Examples

document/i64

input_text holds this document:

dust5 B
x 41
c510 B
stardust_document *source = NULL;
int64_t root = 0, node = 0;
int64_t result = 0;
int64_t status = stardust_parse(input_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK) status = stardust_document_member(source, root, (stardust_bytes){(const uint8_t *)"x", 1}, &node);
if (status == STARDUST_OK) status = stardust_document_i64(source, node, &result);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
Result / 2 B
41

stardust_document_f64

c90 B
int64_t stardust_document_f64(const stardust_document *doc, int64_t node, double *output);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeint64_tValueRequiredValue passed to the call.
outputdouble *Caller-owned outputRequiredReceives the scalar result.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe node is not a number or its value overflows f64

Notes

Integer conversion can round values outside the exact f64 integer range.

Examples

document/f64

number_text holds this document:

dust4 B
1.0
c374 B
stardust_document *source = NULL;
int64_t root = 0;
double result = 0;
int64_t status = stardust_parse(number_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_document_root(source, &root);
if (status == STARDUST_OK) status = stardust_document_f64(source, root, &result);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
Result / 3 B
1.0

stardust_document_release

c55 B
void stardust_document_release(stardust_document *doc);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
docstardust_document *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Examples

document/close

expression_text holds this document:

dust9 B
[+ ?x 1]
c338 B
stardust_document *source = NULL;
stardust_text *result = NULL;
int64_t status = stardust_parse(expression_text, STARDUST_DUST, &source);
if (status == STARDUST_OK) status = stardust_serialize(source, STARDUST_DUST, 0, &result);
stardust_document_release(source);
if (status != STARDUST_OK) {stardust_text_release(result); return status;}
Result / 33 B
{
  text '''
    [+ ?x 1]
  '''
}

stardust_node_view

This record contains the result of read and read_many. The key and text fields borrow the document until it closes.

FieldC typeUnitRangeAbsentMeaning
kindint64_tNoneSigned i64Always present—
booleanint64_tNoneSigned i64Always presentTrue only for true.
parentint64_tNoneSigned i64STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE shows the root.
positionint64_tCountSigned i64Always presentIndex within the parent container.
first_childint64_tNoneSigned i64STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE shows that there is no child.
next_siblingint64_tNoneSigned i64STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE shows that there is no next sibling.
keystardust_bytesNoneC type rangeAlways presentMember key of an object member, else empty.
textstardust_bytesNoneC type rangeAlways presentValue of a string, else empty. It can contain NUL.

stardust_node_input

This record supplies a node for add and add_many. The number field holds a typed i64 or f64 value. Go uses I64/F64, Rust and Odin use Number, Clojure uses long or double, and Python uses int or float. This value sets the ABI number kind and the integer or real field.

FieldC typeRangeDefaultAbsentMeaning
parentint64_tSigned i64Required: node ID or STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE adds the root.
kindint64_tSigned i64ZeroAlways present—
booleanint64_tSigned i64ZeroAlways presentValue of a boolean node.
numberint64_tSigned i64STARDUST_NUMBER_INTEGER (0)Always presentSelects integer or real for a Number node. Zero selects Integer.
keystardust_bytesC type rangeZeroAlways presentMember key when the parent is an object.
textstardust_bytesC type rangeZeroAlways presentValue of a string node.
integerint64_tSigned i64ZeroAlways presentContains the value when number is STARDUST_NUMBER_INTEGER. Otherwise, set integer to zero.
realdoubleC type rangeZeroAlways presentContains the finite value when number is STARDUST_NUMBER_FLOAT. Otherwise, set real to zero.