code wiki / (root) / nx_h2_frame.nx

nx_h2_frame.nx

buildroot/runtime/nx_h2_frame.nx

31682 B583 linesdepth 5pulls 7 transitivereach 18 importersview sourcekind tooltopic h2
docsdependenciesstructsconstsfunctions

about

nx_h2_frame.nx -- TUTOR-BOOTSTRAP SCAFFOLD (Claude, authored under the R4-H2 HTTP/2-transport-ladder workflow), NOT credited as team self-authoring. R4-H2-003 of the sovereign HTTP/2 transport ladder (knowledge/specs/2026-06-13-http2-transport-ladder.md). The HTTP/2 frame codec (RFC 9113 §3.4 / §4.1 / §6). The WIRE FORMAT -- the 9-octet generic frame header (Length 24-bit BE, Type 8, Flags 8, R 1 + Stream-ID 31 BE), the 24-octet connection preface, and the per-frame payload layouts of SETTINGS, HEADERS, DATA, RST_STREAM, PING, GOAWAY, WINDOW_UPDATE -- is an allowed internet-boundary requirement: the bytes are dictated by RFC 9113 byte-for- byte so we interoperate, exactly as nx_tls13_ext.nx emits RFC 8446 extension bytes and nx_hpack.nx emits RFC 7541 header blocks. The IMPLEMENTATION is pure NishiLang via nx_cc -> nxasm_x86: no gcc, no openssl, no nghttp2. FOUNDED ON (composes, does not reinvent -- anti-orphan law): - nx_hpack.nx (R4-H2-002, GREEN): the HEADERS frame wraps an HPACK block built by hpack_encode_indexed / hpack_encode_lit_inc_indexed_name; it transitively splices nx_str.nx -> syscalls.nx -> nx_syscalls.nx, so we inherit sys_mmap / sys_write / sys_exit from ONE import (importing nx_str / nx_syscalls directly TOO would be the RC6 double-import landmine). - nx_tls13.nx (no imports; pure byte helpers): we reuse tls_write_u16_be / tls_read_u16_be (nx_tls13.nx:201/205) for the SETTINGS Identifier(16) AND tls_write_u24_be / tls_read_u24_be (nx_tls13.nx:188/192) for the 24-bit frame Length -- the exact same big-endian helpers the TLS handshake-message headers use, NOT reinvented here (Rule-15 DRY). Only the u31/u32 BE pair (which has no TLS counterpart) is added locally. nx_tls13 imports nothing, so importing it alongside nx_hpack does NOT double-import syscalls. No floating capability: HPACK founds this frame codec; the stream state machine (R4-H2-004) founds on this next. BACK-FILL: the team RE-AUTHORS this from the DATA spec via the emitter-of-emitters (X-AUT-006c/e/f) -- this hand-authored scaffold is the sanctioned one-time bootstrap only (meter-integrity, mirror nx_frame_codec.nx:13-16 / nx_hpack.nx:28-31). GATE (main): asserts byte-exact the RFC 9113 known-answers -- the 24-byte connection preface (§3.4), the empty client SETTINGS frame (00 00 00 04 00 00 00 00 00), SETTINGS ACK, a SETTINGS frame carrying INITIAL_WINDOW_SIZE=65535, a HEADERS frame on stream 1 (flags END_STREAM|END_HEADERS = 0x05) wrapping the C.3.1-style HPACK block, plus WINDOW_UPDATE / RST_STREAM / PING / GOAWAY /

dependencies 3 imports · 2 importers

nx_hpack.nx nx_itoa_lib.nx nx_tls13.nx nx_h2_frame.nx nx_h2_flow.nx nx_h2_stream.nx

imports: nx_hpack.nxnx_itoa_lib.nxnx_tls13.nx

imported by: nx_h2_flow.nxnx_h2_stream.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main h2_puts h2_write_preface h2_check_bytes h2_puts ↻ h2_putn nxi_out nxi_fd sys_mmap ccz_cat_num sys_write sys_munmap h2_puthex2 h2_check_preface h2_write_preface ↻ h2_putn ↻ h2_frame_write_settings_em h2_frame_write_header tls_write_u24_be h2_write_u32_be h2_frame_write_settings_ac h2_frame_write_header ↻ h2_frame_write_settings_pa h2_frame_write_header ↻ tls_write_u16_be h2_write_u32_be ↻ nx_str_cpy hpack_encode_indexed hpack_encode_int hpack_encode_lit_inc_index hpack_encode_int ↻ hpack_encode_str_raw hpack_encode_int ↻ h2_frame_write_headers h2_frame_write_header ↻ h2_frame_write_window_upda h2_frame_write_header ↻ h2_write_u32_be ↻ h2_frame_write_rst_stream h2_frame_write_header ↻

structs

none

consts

54const K_MAGIC_65535: i64 = 65535

functions

57func h2_puts(s: *u8) -> i64
called by 2: h2_check_bytesmain
67func h2_putn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: h2_check_bytesmain calls 1: nxi_out
68func h2_puthex2(v: i64) -> i64
called by 1: h2_check_bytes
83func h2_fdn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
92func h2_write_u32_be(buf: *u8, off: i64, v: i64) -> i64
99func h2_read_u32_be(buf: *u8, off: i64) -> i64
109func h2_frame_write_header(out: *u8, off: i64, length: i64, ftype: i64, flags: i64, stream_id: i64) -> i64
126func h2_frame_read_header(buf: *u8, off: i64, lim: i64, out_len: *i64, out_type: *i64, out_flags: *i64, out_sid: *i64) -> i64
146func h2_write_preface(out: *u8, off: i64) -> i64
176func h2_check_preface(buf: *u8, off: i64, lim: i64) -> i64
192func h2_frame_write_settings_empty(out: *u8, off: i64) -> i64
195func h2_frame_write_settings_ack(out: *u8, off: i64) -> i64
200func h2_frame_write_settings_param(out: *u8, off: i64, ident: i64, value: i64) -> i64
208func h2_settings_payload_valid(len: i64) -> i64
called by 1: main
219func h2_frame_write_headers(out: *u8, off: i64, stream_id: i64, flags: i64, block: *u8, blen: i64) -> i64
232func h2_frame_write_data(out: *u8, off: i64, stream_id: i64, flags: i64, data: *u8, dlen: i64) -> i64
246func h2_frame_write_rst_stream(out: *u8, off: i64, stream_id: i64, error_code: i64) -> i64
254func h2_frame_write_rst_stream_checked(out: *u8, off: i64, stream_id: i64, error_code: i64, declared_len: i64) -> i64
called by 1: main calls 1: h2_frame_write_rst_stream
263func h2_frame_write_ping(out: *u8, off: i64, flags: i64, opaque8: *u8) -> i64
called by 1: main calls 1: h2_frame_write_header
275func h2_frame_write_goaway(out: *u8, off: i64, last_stream_id: i64, error_code: i64, debug: *u8, dlen: i64) -> i64
291func h2_frame_write_window_update(out: *u8, off: i64, stream_id: i64, increment: i64) -> i64
301func h2_check_bytes(name: *u8, got: *u8, glen: i64, exp: *u8, elen: i64) -> i64
called by 1: main calls 3: h2_putsh2_putnh2_puthex2
324func main() -> i64