tsv.nx
buildroot/runtime/tsv.nx
about
tsv.nx -- Tab-separated values reader + writer.
The "database format" for sovereign apps that don't yet have a
SQLite binding (per ROADMAP P8). Append-only files, one per
entity (people.tsv, obligations.tsv, interactions.tsv). Reads
are linear scans; writes are fwrite-append at end.
Format (RFC 4180 TSV variant, simpler than CSV):
- Fields separated by TAB (0x09)
- Rows separated by LF (0x0A)
- No field-level quoting -- TAB and LF inside fields escaped
via \t and \n (our convention; not RFC 4180)
- Leading #-comment rows skipped by the reader
Not designed for megabyte-scale; linear scans are O(n). Fine
at the ~1k-record scale that CLAUDE.md rule #1 (Schema First)
implies for a CRM/ops app's first iteration.
Invariants:
TSV1 Round-trip exact for any row whose fields don't contain
raw TAB or LF. Fields with TAB/LF are lossy unless
caller pre-escapes via tsv_escape_field.
TSV2 Comment rows (# at start-of-line) never contribute
fields to row callbacks.
TSV3 Trailing newline on the file is tolerated; absence is
also fine.
TSV4 Reader is streaming: processes byte-by-byte without
buffering whole rows. Safe on arbitrarily-long files.
dependencies 2 imports · 0 importers
imports: syscalls.nxfs.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 51 | func tsv_scan_field(buf: *u8, len: i64, pos: *i64,
called by 1: main |
| 80 | func tsv_skip_comment(buf: *u8, len: i64, pos: i64) -> i64 { |
| 96 | func tsv_write_field(out: *u8, pos: *i64, cap: i64,
called by 1: main |
| 118 | func tsv_end_row(out: *u8, pos: *i64, cap: i64) -> i64 {
called by 1: main |
| 131 | func tsv_escape_field(in_bytes: *u8, n: i64, |
| 164 | func tsv_unescape_field(in_bytes: *u8, n: i64, |
| 204 | func main() -> i64 { |