c0
C0DATA — structured data using ASCII C0 control codes (C)
Loading...
Searching...
No Matches
c0_builder Struct Reference

Writes C0DATA in canonical compact form into a growable buffer it owns; call c0_builder_free when done. More...

#include <c0.h>

Data Fields

uint8_t * data
size_t len
size_t cap
c0_status status
int state
 internal: top / heading / record
size_t units
 internal: units written in the open record
int * stack
 internal: saved state per open level
size_t depth
 internal: open levels
size_t stack_cap
 internal

Detailed Description

Writes C0DATA in canonical compact form into a growable buffer it owns; call c0_builder_free when done.

Once status is set, further writes are no-ops; check it before using the bytes. Values are byte-transparent and written in their one spelling: plain when they can be, text otherwise with only the seven codes escaped. Names (file, group, header, key, reference, ETB payload) must be plain, or C0_ERR_BAD_NAME is set.

Two layers. The primitives, c0_builder_<code>, are one function per code (fs gs rs us sub soh dle can bel enq syn eot etb em); each writes its code and, when given, what grammatically follows it, so a sequence of calls reads like the bytes:

c0_builder_rs_str(&b, "Alice"); c0_builder_us_str(&b, "1502.30"); ␞Alice␟1502.30 c0_builder_rs(&b); c0_builder_soh_str(&b, "host"); c0_builder_us_str(&b, "localhost"); c0_builder_bel(&b); c0_builder_gs_str(&b, "old"); a dead group c0_builder_sub(&b); c0_builder_gs_str(&b, "s"); ␚␝s: a subsection (depth 2) c0_builder_rs_str(&b, "old"); c0_builder_sub(&b); c0_builder_us_str(&b, "new"); ␞old␚␟new: a sub-unit

The composed functions, c0_build_<what> (file, group, section, header, record, field, sub_unit, map, key, level, list, ref, note), are built on the primitives and cannot write ill-formed output. The primitives write what you spell; well-formedness is then yours to keep. Both layers share the record state, so they mix.

A record is opened by c0_build_record or c0_builder_rs (or implicitly by the first c0_build_field / c0_build_key / c0_build_level_open / c0_build_list / c0_build_ref) and ended by the next structural call. Keyed units written right after c0_build_syn belong to the heading, not to a record.

Field Documentation

◆ cap

size_t c0_builder::cap

◆ data

uint8_t* c0_builder::data

◆ depth

size_t c0_builder::depth

internal: open levels

◆ len

size_t c0_builder::len

◆ stack

int* c0_builder::stack

internal: saved state per open level

◆ stack_cap

size_t c0_builder::stack_cap

internal

◆ state

int c0_builder::state

internal: top / heading / record

◆ status

c0_status c0_builder::status

◆ units

size_t c0_builder::units

internal: units written in the open record


The documentation for this struct was generated from the following file: