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:

TRON449 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0585C 236C696E6Btxt "#link"
05E5C 235F616461txt "#_ada"
0640F 0A 58000000 5E00 0000map leaf, size 10: @58 → @5E
06E3C 616765txt "age"
07202 29000000000000 00i64 41
07B0F 0A 6E000000 7200 0000map leaf, size 10: @6E → @72
0856C 6D656E746F72txt "mentor"
08C0F 0A 85000000 6400 0000map leaf, size 10: @85 → @64
0964C 726F6C65txt "role"
09B8C 656E67696E6565 72txt "engineer"
0A40F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
0AE4C 6E616D65txt "name"
0B33C 426F62txt "Bob"
0B70F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0C107 16 00990000 7B00 0000 8C000000 A400 0000 B7000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @7B → @8C → @A4 → @B7
0D73C 616765txt "age"
0DB02 1D000000000000 00i64 29
0E40F 0A D7000000 DB00 0000map leaf, size 10: @D7 → @DB
0EE4C 726F6C65txt "role"
0F38C 64657369676E65 72txt "designer"
0FC0F 0A EE000000 F300 0000map leaf, size 10: @EE → @F3
1064C 6E616D65txt "name"
10B2C 4379txt "Cy"
10E0F 0A 06010000 0B01 0000map leaf, size 10: @106 → @10B
11807 12 00910000 E400 0000 FC000000 0E01 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @E4 → @FC → @10E
12A6C 617574686F72txt "author"
1315C 736D6F6B65txt "smoke"
1370F 0A 2A010000 3101 0000map leaf, size 10: @12A → @131
1416C 726561736F6Etxt "reason"
1484C 73656564txt "seed"
14D0F 0A 41010000 4801 0000map leaf, size 10: @141 → @148
15707 0E 40080000 3701 0000 4D010000map branch, size 14, depth 0 (root), slots 6, 11: @137 → @14D
1654C 235F7478txt "#_tx"
16A0F 0A 65010000 5701 0000map leaf, size 10: @165 → @157
1744C 235F6379txt "#_cy"
1790F 0A 74010000 1801 0000map leaf, size 10: @174 → @118
1835C 235F626F62txt "#_bob"
1890F 0A 83010000 C100 0000map leaf, size 10: @183 → @C1
1935C 235F616461txt "#_ada"
1990F 0A 93010000 4600 0000map leaf, size 10: @193 → @46
1A307 16 88210000 6A01 0000 79010000 8901 0000 99010000map branch, size 22, depth 0 (root), slots 3, 7, 8, 13: @16A → @179 → @189 → @199
c649 B
stardust_document *people = NULL;
uint32_t root = 0, ada = 0, age = 0;
int64_t result = 0;
uint32_t status = stardust_parse(people_text, STARDUST_TRON, &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;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 24000000000000 00i64 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_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.
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_parse

c92 B
uint32_t stardust_parse(stardust_bytes source, uint32_t format, stardust_document **output);
c97 B
uint32_t stardust_document_error(const stardust_document *doc, stardust_diagnostic_view *output);

Parameters

stardust_parse

ParameterTypeOwnershipDefaultMeaning
sourcestardust_bytesValueRequiredValue passed to the call.
formatuint32_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]
c187 B
stardust_document *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_DUST, &result);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON466 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0041C 2Btxt "+"
0062C 3F78txt "?x"
00902 01000000000000 00i64 1
0120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9
0271C 78txt "x"
02902 01000000000000 00i64 1
0320F 0A 27000000 2900 0000map leaf, size 10: @27 → @29
03C1C 78txt "x"
03E02 29000000000000 00i64 41
0470F 0A 3C000000 3E00 0000map leaf, size 10: @3C → @3E
0510E 11 00 0300 020000 00 32000000 470000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @32 → @47
06202 02000000000000 00i64 2
06B02 2A000000000000 00i64 42
0740E 11 00 0300 020000 00 62000000 6B0000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @62 → @6B
0858C 24636F6D6D656E 74txt "$comment"
08E14 CD 4F6E65206578 7072657373696F6E 206275696C74206F 6E636520616E6420 6576616C75617465 6420616761696E73 7420736576657261 6C20696E70757473 2E205468650A6576 616C756174652065 78616D706C657320 6C6F616420746869 732066696C652C20 6275696C64206065 787072657373696F 6E602C206576616C 7561746520697420 7769746820656163 680A6F662060696E 707574736020696E 206F726465722061 6E6420636F6D7061 7265206561636820 726573756C742077 6974682060657870 6563746564602Etxt "One expression built onc…"
15D0F 0A 85000000 8E00 0000map leaf, size 10: @85 → @8E
1676C 696E70757473txt "inputs"
16E0F 0A 67010000 5100 0000map leaf, size 10: @167 → @51
1788C 65787065637465 64txt "expected"
1810F 0A 78010000 7400 0000map leaf, size 10: @178 → @74
18B07 0E 02010000 6E01 0000 81010000map branch, size 14, depth 2, slots 1, 8: @16E → @181
19907 0A 01000000 8B01 0000map branch, size 10, depth 1, slots 0: @18B
1A3AC 65787072657373 696F6Etxt "expression"
1AE0F 0A A3010000 1200 0000map leaf, size 10: @1A3 → @12
1B807 12 40090000 5D01 0000 99010000 AE01 0000map branch, size 18, depth 0 (root), slots 6, 8, 11: @15D → @199 → @1AE

Report a malformed byte at offset zero

malformed_text holds these bytes:

text1 B
]
c188 B
stardust_document *failed = NULL;
uint32_t status = stardust_parse(malformed_text, STARDUST_DUST, &failed);
stardust_diagnostic_view result = {0};
stardust_document_error(failed, &result);
TRON242 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B14 10 696E76616C69 645F617267756D65 6E74txt "invalid_argument"
1D0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
276C 656E74697479txt "entity"
2E00nil
2F0F 0A 27000000 2E00 0000map leaf, size 10: @27 → @2E
397C 6D657373616765txt "message"
4114 1A 496E76616C69 645F53796E746178 206174206F666673 65742030txt "Invalid_Syntax at offset…"
5D0F 0A 39000000 4100 0000map leaf, size 10: @39 → @41
6707 0E 08020000 2F00 0000 5D000000map branch, size 14, depth 1, slots 3, 9: @2F → @5D
754C 70617468txt "path"
7A00nil
7B0F 0A 75000000 7A00 0000map leaf, size 10: @75 → @7A
855C 6669656C64txt "field"
8B00nil
8C0F 0A 85000000 8B00 0000map leaf, size 10: @85 → @8B
964C 636F6465txt "code"
9BCC 696E76616C6964 5F64757374txt "invalid_dust"
A80F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
B26C 6F6666736574txt "offset"
B902 00000000000000 00i64 0
C20F 0A B2000000 B900 0000map leaf, size 10: @B2 → @B9
CC07 1E 51620000 1D00 0000 67000000 7B00 0000 8C000000 A800 0000 C2000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @1D → @67 → @7B → @8C → @A8 → @C2

Report malformed DUST

malformed_text holds these bytes:

text1 B
[
c188 B
stardust_document *failed = NULL;
uint32_t status = stardust_parse(malformed_text, STARDUST_DUST, &failed);
stardust_diagnostic_view result = {0};
stardust_document_error(failed, &result);
TRON242 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B14 10 696E76616C69 645F617267756D65 6E74txt "invalid_argument"
1D0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
276C 656E74697479txt "entity"
2E00nil
2F0F 0A 27000000 2E00 0000map leaf, size 10: @27 → @2E
397C 6D657373616765txt "message"
4114 1A 556E65787065 637465645F456E64 206174206F666673 65742032txt "Unexpected_End at offset…"
5D0F 0A 39000000 4100 0000map leaf, size 10: @39 → @41
6707 0E 08020000 2F00 0000 5D000000map branch, size 14, depth 1, slots 3, 9: @2F → @5D
754C 70617468txt "path"
7A00nil
7B0F 0A 75000000 7A00 0000map leaf, size 10: @75 → @7A
855C 6669656C64txt "field"
8B00nil
8C0F 0A 85000000 8B00 0000map leaf, size 10: @85 → @8B
964C 636F6465txt "code"
9BCC 696E76616C6964 5F64757374txt "invalid_dust"
A80F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
B26C 6F6666736574txt "offset"
B902 02000000000000 00i64 2
C20F 0A B2000000 B900 0000map leaf, size 10: @B2 → @B9
CC07 1E 51620000 1D00 0000 67000000 7B00 0000 8C000000 A800 0000 C2000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @1D → @67 → @7B → @8C → @A8 → @C2

Also calls: stardust_document_error

stardust_document_root

c78 B
uint32_t stardust_document_root(const stardust_document *doc, uint32_t *node);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeuint32_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:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c297 B
stardust_document *source = NULL;
uint32_t root = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &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;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 00000000000000 00i64 0

stardust_document_count

c79 B
uint32_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:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c278 B
stardust_document *source = NULL;
int64_t result = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &source);
if (status == STARDUST_OK) status = stardust_document_count(source, &result);
stardust_document_release(source);
if (status != STARDUST_OK) return status;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 02000000000000 00i64 2

read

Call stardust_document_read_many with capacity 1.

Also calls: stardust_document_read_many

stardust_document_read_many

c147 B
uint32_t stardust_document_read_many(const stardust_document *doc, uint32_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.
startuint32_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:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c527 B
stardust_document *source = NULL;
uint32_t root = 0;
stardust_node_view view = {0};
int64_t written = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &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;
TRON233 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
043C 6B6579txt "key"
080Ctxt ""
090F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
134C 6B696E64txt "kind"
186C 6F626A656374txt "object"
1F0F 0A 13000000 1800 0000map leaf, size 10: @13 → @18
29BC 66697273745F63 68696C64txt "first_child"
3502 01000000000000 00i64 1
3E0F 0A 29000000 3500 0000map leaf, size 10: @29 → @35
488C 706F736974696F 6Etxt "position"
5102 00000000000000 00i64 0
5A0F 0A 48000000 5100 0000map leaf, size 10: @48 → @51
6407 0E 00810000 3E00 0000 5A000000map branch, size 14, depth 1, slots 8, 15: @3E → @5A
726C 706172656E74txt "parent"
7900nil
7A0F 0A 72000000 7900 0000map leaf, size 10: @72 → @79
844C 74657874txt "text"
890Ctxt ""
8A0F 0A 84000000 8900 0000map leaf, size 10: @84 → @89
947C 626F6F6C65616Etxt "boolean"
9C01bit false
9D0F 0A 94000000 9C00 0000map leaf, size 10: @94 → @9C
A7CC 6E6578745F7369 626C696E67txt "next_sibling"
B400nil
B50F 0A A7000000 B400 0000map leaf, size 10: @A7 → @B4
BF07 22 A1990000 0900 0000 1F000000 6400 0000 7A000000 8A00 0000 9D000000 B500 0000map branch, size 34, depth 0 (root), slots 0, 5, 7, 8, 11, 12, 15: @9 → @1F → @64 → @7A → @8A → @9D → @B5

document/read_many

input_text holds this document:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c527 B
stardust_document *source = NULL;
uint32_t root = 0;
stardust_node_view view = {0};
int64_t written = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &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;
TRON233 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
043C 6B6579txt "key"
080Ctxt ""
090F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
134C 6B696E64txt "kind"
186C 6F626A656374txt "object"
1F0F 0A 13000000 1800 0000map leaf, size 10: @13 → @18
29BC 66697273745F63 68696C64txt "first_child"
3502 01000000000000 00i64 1
3E0F 0A 29000000 3500 0000map leaf, size 10: @29 → @35
488C 706F736974696F 6Etxt "position"
5102 00000000000000 00i64 0
5A0F 0A 48000000 5100 0000map leaf, size 10: @48 → @51
6407 0E 00810000 3E00 0000 5A000000map branch, size 14, depth 1, slots 8, 15: @3E → @5A
726C 706172656E74txt "parent"
7900nil
7A0F 0A 72000000 7900 0000map leaf, size 10: @72 → @79
844C 74657874txt "text"
890Ctxt ""
8A0F 0A 84000000 8900 0000map leaf, size 10: @84 → @89
947C 626F6F6C65616Etxt "boolean"
9C01bit false
9D0F 0A 94000000 9C00 0000map leaf, size 10: @94 → @9C
A7CC 6E6578745F7369 626C696E67txt "next_sibling"
B400nil
B50F 0A A7000000 B400 0000map leaf, size 10: @A7 → @B4
BF07 22 A1990000 0900 0000 1F000000 6400 0000 7A000000 8A00 0000 9D000000 B500 0000map branch, size 34, depth 0 (root), slots 0, 5, 7, 8, 11, 12, 15: @9 → @1F → @64 → @7A → @8A → @9D → @B5

stardust_document_member

c118 B
uint32_t stardust_document_member(const stardust_document *doc, uint32_t object, stardust_bytes name, uint32_t *node);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
objectuint32_tValueRequiredValue passed to the call.
namestardust_bytesValueRequiredValue passed to the call.
nodeuint32_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:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c433 B
stardust_document *source = NULL;
uint32_t root = 0, node = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &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;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 01000000000000 00i64 1

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

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

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeuint32_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:

TRON33 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 29000000000000 00i64 41
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
c512 B
stardust_document *source = NULL;
uint32_t root = 0, node = 0;
int64_t result = 0;
uint32_t status = stardust_parse(input_text, STARDUST_TRON, &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;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 29000000000000 00i64 41

stardust_document_f64

c92 B
uint32_t stardust_document_f64(const stardust_document *doc, uint32_t node, double *output);

Parameters

ParameterTypeOwnershipDefaultMeaning
docconst stardust_document *Borrowed handleRequiredKeep the handle alive until the call returns.
nodeuint32_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:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1
c376 B
stardust_document *source = NULL;
uint32_t root = 0;
double result = 0;
uint32_t status = stardust_parse(number_text, STARDUST_TRON, &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;
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1

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:

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9
c339 B
stardust_document *source = NULL;
stardust_text *result = NULL;
uint32_t status = stardust_parse(expression_text, STARDUST_TRON, &source);
if (status == STARDUST_OK) status = stardust_serialize(source, STARDUST_TRON, 0, &result);
stardust_document_release(source);
if (status != STARDUST_OK) {stardust_text_release(result); return status;}
TRON76 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 74657874txt "text"
0914 2F 54524F4E1C2B 2C3F780201000000 000000000E150007 0003000000040000 0006000000090000 0012000000000000 00txt "TRON\u001C+,?x\u0002\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000E\u0015\u0000\u0007\u0000\u0003…"
3A0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9

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
kinduint32_tNoneUnsigned u32Always present—
booleanuint32_tNoneUnsigned u32Always presentTrue only for true.
parentuint32_tNoneUnsigned u32STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE shows the root.
positionuint32_tCountUnsigned u32Always presentIndex within the parent container.
first_childuint32_tNoneUnsigned u32STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE shows that there is no child.
next_siblinguint32_tNoneUnsigned u32STARDUST_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
parentuint32_tUnsigned u32Required: node ID or STARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODESTARDUST_DOCUMENT_NO_NODE adds the root.
kinduint32_tUnsigned u32ZeroAlways present—
booleanuint32_tUnsigned u32ZeroAlways presentValue of a boolean node.
numberuint32_tUnsigned u32STARDUST_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.