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

peopleText 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
go366 B
people, err := stardust.Parse(peopleText, stardust.TRON)
if err != nil {
	return err
}
defer people.Close()

root, err := people.Root()
if err != nil {
	return err
}
ada, err := people.Member(root, "#_ada")
if err != nil {
	return err
}
age, err := people.Member(ada, "age")
if err != nil {
	return err
}

result, err := people.I64(age)
if err != nil {
	return err
}
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
ValidateSchemanonevalidate_schema(bundle, instance, node) validates a native subtree with JSON Schema Draft 7.
Parsedocumentparse(text, format) returns an owned document.
Document.Rootnodedocument.root() returns the root node ID.
Document.Countcountdocument.count() returns the number of nodes.
Document.Readnode_viewdocument.read(id) returns a node view: kind, boolean, parent, position, first_child, next_sibling, key and text.
Document.ReadManynode_viewsdocument.read_many(start, capacity) reads consecutive node views.
Document.Membernodedocument.member(id, key) returns the first matching object member ID.
Document.Pointerfound_nodedocument.pointer(id, path) returns the node that a path array or JSON Pointer text selects from id, or no node when the path misses.
pointer.Parsepathpointer.parse(text) returns the path array of JSON Pointer text.
pointer.Formatnamepointer.format(path) returns the JSON Pointer text of a path array.
Document.Childrennode_viewsdocument.children(id) iterates the node views of a node's children in order.
Document.Membersnode_viewsdocument.members(id) iterates the members of an object node in order, each with its key.
Document.I64integerRead an exact signed integer.
Document.F64realRead a finite floating-point number.
Document.ClosenoneRelease the document handle.

ValidateSchema

go62 B
func ValidateSchema(bundle, instance *Document, node ID) error

Parameters

ParameterTypeOwnershipDefaultMeaning
bundle*DocumentBorrowed for the callRequiredThe document containing the root schema name, schema resources and optional schemaPath.
instance*DocumentBorrowed for the callRequiredThe native document containing the value to validate.
nodeIDValueRequiredThe node ID within instance to validate. Zero selects its root.

Errors

StatusWhen
StatusInvalidArgumentthe bundle, schemaPath or node is invalid or an input exceeds its limit
StatusInvalidDefinitiona schema cannot compile or a reference cannot resolve
StatusSchemaViolationthe selected instance does not match the schema
StatusEvaluationFailedthe validation work limit is exceeded
StatusOutOfMemorynative memory is exhausted

Examples

Validate a document against an authored schema

go304 B
bundle, err := stardust.Parse(bundleText, stardust.DUST)
if err != nil {
	return err
}
defer bundle.Close()
instance, err := stardust.Parse(instanceText, stardust.DUST)
if err != nil {
	return err
}
defer instance.Close()
if err := stardust.ValidateSchema(bundle, instance, 0); err != nil {
	return err
}

Validate a document against an authored schema

go304 B
bundle, err := stardust.Parse(bundleText, stardust.JSON)
if err != nil {
	return err
}
defer bundle.Close()
instance, err := stardust.Parse(instanceText, stardust.JSON)
if err != nil {
	return err
}
defer instance.Close()
if err := stardust.ValidateSchema(bundle, instance, 0); err != nil {
	return err
}

Validate a document against an authored schema

go302 B
bundle, err := stardust.Parse(bundleText, stardust.EDN)
if err != nil {
	return err
}
defer bundle.Close()
instance, err := stardust.Parse(instanceText, stardust.EDN)
if err != nil {
	return err
}
defer instance.Close()
if err := stardust.ValidateSchema(bundle, instance, 0); err != nil {
	return err
}

Validate a document against an authored schema

go304 B
bundle, err := stardust.Parse(bundleText, stardust.TRON)
if err != nil {
	return err
}
defer bundle.Close()
instance, err := stardust.Parse(instanceText, stardust.TRON)
if err != nil {
	return err
}
defer instance.Close()
if err := stardust.ValidateSchema(bundle, instance, 0); err != nil {
	return err
}

C exports: stardust_schema_validate, stardust_result_error, stardust_result_release

Parse

go57 B
func Parse(text []byte, format Format) (*Document, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
text[]byteValueRequiredEncoded input bytes in the selected format. TRON is binary.
formatFormatValueRequiredThe codec to use for this operation.

Errors

StatusWhen
StatusInvalidJSONJSON text is malformed
StatusInvalidArgumentthe text is malformed, the format is unknown or a number is outside i64 or finite f64
StatusOutOfMemorynative memory is exhausted

Examples

Parse the shared DUST expression fixture

expressionText 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]
go111 B
result, err := stardust.Parse(expressionText, stardust.DUST)
if err != nil {
	return err
}
defer result.Close()
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

malformedText holds these bytes:

text1 B
]
go105 B
failed, result := stardust.Parse(malformedText, stardust.DUST)
if failed != nil {
	defer failed.Close()
}
TRON288 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 737461747573txt "status"
00B14 10 696E76616C69 645F617267756D65 6E74txt "invalid_argument"
01D0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
0276C 656E74697479txt "entity"
02E00nil
02F0F 0A 27000000 2E00 0000map leaf, size 10: @27 → @2E
0397C 6D657373616765txt "message"
04114 1A 496E76616C69 645F53796E746178 206174206F666673 65742030txt "Invalid_Syntax at offset…"
05D0F 0A 39000000 4100 0000map leaf, size 10: @39 → @41
06707 0E 08020000 2F00 0000 5D000000map branch, size 14, depth 1, slots 3, 9: @2F → @5D
0754C 70617468txt "path"
07A00nil
07B0F 0A 75000000 7A00 0000map leaf, size 10: @75 → @7A
085AC 76696F6C617469 6F6E73txt "violations"
09000nil
0910F 0A 85000000 9000 0000map leaf, size 10: @85 → @90
09B5C 6669656C64txt "field"
0A100nil
0A20F 0A 9B000000 A100 0000map leaf, size 10: @9B → @A1
0AC07 0E 00090000 9100 0000 A2000000map branch, size 14, depth 2, slots 8, 11: @91 → @A2
0BA07 0A 02000000 AC00 0000map branch, size 10, depth 1, slots 1: @AC
0C44C 636F6465txt "code"
0C9CC 696E76616C6964 5F64757374txt "invalid_dust"
0D60F 0A C4000000 C900 0000map leaf, size 10: @C4 → @C9
0E06C 6F6666736574txt "offset"
0E702 00000000000000 00i64 0
0F00F 0A E0000000 E700 0000map leaf, size 10: @E0 → @E7
0FA07 1E 51620000 1D00 0000 67000000 7B00 0000 BA000000 D600 0000 F0000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @1D → @67 → @7B → @BA → @D6 → @F0

Report malformed DUST

malformedText holds these bytes:

text1 B
[
go174 B
failed, err := stardust.Parse(malformedText, stardust.DUST)
if failed != nil {
	defer failed.Close()
}

var result *stardust.Error
if !errors.As(err, &result) {
	return err
}
TRON288 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 737461747573txt "status"
00B14 10 696E76616C69 645F617267756D65 6E74txt "invalid_argument"
01D0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
0276C 656E74697479txt "entity"
02E00nil
02F0F 0A 27000000 2E00 0000map leaf, size 10: @27 → @2E
0397C 6D657373616765txt "message"
04114 1A 556E65787065 637465645F456E64 206174206F666673 65742032txt "Unexpected_End at offset…"
05D0F 0A 39000000 4100 0000map leaf, size 10: @39 → @41
06707 0E 08020000 2F00 0000 5D000000map branch, size 14, depth 1, slots 3, 9: @2F → @5D
0754C 70617468txt "path"
07A00nil
07B0F 0A 75000000 7A00 0000map leaf, size 10: @75 → @7A
085AC 76696F6C617469 6F6E73txt "violations"
09000nil
0910F 0A 85000000 9000 0000map leaf, size 10: @85 → @90
09B5C 6669656C64txt "field"
0A100nil
0A20F 0A 9B000000 A100 0000map leaf, size 10: @9B → @A1
0AC07 0E 00090000 9100 0000 A2000000map branch, size 14, depth 2, slots 8, 11: @91 → @A2
0BA07 0A 02000000 AC00 0000map branch, size 10, depth 1, slots 1: @AC
0C44C 636F6465txt "code"
0C9CC 696E76616C6964 5F64757374txt "invalid_dust"
0D60F 0A C4000000 C900 0000map leaf, size 10: @C4 → @C9
0E06C 6F6666736574txt "offset"
0E702 02000000000000 00i64 2
0F00F 0A E0000000 E700 0000map leaf, size 10: @E0 → @E7
0FA07 1E 51620000 1D00 0000 67000000 7B00 0000 BA000000 D600 0000 F0000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @1D → @67 → @7B → @BA → @D6 → @F0

C exports: stardust_parse, stardust_document_error

Document.Root

go37 B
func (d *Document) Root() (ID, error)

Errors

StatusWhen
StatusClosedthe document is closed

Examples

document/root

inputText 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
go166 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

result, err := source.Root()
if err != nil {
	return err
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 00000000000000 00i64 0

C exports: stardust_document_root

Document.Count

go39 B
func (d *Document) Count() (int, error)

Errors

StatusWhen
StatusClosedthe document is closed

Examples

document/count

inputText 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
go167 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

result, err := source.Count()
if err != nil {
	return err
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 02000000000000 00i64 2

C exports: stardust_document_count

Document.Read

go48 B
func (d *Document) Read(id ID) (NodeView, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.

Errors

StatusWhen
StatusInvalidArgumentid is not a node of the document
StatusClosedthe document is closed

Notes

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

Examples

document/read

inputText 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
go228 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result, err := source.Read(root)
if err != nil {
	return err
}
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

Document.ReadMany

go69 B
func (d *Document) ReadMany(start ID, output []NodeView) (int, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
startIDValueRequiredThe first node ID of the consecutive read.
output[]NodeViewValueRequiredThe maximum number of node views to read. For output slices, the call uses the caller's slice length.

Errors

StatusWhen
StatusInvalidArgumentstart is past the last node or capacity is negative
StatusClosedthe document is closed

Examples

document/read_many

inputText 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
go321 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

views := make([]stardust.NodeView, 1)
written, err := source.ReadMany(root, views)
if err != nil {
	return err
}
views = views[:written]
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

Document.Member

go56 B
func (d *Document) Member(id ID, key string) (ID, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.
keystringValueRequiredThe object member name to find.

Errors

StatusWhen
StatusNotFoundthe object has no member with the key
StatusInvalidArgumentid is not an object node of the document
StatusClosedthe document is closed

Examples

document/member

inputText 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
go235 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result, err := source.Member(root, "x")
if err != nil {
	return err
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 01000000000000 00i64 1

C exports: stardust_document_member

Document.Pointer

go62 B
func (d *Document) Pointer(id ID, path Path) (ID, bool, error)
go68 B
func (d *Document) PointerText(id ID, text string) (ID, bool, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.
pathPathValueRequiredThe stored definition path.
textstringValueRequiredThe JSON Pointer text, such as /items/0/name.

Errors

StatusWhen
StatusInvalidPointerthe text is not a JSON Pointer or the array is not a canonical path array
StatusInvalidArgumentid is not a node of the document
StatusClosedthe document is closed
StatusOutOfMemorynative memory is exhausted
StatusInvalidArgumenta path token is neither a string nor an int or int64

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

expressionText 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]
go319 B
source, err := stardust.Parse(expressionText, stardust.DUST)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result, found, err := source.Pointer(root, stardust.Path{"inputs", 1, "x"})
if err != nil {
	return err
}
if !found {
	return stardust.ErrNotFound
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 09000000000000 00i64 9

C exports: stardust_document_pointer, stardust_document_pointer_text, stardust_document_builder_create, stardust_document_builder_add_many, stardust_document_builder_seal, stardust_document_builder_release, stardust_document_release

pointer.Parse

go46 B
func Parse(text string) (stardust.Path, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
textstringValueRequiredEncoded input bytes in the selected format. TRON is binary.

Errors

StatusWhen
StatusInvalidPointerthe text is not empty and does not start with /, or holds ~ not followed by 0 or 1
StatusOutOfMemorynative memory is exhausted

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

go73 B
result, err := pointer.Parse("/inputs/1/x")
if err != nil {
	return err
}
TRON51 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 696E70757473txt "inputs"
0B02 01000000000000 00i64 1
141C 78txt "x"
160E 15 00 0700 030000 00 04000000 0B0000 00 14000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @B → @14

C exports: stardust_pointer_parse, stardust_document_error, stardust_document_read_many, stardust_document_i64, stardust_document_release

pointer.Format

go47 B
func Format(path stardust.Path) (string, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
pathstardust.PathValueRequiredThe database file path.

Errors

StatusWhen
StatusInvalidPointera token is a negative or non-integral number, an index-shaped string such as "0", or neither a number nor a string
StatusOutOfMemorynative memory is exhausted
StatusInvalidArgumenta path token is neither a string nor an int or int64

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

go92 B
result, err := pointer.Format(stardust.Path{"inputs", 1, "x"})
if err != nil {
	return err
}
TRON39 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 74657874txt "text"
09BC 2F696E70757473 2F312F78txt "/inputs/1/x"
150F 0A 04000000 0900 0000map leaf, size 10: @4 → @9

C exports: stardust_pointer_format, 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

Document.Children

go61 B
func (d *Document) Children(id ID) iter.Seq2[NodeView, error]

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.

Errors

StatusWhen
StatusInvalidArgumentid is not a node of the document
StatusClosedthe 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

document/children

seedText 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
go265 B
source, err := stardust.Parse(seedText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result := 0
for _, err := range source.Children(root) {
	if err != nil {
		return err
	}
	result++
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 04000000000000 00i64 4

C exports: stardust_document_read_many

Document.Members

go60 B
func (d *Document) Members(id ID) iter.Seq2[NodeView, error]

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.

Errors

StatusWhen
StatusInvalidArgumentid is not an object node of the document
StatusClosedthe document is closed

Notes

Duplicate keys appear in document order. Keep the document open during iteration. A read failure is reported once and ends iteration.

Examples

document/members

seedText 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
go284 B
source, err := stardust.Parse(seedText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result := ""
for view, err := range source.Members(root) {
	if err != nil {
		return err
	}
	result = view.Key
	break
}
TRON32 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 74657874txt "text"
094C 235F7478txt "#_tx"
0E0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9

C exports: stardust_document_read_many

Document.I64

go44 B
func (d *Document) I64(id ID) (int64, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.

Errors

StatusWhen
StatusInvalidArgumentthe node is not an integer number
StatusClosedthe document is closed

Examples

document/i64

inputText 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
go295 B
source, err := stardust.Parse(inputText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}
node, err := source.Member(root, "x")
if err != nil {
	return err
}

result, err := source.I64(node)
if err != nil {
	return err
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 29000000000000 00i64 41

C exports: stardust_document_i64

Document.F64

go46 B
func (d *Document) F64(id ID) (float64, error)

Parameters

ParameterTypeOwnershipDefaultMeaning
idIDValueRequiredA node ID within the receiver document.

Errors

StatusWhen
StatusInvalidArgumentthe node is not a number or its value overflows f64
StatusClosedthe document is closed

Notes

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

Examples

document/f64

floatText holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1
go227 B
source, err := stardust.Parse(floatText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

root, err := source.Root()
if err != nil {
	return err
}

result, err := source.F64(root)
if err != nil {
	return err
}
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 000000000000F0 3Ff64 1

C exports: stardust_document_f64

Document.Close

go26 B
func (d *Document) Close()

Consumes the receiver handle.

Examples

document/close

expressionText 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
go208 B
source, err := stardust.Parse(expressionText, stardust.TRON)
if err != nil {
	return err
}
defer source.Close()

result, err := source.Serialize(stardust.TRON, 0)
if err != nil {
	return err
}

source.Close()
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
kindKindNone——
booleanboolNone—True only for true.
parentIDNoneNoNode—
positionint64Count—Index within the parent container.
first_childIDNoneNoNode—
next_siblingIDNoneNoNode—
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
parentIDNoNode—
kindKind——
booleanbool—Value of a boolean node.
numberNumericnilValue of a number node.
keystring—Member key when the parent is an object.
textstring—Value of a string node.