~bigbes/tarantool-protobuf: 3235f34a

c_runtime: proto2 — required, defaults, groups, extensions (ra6 3i)

Plumb proto2 semantic surface through the C plan and codec:

  * required: encode-time `required field missing` error with full path
    (`<msg>.<field>`); set scalars/enums force-emit so zero still reaches
    the wire (matches build_required_writer).
  * groups: kind='group' compiles to PB_KIND_MESSAGE with is_group=1; tag
    uses SGROUP and a pre-encoded EGROUP closer; encode walks regular
    body bytes into a sub-buf and brackets with SGROUP+body+EGROUP (no
    length prefix). Decode adds a stop_group_id to decode_body so the
    inner walk terminates on the matching EGROUP, with id-mismatch as a
    hard error per spec. Unknown-tag skip (`dec_skip_with_id`) recurses
    through SGROUP bodies to the matching EGROUP.
  * extensions: walk `desc.extensions_list` at plan-compile time, cache
    each ext's full_name; encode iterates the cached array and emits any
    present in `data._extensions[full_name]`; decode probes unregistered
    tags against `plan->extensions` before falling through to
    `_unknown_fields`, routing matched bytes into result._extensions.

Defaults: presence-tracked optional fields stay nil-on-absent in the
decoded table; the descriptor's `default_value` is surfaced for callers
(JSON, text) but never auto-materialized at decode — same as codec.lua.

36 new tests in test/c_runtime_proto2_test.lua exercise required missing
+ zero-emit, presence-tracked defaults, singular/repeated groups, and
extension round-trip — each asserts byte-equality with mode=full pure-Lua
output across both codegen modes.

ra6 3i

Eugene Blikh <bigbes@gmail.com> — 2026-05-23 18:39:58 UTC

Commit 3235f34af486e3ef0043f8cb9d9230e29b919980view raw patch

Parent(s): c57b013b

2 changed file(s)

FileStatus+
runtime/pb/c/c_runtime.c M +420 -24
test/c_runtime_proto2_test.lua A +264