nx_h2_frame.nx
buildroot/runtime/nx_h2_frame.nx
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
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
structs
| none |
consts
| 54 | const K_MAGIC_65535: i64 = 65535 |
functions
| 57 | func h2_puts(s: *u8) -> i64 |
| 67 | func h2_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 68 | func h2_puthex2(v: i64) -> i64 called by 1: h2_check_bytes |
| 83 | func h2_fdn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 92 | func h2_write_u32_be(buf: *u8, off: i64, v: i64) -> i64 |
| 99 | func h2_read_u32_be(buf: *u8, off: i64) -> i64 called by 1: h2_frame_read_header |
| 109 | func h2_frame_write_header(out: *u8, off: i64, length: i64, ftype: i64, flags: i64, stream_id: i64) -> i64 |
| 126 | func h2_frame_read_header(buf: *u8, off: i64, lim: i64, out_len: *i64, out_type: *i64, out_flags: *i64, out_sid: *i64) -> i64 |
| 146 | func h2_write_preface(out: *u8, off: i64) -> i64 |
| 176 | func h2_check_preface(buf: *u8, off: i64, lim: i64) -> i64 called by 5: mainmainh2_serve_connectionh2_serve_connection_multih2_server_recv_request calls 1: h2_write_preface |
| 192 | func h2_frame_write_settings_empty(out: *u8, off: i64) -> i64 |
| 195 | func h2_frame_write_settings_ack(out: *u8, off: i64) -> i64 called by 8: h2_tls_geth2_tls_drainhc_synth_responsemainmainh2_serve_connection+2 calls 1: h2_frame_write_header |
| 200 | func h2_frame_write_settings_param(out: *u8, off: i64, ident: i64, value: i64) -> i64 called by 4: mainmainmainh2_serve_connection_multi calls 3: h2_frame_write_headertls_write_u16_beh2_write_u32_be |
| 208 | func h2_settings_payload_valid(len: i64) -> i64 called by 1: main |
| 219 | func h2_frame_write_headers(out: *u8, off: i64, stream_id: i64, flags: i64, block: *u8, blen: i64) -> i64 called by 9: hc_synth_responsemainh2_build_client_openh2_build_client_open_uamainmain+3 calls 1: h2_frame_write_header |
| 232 | func h2_frame_write_data(out: *u8, off: i64, stream_id: i64, flags: i64, data: *u8, dlen: i64) -> i64 called by 7: hc_synth_responsemainmainmainh2_serve_connectionmsrv_respond_stream+1 calls 1: h2_frame_write_header |
| 246 | func h2_frame_write_rst_stream(out: *u8, off: i64, stream_id: i64, error_code: i64) -> i64 |
| 254 | func h2_frame_write_rst_stream_checked(out: *u8, off: i64, stream_id: i64, error_code: i64, declared_len: i64) -> i64 |
| 263 | func h2_frame_write_ping(out: *u8, off: i64, flags: i64, opaque8: *u8) -> i64 |
| 275 | func h2_frame_write_goaway(out: *u8, off: i64, last_stream_id: i64, error_code: i64, debug: *u8, dlen: i64) -> i64 called by 3: mainh2_serve_connectionh2_serve_connection_multi calls 2: h2_frame_write_headerh2_write_u32_be |
| 291 | func h2_frame_write_window_update(out: *u8, off: i64, stream_id: i64, increment: i64) -> i64 called by 4: h2_tls_geth2_tls_drainh2_flow_write_window_updatemain calls 2: h2_frame_write_headerh2_write_u32_be |
| 301 | func h2_check_bytes(name: *u8, got: *u8, glen: i64, exp: *u8, elen: i64) -> i64 |
| 324 | func main() -> i64 |