These operations construct a document one node at a time.
For most operations, parse a document in your selected format.
Use these operations only when you cannot parse the document from text.
Create a builder.
Add the nodes in preorder.
Seal the builder to create an owned document.
python 53 B
def builder (* , library : str | None = None ) -> Builder
Add nodes in depth-first preorder. An append failure makes the builder unusable.
python 257 B
async with (await stardust .builder ()) as builder :
object_node = (await builder .add (stardust .NodeInput (kind = "object" )))
(await builder .add (stardust .NodeInput (parent = object_node , kind = "number" , key = "x" , number = 41 )))
result = (await builder .seal ())
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
C exports: stardust_document_builder_create
python 37 B
def add (self , node : NodeInput ) -> int
Requires exclusive use of the receiver handle.
The root has no parent. Each later parent must be an open container or one of its ancestors.
python 257 B
async with (await stardust .builder ()) as builder :
object_node = (await builder .add (stardust .NodeInput (kind = "object" )))
(await builder .add (stardust .NodeInput (parent = object_node , kind = "number" , key = "x" , number = 41 )))
result = (await builder .seal ())
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
python 148 B
input = stardust .NodeInput (kind = "number" , number = 41 )
async with (await stardust .builder ()) as builder :
(await builder .add (input ))
result = input
TRON158 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 3C 6B6579 txt "key" 08 0C txt "" 09 0F 0A 04000000 0800
0000 map leaf, size 10: @4 → @8 13 4C 6B696E64 txt "kind" 18 6C 6E756D626572 txt "number" 1F 0F 0A 13000000 1800
0000 map leaf, size 10: @13 → @18 29 6C 6E756D626572 txt "number" 30 02 29000000000000
00 i64 41 39 0F 0A 29000000 3000
0000 map leaf, size 10: @29 → @30 43 6C 706172656E74 txt "parent" 4A 00 nil 4B 0F 0A 43000000 4A00
0000 map leaf, size 10: @43 → @4A 55 4C 74657874 txt "text" 5A 0C txt "" 5B 0F 0A 55000000 5A00
0000 map leaf, size 10: @55 → @5A 65 7C 626F6F6C65616E txt "boolean" 6D 01 bit false 6E 0F 0A 65000000 6D00
0000 map leaf, size 10: @65 → @6D 78 07 1E A1190000 0900
0000 1F000000 3900
0000 4B000000 5B00
0000 6E000000 map branch, size 30, depth 0 (root), slots 0, 5, 7, 8, 11, 12: @9 → @1F → @39 → @4B → @5B → @6E
C exports: stardust_document_builder_add_many , stardust_document_builder_error
python 33 B
def add_many (self , nodes ) -> None
Requires exclusive use of the receiver handle.
python 239 B
async with (await stardust .builder ()) as builder :
(await builder .add_many ([
stardust .NodeInput (kind = "object" ),
stardust .NodeInput (parent = 0 , kind = "number" , key = "x" , number = 41 ),
]))
result = (await builder .seal ())
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
C exports: stardust_document_builder_add_many , stardust_document_builder_error
python 26 B
def seal (self ) -> Document
Requires exclusive use of the receiver handle.
The builder accepts no more nodes after sealing.
python 257 B
async with (await stardust .builder ()) as builder :
object_node = (await builder .add (stardust .NodeInput (kind = "object" )))
(await builder .add (stardust .NodeInput (parent = object_node , kind = "number" , key = "x" , number = 41 )))
result = (await builder .seal ())
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
C exports: stardust_document_builder_seal , stardust_document_builder_error
python 23 B
def close (self ) -> None
Consumes the receiver handle.
input_text holds this document:
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
python 112 B
builder = (await stardust .builder ())
(await builder .close ())
result = (await stardust .parse (input_text , "tron" ))
TRON33 B
Offset (hex) Bytes (hex) Meaning 00 54 52 4F 4E magic TRON 04 1C 78 txt "x" 06 02 29000000000000
00 i64 41 0F 0F 0A 04000000 0600
0000 map leaf, size 10: @4 → @6
C exports: stardust_document_builder_release