nx_safetensors.nx
buildroot/runtime/nx_safetensors.nx
about
nx_safetensors.nx -- SOVEREIGN safetensors parser (the neural-weights loader foundation). safetensors is the
modern HuggingFace weight format (HiFi-GAN / VITS vocoders, image models, etc. are hosted in it): 8-byte LE
header-length, then a JSON header {name:{dtype,shape,data_offsets:[s,e]}, ...}, then the raw tensor bytes. This
parses the header (bounded per-tensor brace scan so a tensor's keys don't leak into the next) and returns each
tensor's dtype/shape/byte-range -> a pointer into the data section. Paired with nx_https_get_stream (streaming
download) this is the sovereign path to ACQUIRE + LOAD a neural model ourselves -- no operator-must-download,
the real unblock for human-realistic neural voice (and neural image). Self-test builds a synthetic safetensors
in memory + parses it back (metadata + f32 values byte-exact). No JSON lib, no ML dep. license_tier: ORIGINAL expect_exit: 0
dependencies 1 imports · 0 importers
imports: nx_syscalls.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
| 10 | const K_MAGIC_65536: i64 = 65536 |
functions
| 12 | func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 13 | func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } |
| 14 | func shx(v: i64) -> i64 { let b: *u8=sys_mmap(8); var i: i64=0; while i<8 { let n: i64=(v>>((7-i)*4))&0xF; if n<10 {b[i]=(48+n) as u8} else {b[i]=(87+n) as u8} i=i+1 } sys_write(1,b,8); return 0 } |
| 15 | func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 18 | func st_u64le(buf: *u8, off: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v = v | ((buf[off+i]&0xff) << (i*8)); i=i+1 } return v } called by 1: main |
| 19 | func st_u32le(buf: *u8, off: i64) -> i64 { return (buf[off]&0xff) | ((buf[off+1]&0xff)<<8) | ((buf[off+2]&0xff)<<16) | ((buf[off+3]&0xff)<<24) } called by 1: main |
| 22 | func st_find(hdr: *u8, start: i64, end: i64, pat: *u8) -> i64 |
| 33 | func st_match_brace(hdr: *u8, obj_start: i64, hlen: i64) -> i64 called by 1: st_tensor |
| 44 | func st_int_array(hdr: *u8, pos: i64, hlen: i64, arr: *i64) -> i64 called by 1: st_tensor |
| 57 | func st_tensor(hdr: *u8, hlen: i64, name: *u8, dtype_out: *u8, shape_out: *i64, offs_out: *i64) -> i64 |
| 86 | func put_u64le(buf: *u8, off: i64, v: i64) -> i64 { var i: i64=0; while i<8 { buf[off+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 } called by 1: main |
| 87 | func put_u32le(buf: *u8, off: i64, v: i64) -> i64 { var i: i64=0; while i<4 { buf[off+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 } called by 1: main |
| 88 | func put_str(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ buf[off+i]=s[i]; i=i+1 } return off+i } called by 1: main |
| 90 | func main() -> i64 |