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
odin280 B
people := stardust.parse(people_text, .TRON) or_return
defer stardust.close(&people)

root := stardust.root(people) or_return
ada := stardust.member(people, root, "#_ada") or_return
age := stardust.member(people, ada, "age") or_return
result := stardust.i64(people, age) or_return
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
parsedocumentparse(text, format) returns an owned document.
rootnodedocument.root() returns the root node ID.
countcountdocument.count() returns the number of nodes.
readnode_viewdocument.read(id) returns a node view: kind, boolean, parent, position, first_child, next_sibling, key and text.
read_manynode_viewsdocument.read_many(start, capacity) reads consecutive node views.
membernodedocument.member(id, key) returns the first matching object member ID.
child_iteratornode_viewsdocument.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.
i64integerRead an exact signed integer.
f64realRead a finite floating-point number.
closenoneRelease the document handle.

parse

odin114 B
parse :: proc(
	text: string,
	format: Source_Format,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
textstringValueRequiredEncoded input bytes in the selected format. TRON is binary.
formatSource_FormatValueRequiredThe codec to use for this operation.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_JSONJSON text is malformed
.Invalid_Argumentthe text is malformed, the format is unknown or a number is outside i64 or finite f64
.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]
odin88 B
result := stardust.parse(expression_text, .DUST) or_return
defer stardust.close(&result)
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 holds these bytes:

text1 B
]
odin110 B
failed, result := stardust.parse(malformed, .DUST)
defer stardust.close(&failed)
defer stardust.close(&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 holds these bytes:

text1 B
[
odin110 B
failed, result := stardust.parse(malformed, .DUST)
defer stardust.close(&failed)
defer stardust.close(&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

C exports: stardust_parse, stardust_document_error

root

odin48 B
root :: proc(document: Document) -> (u32, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.

Errors

StatusWhen
.Closedthe document is closed

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
odin131 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

result := i64(stardust.root(source) or_return)
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 00000000000000 00i64 0

C exports: stardust_document_root

count

odin57 B
count :: proc(document: Document) -> (builtin.i64, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.

Errors

StatusWhen
.Closedthe document is closed

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
odin132 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

result := i64(stardust.count(source) or_return)
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 02000000000000 00i64 2

C exports: stardust_document_count

read

odin63 B
read :: proc(document: Document, id: u32) -> (Node_View, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
idu32ValueRequiredA node ID within the receiver document.

Errors

StatusWhen
.Invalid_Argumentid is not a node of the document
.Closedthe document is closed

Notes

Text contains string values. Read numbers with i64 or f64.

Examples

document/read

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
odin172 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

root := stardust.root(source) or_return
result := stardust.read(source, root) or_return
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

C exports: stardust_document_read_many

read_many

odin86 B
read_many :: proc(document: Document, start: u32, output: []Node_View) -> (int, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
startu32ValueRequiredThe first node ID of the consecutive read.
output[]Node_ViewValueRequiredThe maximum number of node views to read. For output slices, the call uses the caller's slice length.

Errors

StatusWhen
.Invalid_Argumentstart is past the last node or capacity is negative
.Closedthe document is closed

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
odin229 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

root := stardust.root(source) or_return
views: [1]stardust.Node_View
_ = stardust.read_many(source, root, views[:]) or_return
result := views[0]
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

C exports: stardust_document_read_many

member

odin72 B
member :: proc(document: Document, id: u32, key: string) -> (u32, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
idu32ValueRequiredA node ID within the receiver document.
keystringValueRequiredThe object member name to find.

Errors

StatusWhen
.Not_Foundthe object has no member with the key
.Invalid_Argumentid is not an object node of the document
.Closedthe document is closed

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
odin197 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

root := stardust.root(source) or_return
node := stardust.member(source, root, "x") or_return
result := i64(node)
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 01000000000000 00i64 1

C exports: stardust_document_member

child_iterator

odin64 B
child_iterator :: proc(doc: Document, id: u32) -> Child_Iterator

Parameters

ParameterTypeOwnershipDefaultMeaning
docDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
idu32ValueRequiredA node ID within the receiver document.

Errors

StatusWhen
.Invalid_Argumentid is not a node of the document
.Closedthe document is closed

Notes

Keep the document open during iteration. A scalar has no children. A read failure is reported once and ends iteration.

Examples

Iterate the children of a node

seed_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
odin291 B
seed := stardust.parse(seed_text, .TRON) or_return
defer stardust.close(&seed)

root := stardust.root(seed) or_return
it := stardust.child_iterator(seed, root)
result: i64 = 0
for view in stardust.iterate_children(&it) {
	if len(view.key) > 0 {result += 1}
}
if it.err != nil {return it.err}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 04000000000000 00i64 4

C exports: stardust_document_read_many

members

child_iterator views carry each member key. Odin has no separate members iterator.

C exports: stardust_document_read_many

i64

odin64 B
i64 :: proc(document: Document, id: u32) -> (builtin.i64, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
idu32ValueRequiredA node ID within the receiver document.

Errors

StatusWhen
.Invalid_Argumentthe node is not an integer number
.Closedthe document is closed

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
odin224 B
source := stardust.parse(input_text, .TRON) or_return
defer stardust.close(&source)

root := stardust.root(source) or_return
node := stardust.member(source, root, "x") or_return
result := stardust.i64(source, node) or_return
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 29000000000000 00i64 41

C exports: stardust_document_i64

f64

odin64 B
f64 :: proc(document: Document, id: u32) -> (builtin.f64, Error)

Parameters

ParameterTypeOwnershipDefaultMeaning
documentDocumentBorrowed for the callRequiredThe document owner for this operation. Keep it alive during the call.
idu32ValueRequiredA node ID within the receiver document.

Errors

StatusWhen
.Invalid_Argumentthe node is not a number or its value overflows f64
.Closedthe document is closed

Notes

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

Examples

document/f64

float_text holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1
odin158 B
source := stardust.parse(float_text, .TRON) or_return
defer stardust.close(&source)

result := stardust.f64(source, stardust.root(source) or_return) or_return
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1

C exports: stardust_document_f64

close

odin34 B
close :: proc(document: ^Document)

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
document^DocumentConsumed ownerRequiredThe document owner to release. Do not use it 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
odin189 B
source := stardust.parse(expression_text, .TRON) or_return
defer stardust.close(&source)

result := stardust.serialize(source, .TRON) or_return
defer delete(result)

stardust.close(&source)
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

C exports: stardust_document_release

node_view

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

FieldTypeUnitAbsentMeaning
kindValue_KindNone——
booleanboolNone—True only for true.
parentu32NoneNO_NODE—
positionu32Count—Index within the parent container.
first_childu32NoneNO_NODE—
next_siblingu32NoneNO_NODE—
keystringNone—Member key of an object member, else empty.
textstringNone—Value of a string, else empty. It can contain NUL.

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.

FieldTypeAbsentMeaning
parentu32NO_NODE—
kindValue_Kind——
booleanbool—Value of a boolean node.
numberNumbernilValue of a number node.
keystring—Member key when the parent is an object.
textstring—Value of a string node.