code wiki / _hdl_build / nx_dataset_export.nx
nx_dataset_export.nx
buildroot/runtime/_hdl_build/nx_dataset_export.nx
about
nx_dataset_export.nx -- IMS Thrust D R2: BYTE-FAITHFUL multi-format dataset export.
ONE source dataset -> THREE serializations (CSV / JSON / TSV) that are ROUND-TRIPPABLE: parse any of
the three back and you recover the IDENTICAL records (same headers, same cells, byte-exact). This is
the "dataset in lots of formats to download" half of the arc -- the data a chart visualises, offered
for download in the format the consumer wants, with no lossy drift between them.
REUSE-vs-NEW: the UXF family (nx_uxf_tsv_migrate / nx_canon_cid) models "one source -> ONE content-
addressed CID for dedup/round-trip-to-CID" -- a DIFFERENT goal (it does not emit human-readable CSV/
JSON/TSV text files a browser can download). The CSV escaping RULES here follow RFC 4180 exactly as
nx_chem_report_csv established (quote a field with , " CR LF; double internal "); the JSON string
escaping follows RFC 8259 as json_emit established. We implement the 3 generic emitters + 3 parsers
directly over a tiny generic ROW MODEL (no per-schema code) -- the gap those organs do not fill.
ROW MODEL (NxDataset): nrows records, each with ncols string fields, in flat parallel arrays
hdr_ptr[c]/hdr_len[c] -- the c-th column header
cell_ptr[r*ncols+c]/cell_len[..] -- the field at (row r, col c)
Fields are arbitrary bytes (may contain commas, quotes, tabs, newlines). PURE: no I/O here; the
caller owns buffers (sys_mmap scratch only). license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_figure_gate.nxnx_figures_page.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 35 | struct NxDataset |
consts
| 21 | const DX_MAGIC_4096: i64 = 4096 |
| 22 | const DX_MAGIC_1024: i64 = 1024 |
| 25 | const DX_OK: i64 = 0 |
| 26 | const DX_BAD_INPUT: i64 = 2910 |
| 27 | const DX_OVERFLOW: i64 = 2911 |
| 28 | const DX_PARSE: i64 = 2912 |
| 30 | const DX_MAXCOLS: i64 = 32 |
| 31 | const DX_MAXROWS: i64 = 256 |
| 32 | const DX_MAXCELLS: i64 = 8192 // DX_MAXROWS * DX_MAXCOLS ceiling guard |
functions
| 46 | func dx_alloc(ds: *NxDataset, ncols: i64, nrows: i64) -> i64 |
| 62 | func dx_set_hdr(ds: *NxDataset, c: i64, s: *u8) -> i64 |
| 74 | func dx_set_cell(ds: *NxDataset, r: i64, c: i64, p: *u8, len: i64) -> i64 |
| 87 | func dx_set_cell_z(ds: *NxDataset, r: i64, c: i64, s: *u8) -> i64 |
| 93 | func dx_cell_ptr(ds: *NxDataset, r: i64, c: i64) -> *u8 { return ds.cell_ptr[r * ds.ncols + c] as *u8 } |
| 94 | func dx_cell_len(ds: *NxDataset, r: i64, c: i64) -> i64 { return ds.cell_len[r * ds.ncols + c] } |
| 99 | func dx_bytes_eq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 called by 1: dx_equal |
| 110 | func dx_equal(a: *NxDataset, b: *NxDataset) -> i64 |
| 136 | func dx_field_needs_quote(p: *u8, n: i64) -> i64 called by 1: dx_emit_csv_field |
| 150 | func dx_emit_csv_field(out: *u8, off: i64, cap: i64, p: *u8, n: i64) -> i64 |
| 183 | func dx_emit_csv(ds: *NxDataset, out: *u8, cap: i64) -> i64 |
| 221 | func dx_parse_csv(src: *u8, n: i64, ds: *NxDataset) -> i64 |
| 328 | func dx_emit_tsv(ds: *NxDataset, out: *u8, cap: i64) -> i64 |
| 363 | func dx_parse_tsv(src: *u8, n: i64, ds: *NxDataset) -> i64 |
| 423 | func dx_emit_json_str(out: *u8, off: i64, cap: i64, p: *u8, n: i64) -> i64 called by 1: dx_emit_json |
| 457 | func dx_emit_json(ds: *NxDataset, out: *u8, cap: i64) -> i64 |
| 493 | func dx_json_unescape_string(src: *u8, n: i64, i_io: *i64, outbuf: *u8) -> i64 called by 1: dx_parse_json |
| 539 | func dx_parse_json(src: *u8, n: i64, ds: *NxDataset) -> i64 |
| 620 | func main() -> i64 |