Skip to main content

Module record

Module record 

Source
Expand description

Structured records - the typed Table that flows through GodspeedOS pipes.

POSIX pipes carry text, so structured data is flattened to a string and grep/awk/cut re-parse it back. GodspeedOS keeps the structure: a producer emits a Table (typed columns + rows); filters operate on real fields (where mem>0), and JSON/YAML/the grid are renderings of the model, not the model itself. This module is that model, lifted into the SDK so any service - not just the shell - can build records, filter them, and render them to JSON/YAML. See docs/records.md.

§Building a pipe-friendly service

A service participates in a record pipe today without any new kernel surface: build a Table, render it with Table::to_json, and emit the bytes (EOT-terminated) like any byte producer (docs/pipes.md). The shell’s | from json lifts it back to records:

ⓘ
let mut t = Table::new(&["name", "n"]);
let n = t.intern(b"alpha");
t.add_row(&[n, Value::Int(1)]);
let mut buf = MyBuf::new();        // any RecordSink (e.g. wrapping an IPC message)
t.to_json(&mut buf);              // → `[ {"name": "alpha", "n": 1} ]`

To cross a service boundary as records (skipping the JSON round-trip), use the bounded binary wire codec instead: Table::encode on the producer, Table::decode on the consumer. It is the Table itself on the wire - compact and typed, not JSON. examples/roster produces records this way; the shell decodes them straight into a Table.

§Bounds (§26.6)

Everything is fixed-size and stack-resident - no heap, loud on overflow: at most REC_MAX_COLS columns, REC_MAX_ROWS rows, a REC_ARENA-byte string arena, and REC_COL_NAME-byte column names. Overflowing any bound sets Table::overflow. One input is ignored WITHOUT setting it: values past the column count in an add_row call.

Structs§

Table
A bounded table of typed rows - the canonical structured-pipe value. Owned column names (so a from_json parse can name columns dynamically), rows of Value, and a byte arena holding the Str cells. All inline, no heap.

Enums§

AggErr
Why an aggregate failed - each maps to a loud shell notice, never a silent 0.
AggOp
A numeric-column reducer (the sum/min/max/avg pipe aggregators, docs/scripting.md §5).
Value
A typed cell. Str points into the owning Table’s arena (no lifetimes, no heap).

Constants§

REC_ARENA
Backing store (bytes) for interned Str cell values.
REC_COL_NAME
Maximum column-name length (bytes).
REC_MAX_COLS
Maximum columns in a table.
REC_MAX_ROWS
Maximum rows in a table.
REC_WIRE_MAGIC
Magic prefix of the binary wire encoding (Table::encode/decode). Lets a decoder reject a non-record byte stream loudly instead of misparsing it.

Traits§

RecordSink
A sink the renderers write bytes into - the caller’s bridge to a console, a capture buffer, or an IPC message. Implement it for whatever the bytes should go to.

Functions§

parse_predicate
Parse a compact predicate token col<op>val (e.g. mem>0, state=BlockRecv, name!=x). The operator is the longest match (!=/>=/<=/== before =/>/</~); before it is the column, after it the value. None if no operator is present.