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.
c 78 B
uint32_t stardust_document_builder_create (stardust_document_builder ** output );
Add nodes in depth-first preorder. An append failure makes the builder unusable.
c 692 B
stardust_document_builder * builder = NULL ;
stardust_document * result = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
stardust_node_input nodes [] = {
{. parent = STARDUST_DOCUMENT_NO_NODE , . kind = STARDUST_OBJECT },
{. parent = 0 , . kind = STARDUST_NUMBER , . key = {(const uint8_t * )"x" , 1 },
. number = STARDUST_NUMBER_INTEGER , . integer = 41 },
};
if (status == STARDUST_OK )
status = stardust_document_builder_add_many (builder , nodes , 2 );
if (status == STARDUST_OK )
status = stardust_document_builder_seal (builder , & result );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) {
stardust_document_release (result );
return status ;
}
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
Call stardust_document_builder_add_many with one node.
c 452 B
stardust_node_input input = {. parent = STARDUST_DOCUMENT_NO_NODE , . kind = STARDUST_NUMBER , . number = STARDUST_NUMBER_INTEGER , . integer = 41 };
stardust_document_builder * builder = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
if (status == STARDUST_OK ) status = stardust_document_builder_add_many (builder , & input , 1 );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) return status ;
stardust_node_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
Also calls: stardust_document_builder_add_many , stardust_document_builder_error
c 129 B
uint32_t stardust_document_builder_add_many (stardust_document_builder * builder , const stardust_node_input * nodes , int64_t count );
c 117 B
uint32_t stardust_document_builder_error (const stardust_document_builder * builder , stardust_diagnostic_view * output );
Requires exclusive use of the receiver handle.
c 692 B
stardust_document_builder * builder = NULL ;
stardust_document * result = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
stardust_node_input nodes [] = {
{. parent = STARDUST_DOCUMENT_NO_NODE , . kind = STARDUST_OBJECT },
{. parent = 0 , . kind = STARDUST_NUMBER , . key = {(const uint8_t * )"x" , 1 },
. number = STARDUST_NUMBER_INTEGER , . integer = 41 },
};
if (status == STARDUST_OK )
status = stardust_document_builder_add_many (builder , nodes , 2 );
if (status == STARDUST_OK )
status = stardust_document_builder_seal (builder , & result );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) {
stardust_document_release (result );
return status ;
}
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 692 B
stardust_document_builder * builder = NULL ;
stardust_document * result = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
stardust_node_input nodes [] = {
{. parent = STARDUST_DOCUMENT_NO_NODE , . kind = STARDUST_OBJECT },
{. parent = 0 , . kind = STARDUST_NUMBER , . key = {(const uint8_t * )"x" , 1 },
. number = STARDUST_NUMBER_INTEGER , . integer = 41 },
};
if (status == STARDUST_OK )
status = stardust_document_builder_add_many (builder , nodes , 2 );
if (status == STARDUST_OK )
status = stardust_document_builder_seal (builder , & result );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) {
stardust_document_release (result );
return status ;
}
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
Also calls: stardust_document_builder_error
c 104 B
uint32_t stardust_document_builder_seal (stardust_document_builder * builder , stardust_document ** output );
c 117 B
uint32_t stardust_document_builder_error (const stardust_document_builder * builder , stardust_diagnostic_view * output );
Requires exclusive use of the receiver handle.
The builder accepts no more nodes after sealing.
c 692 B
stardust_document_builder * builder = NULL ;
stardust_document * result = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
stardust_node_input nodes [] = {
{. parent = STARDUST_DOCUMENT_NO_NODE , . kind = STARDUST_OBJECT },
{. parent = 0 , . kind = STARDUST_NUMBER , . key = {(const uint8_t * )"x" , 1 },
. number = STARDUST_NUMBER_INTEGER , . integer = 41 },
};
if (status == STARDUST_OK )
status = stardust_document_builder_add_many (builder , nodes , 2 );
if (status == STARDUST_OK )
status = stardust_document_builder_seal (builder , & result );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) {
stardust_document_release (result );
return status ;
}
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
Also calls: stardust_document_builder_error
c 75 B
void stardust_document_builder_release (stardust_document_builder * builder );
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
c 364 B
stardust_document_builder * builder = NULL ;
uint32_t status = stardust_document_builder_create (& builder );
stardust_document_builder_release (builder );
if (status != STARDUST_OK ) return status ;
stardust_document * result = NULL ;
status = stardust_parse (input_text , STARDUST_TRON , & result );
if (status != STARDUST_OK ) {stardust_document_release (result ); return status ; }
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