e875519e
c_runtime: repeated + packed scalar encode/decode (ra6 3e)
Add repeated dispatch to the C-runtime encode/decode loop. Encode side: encode_repeated_field walks Lua arrays via lua_objlen + per- index rawgeti, dispatches on element kind. Packed numerics build their payload in a stack-backed sub-buffer then emit `tag(LEN) + varint(len) + body`; unpacked emit `tag + value` per element via encode_one_field with force_emit=1 to bypass zero-suppression; strings/bytes flow through the same path (never packable); repeated messages reuse encode_submessage_field per element. Decode side: per-field stack-slot cache (list_stack_idx[]) tied to list_count[] avoids the per-element lua_getfield(result, name) round trip the c-accel spike measured at 2x slower at 100KB. On first hit for a repeated field we lua_createtable + write result[name] AND dup- push the list onto the stack; subsequent hits lua_rawseti through the cached absolute stack index. Lists stay valid across recursive sub- message decodes because each child decode_body cleans up its own scratch back to the caller's frame. Packed/unpacked symmetry on read: a wt==LEN payload for any packable scalar is decoded as a packed blob regardless of the schema's packed flag, and a per-element-tagged stream is decoded element-by-element even on a schema that defaults to packed — per proto3 reader rules. New test/proto/c_repeated.proto fixture carries packed + explicit- unpacked + repeated string/bytes + repeated message branches. The encode and decode tests round-trip at 10/100/1000 elements per branch. The two existing "skip repeated and map" marker tests collapse to "skip map" — only map fields remain out of scope for 3e (bd-asz / 3h lands them next). 854 → 896 passing tests. bd-jc9
Eugene Blikh <bigbes@gmail.com> — 2026-05-23 10:40:25 UTC
Commit e875519ea07d2f9bb86d2a68baccefdd53f3d0f3 —
view raw patch
Parent(s):
6e7835a2
| File | Status | + | − |
|---|---|---|---|
.beads/interactions.jsonl
|
M | +1 | |
.beads/issues.jsonl
|
M | +1 | -1 |
examples/expected/full/c_repeated/c_repeated_pb.lua
|
A | +737 | |
examples/expected/runtime/c_repeated/c_repeated_pb.lua
|
A | +126 | |
runtime/pb/c/c_runtime.c
|
M | +299 | -30 |
test/c_runtime_decode_test.lua
|
M | +157 | -6 |
test/c_runtime_encode_test.lua
|
M | +186 | -7 |
test/proto/c_repeated.proto
|
A | +43 |