diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 0bb20177e4c280b290531c006a4f9f308d203a89..9caf8f22dfc5aebb0847dc1e9bb0fcea0e5bc47f 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -1,3 +1,4 @@ +{"_type":"issue","id":"tarantool-protobuf-rc8","title":"C decoder: strict-decode parity with pure-Lua codec (wire-type 6/7, UTF-8, field-num, merge)","description":"After bd-43t wiring (init.lua dispatch + codegen lazy-compile prologue), the C codec is actually exercised by `PB_ENABLE_C=1 just test` and `just conformance-c`. 77 conformance failures and 13 luatest failures cluster into 7 categories that the pure-Lua decoder already rejects:\n\n1. UnknownWireType6 / UnknownWireType7 — C decoder accepts illegal wire types instead of erroring (Required.Proto[23].ProtobufInput.UnknownWireType{6,7}_Field{1,2,3}_Version{0..3}, 32 cases).\n2. IllegalZeroFieldNum_Case_{0,1,3} — field number 0 must be rejected.\n3. BadTag_FieldNumberSlightlyTooHigh / FieldNumberTooHigh — field numbers \u003e 2^29-1 must be rejected.\n4. BadTag_OverlongVarint — tag varints over the spec-mandated length must be rejected.\n5. RejectInvalidUtf8.String.{Singular,Repeated,Oneof,MapKey,MapValue} — invalid UTF-8 in string/map-key fields must be rejected.\n6. UnmatchedStartGroup / UnmatchedStartGroupNested (proto2) — group balancing.\n7. ValidDataOneof.MESSAGE.Merge / RepeatedScalarMessageMerge — oneof message-merge semantics and repeated-scalar merge accumulate vs replace.\n\nReference impl: runtime/pb/codec.lua + wire.lua (decode_tag rejects wt 6/7 since commit 7442ea2; utf8 validation via utf8.len; merge_message recurses; etc.). C decoder lives in runtime/pb/c/c_runtime.c.\n\nStatus: pb.encode/pb.decode lazy-dispatch to pb.c_runtime.encode/decode whenever PB_ENABLE_C=1 and a c_plan exists. Wrappers in mode=full prologue + runtime mode via pb.encode central dispatch. Dispatch is proven (in-container probe + 1026/1039 luatest pass after wiring vs 748 with C inert / skip).\n\nRepro: PB_ENABLE_C=1 just test → 13 fails in conformance.core.* group. just conformance-c → 77 unexpected failures in binary suite.\n\nBlocks: tarantool-protobuf-43t conformance gate.","status":"open","priority":1,"issue_type":"bug","owner":"bigbes@gmail.com","created_at":"2026-05-23T19:29:06Z","created_by":"Eugene Blikh","updated_at":"2026-05-23T19:29:06Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-exy","title":"ra6 3f: repeated strings + repeated messages (cached stack-idx)","description":"Repeated string fields and repeated message fields. Encode: iterate the Lua array via cached stack idx, write each element (string field or recursive submsg encode). Decode: first hit lazy-creates the result array and stashes its stack index in a per-field slot (sized by plan-\u003en_fields, cap 16 for the spike fixed-size); subsequent hits lua_rawseti directly without re-lookup; one lua_setfield at decode_message exit attaches the array to the result table. This is the SPIKE-VALIDATED PATTERN — naive lazy-getfield is 2x slower at 100KB. Depends on 3d (needs sub-message machinery for repeated messages). Acceptance: Person.emails (repeated string) and Person.friends (repeated Person, self-reference) both round-trip byte-equal to mode=full at 1KB, 10KB, 100KB sizes.","status":"closed","priority":1,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T20:20:52Z","created_by":"Eugene Blikh","updated_at":"2026-05-23T11:07:38Z","started_at":"2026-05-23T11:05:14Z","closed_at":"2026-05-23T11:07:38Z","close_reason":"Acceptance tests landed: Person.emails (repeated string) and Person.friends (repeated Person, self-reference) round-trip byte-equal to mode=full at 1KB/10KB/100KB. Repeated string + message dispatch was already implemented as part of 3e (encode_repeated_field handles MESSAGE + string/bytes branches alongside scalars, decode_body uses cached list_stack_idx[] per-field); this ticket adds the formal size-scaled acceptance coverage.","dependencies":[{"issue_id":"tarantool-protobuf-exy","depends_on_id":"tarantool-protobuf-hwe","type":"blocks","created_at":"2026-05-18T23:22:18Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-jc9","title":"ra6 3e: repeated/packed scalar encode/decode","description":"Repeated scalar fields: encode-time, walk the Lua array via cached stack idx; decode-time, lazy-create the array on first hit and append via lua_rawseti with a cached stack idx (NOT lazy lua_getfield per element — that's 2x slower at 100KB per the spike). Packed repeated: length-prefixed varint blob; tight loop in C. Covers int32/sint32/uint32/int64/uint64/fixed32/fixed64/double/bool/enum. Depends on 3b + 3c (need the scalar primitives). Acceptance: Person.lucky_numbers (packed int32) round-trips byte-equal; a fixture with both packed and unpacked repeated scalars round-trips against mode=full at 10/100/1000-element counts.","status":"closed","priority":1,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T20:20:33Z","created_by":"Eugene Blikh","updated_at":"2026-05-23T10:39:55Z","started_at":"2026-05-23T10:29:02Z","closed_at":"2026-05-23T10:39:55Z","close_reason":"Closed","dependencies":[{"issue_id":"tarantool-protobuf-jc9","depends_on_id":"tarantool-protobuf-mz6","type":"blocks","created_at":"2026-05-18T23:22:07Z","created_by":"Eugene Blikh","metadata":"{}"},{"issue_id":"tarantool-protobuf-jc9","depends_on_id":"tarantool-protobuf-y1n","type":"blocks","created_at":"2026-05-18T23:22:07Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":2,"dependent_count":2,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-hwe","title":"ra6 3d: sub-message encode/decode (recursion)","description":"Nested-message support. Encode: open a sub-buffer, recurse with the submsg plan, prefix parent buffer with tag + length. Decode: bound the byte range, recurse, lua_setfield the resulting table. Sub-buffer stack-backed (4KB) and malloc-promoted, same pattern as the outer buffer. Recursion is by C function call into the same encode/decode routine with a different plan, so depth is bounded by C stack. Depends on 3b + 3c. Acceptance: Person.address (1-level) round-trips; deeper nesting via a 5-level test fixture round-trips byte-equal to mode=full.","status":"closed","priority":1,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T20:20:24Z","created_by":"Eugene Blikh","updated_at":"2026-05-23T10:24:19Z","started_at":"2026-05-23T10:11:41Z","closed_at":"2026-05-23T10:24:19Z","close_reason":"ra6 3d: sub-message encode/decode (recursion) — refactored encode_lua/decode_lua into reusable encode_body/decode_body, added singular sub-message encode (force-promoted parent heap_idx before recursion to make lua_settop safe) and decode (temporarily shrunk c-\u003elen for bounded inner read). 22 new tests cover round-trip, empty sub-message presence, proto3-optional fields, 5-level depth (new test/proto/c_nested.proto), parent-buffer regrow path, truncated-input errors. Full suite 854/854 with PB_ENABLE_C=1.","dependencies":[{"issue_id":"tarantool-protobuf-hwe","depends_on_id":"tarantool-protobuf-mz6","type":"blocks","created_at":"2026-05-18T23:22:06Z","created_by":"Eugene Blikh","metadata":"{}"},{"issue_id":"tarantool-protobuf-hwe","depends_on_id":"tarantool-protobuf-y1n","type":"blocks","created_at":"2026-05-18T23:22:05Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":2,"dependent_count":4,"comment_count":0} diff --git a/Justfile b/Justfile index f55b59e6d32fbdbab75e9e1988c5936062a1a54f..53d9e896cf032170f8e0f4336b5e1170170c79f7 100644 --- a/Justfile +++ b/Justfile @@ -38,7 +38,14 @@ # LUA_CPATH for the optional C runtime (require('pb.c_runtime')). Trailing # `;;` defers to the standard cpath. The C module is built into # runtime/pb/c_runtime.{so,dylib} by `just build-c` when PB_ENABLE_C=1 is # in play; absent without it. See docs/specs/c_accel_build_packaging.md. -lua_cpath := "./runtime/?.so;./runtime/?.dylib;./runtime/?/init.so;./runtime/?/init.dylib;;" +# +# `.dylib` is searched before `.so` because `package.searchpath` returns +# the first existing file (not the first loadable one). If both exist +# (e.g., a Linux `.so` left in the working tree by `just conformance-c`, +# which builds inside the bind-mounted container), macOS dlopen would +# fail on the foreign ELF without ever trying the local `.dylib`. Linux +# never produces a `.dylib` so the order is harmless there. +lua_cpath := "./runtime/?.dylib;./runtime/?.so;./runtime/?/init.dylib;./runtime/?/init.so;;" # --------------------------------------------------------------------------- # Default @@ -231,6 +238,24 @@ # Run the conformance suite with --enforce_recommended (strictest mode). conformance: conformance-build gen docker run --rm -v "$(pwd):/work" -w /work {{image}} + +# Same as `conformance`, but exercises the C-acceleration path +# (require('pb.c_runtime')). Builds runtime/pb/c_runtime.so inside the +# container (host .dylib won't load there), then re-runs the suite with +# PB_ENABLE_C=1 so pb/init.lua dispatches to the C codec. +conformance-c: conformance-build gen + docker run --rm -v "$(pwd):/work" -w /work -e PB_ENABLE_C=1 \ + --entrypoint bash {{image}} -c '\ + set -e; \ + make -C runtime/pb/c clean >/dev/null; \ + make -C runtime/pb/c >/dev/null; \ + conformance_test_runner --enforce_recommended \ + --failure_list test/conformance/known_failures.txt \ + --text_format_failure_list test/conformance/known_failures_text.txt \ + /usr/bin/tarantool cmd/conformance-runner.lua; \ + rc=$?; \ + make -C runtime/pb/c clean >/dev/null; \ + exit $rc' # Quick pass without --enforce_recommended. conformance-quick: conformance-build gen diff --git a/cmd/conformance-runner.lua b/cmd/conformance-runner.lua index df1ded476b55d086baab60fabbbaf702db9a4fe2..dd321eaf28563278746f4e42a122e1cb44333d39 100644 --- a/cmd/conformance-runner.lua +++ b/cmd/conformance-runner.lua @@ -40,6 +40,30 @@ REPO_ROOT .. '/cmd/?.lua', REPO_ROOT .. '/cmd/?/init.lua', package.path, }, ';') +-- package.searchpath returns the first existing file, not the first +-- loadable one. Cross-platform bind mounts (host macOS .dylib and +-- container Linux .so coexisting in the tree after `just conformance-c`) +-- can mask the correct binary if the wrong extension is listed first. +-- Order by host platform. +local _ext_first, _ext_second = '.so', '.dylib' +if jit and jit.os == 'OSX' then + _ext_first, _ext_second = '.dylib', '.so' +end +package.cpath = table.concat({ + REPO_ROOT .. '/runtime/?' .. _ext_first, + REPO_ROOT .. '/runtime/?' .. _ext_second, + REPO_ROOT .. '/runtime/?/init' .. _ext_first, + REPO_ROOT .. '/runtime/?/init' .. _ext_second, + package.cpath, +}, ';') + +-- Force our `pb` to win over any `lua-protobuf` (starwing) `.rocks/lib/ +-- tarantool/pb.so` left behind by transitive dependencies (luatest +-- pulls it in). Tarantool's rocks-aware loader runs ahead of the +-- override package.path/cpath above, so we pre-populate package.loaded. +-- Submodules (`pb.codec`, etc.) have unique names and resolve via the +-- prepended package.path without collision. +package.loaded.pb = dofile(REPO_ROOT .. '/runtime/pb/init.lua') local core = require('cmd.conformance.core') diff --git a/cmd/protoc-gen-tarantool/internal/gen/inline.go b/cmd/protoc-gen-tarantool/internal/gen/inline.go index 7d55041d0539a0a6ed31e457ee119df1855a77e4..73378569881e359ecfe386a4de1cf8adae46d828 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/inline.go +++ b/cmd/protoc-gen-tarantool/internal/gen/inline.go @@ -33,6 +33,17 @@ func emitInlineEncode(w *writer, name string, m *protogen.Message, file *protogen.File, selfPath string, imports map[string]string, prefix string) { emitEmmyWrapperAnnotations(w, name, emmyMessageFullName(m), wrapperEncode) w.line("function M.%s_encode(t)", name) + // C-acceleration: when PB_ENABLE_C=1 was set at module load, dispatch + // into pb.c_runtime.encode. Plan compilation is lazy on first call — + // eager compile would chase sub-message refs that aren't filled in + // yet when finalize_message runs at module load (see init.lua). On + // the default pure-Lua build pb.c_runtime is nil and the branch is a + // single nil-compare. + w.line(" local _d = M.%s_descriptor", name) + w.line(" if pb.c_runtime ~= nil then") + w.line(" local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)") + w.line(" return pb.c_runtime.encode(_p, t)") + w.line(" end") w.line(" if type(t) ~= 'table' then") w.line(" error(\"expected table for %s, got \" .. type(t), 0)", m.Desc.FullName()) w.line(" end") @@ -364,6 +375,12 @@ func emitInlineDecode(w *writer, name string, m *protogen.Message, file *protogen.File, selfPath string, imports map[string]string, prefix string) { emitEmmyWrapperAnnotations(w, name, emmyMessageFullName(m), wrapperDecode) w.line("function M.%s_decode(buf)", name) + // C-acceleration: see emitInlineEncode for rationale and lazy-compile. + w.line(" local _d = M.%s_descriptor", name) + w.line(" if pb.c_runtime ~= nil then") + w.line(" local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)") + w.line(" return pb.c_runtime.decode(_p, buf)") + w.line(" end") w.line(" if type(buf) ~= 'string' then") w.line(" error(\"expected string for %s decode, got \" .. type(buf), 0)", m.Desc.FullName()) w.line(" end") diff --git a/docker/conformance.Dockerfile b/docker/conformance.Dockerfile index 166de04e349e57ca57954a5efd808df4f61e0b96..4cce618f247b29083aa4ccb57973400426c6fe01 100644 --- a/docker/conformance.Dockerfile +++ b/docker/conformance.Dockerfile @@ -51,7 +51,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ && curl -L https://tarantool.io/release/3/installer.sh | bash \ - && apt-get install -y --no-install-recommends tarantool \ + && apt-get install -y --no-install-recommends \ + tarantool \ + tarantool-dev \ + build-essential \ && apt-get purge -y curl \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* diff --git a/examples/expected/full/c_int64/c_int64_pb.lua b/examples/expected/full/c_int64/c_int64_pb.lua index a45f7d301bb4ec4e4c5b20cca304e7fb73bad8e7..e07108a5e499d85305b8f09dafe644ac90a1cfe6 100644 --- a/examples/expected/full/c_int64/c_int64_pb.lua +++ b/examples/expected/full/c_int64/c_int64_pb.lua @@ -50,6 +50,11 @@ ---@param t c_int64.Wide ---@return string function M.Wide_encode(t) + local _d = M.Wide_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_int64.Wide, got " .. type(t), 0) end @@ -107,6 +112,11 @@ ---@param b string ---@return c_int64.Wide function M.Wide_decode(buf) + local _d = M.Wide_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_int64.Wide decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/c_nested/c_nested_pb.lua b/examples/expected/full/c_nested/c_nested_pb.lua index 4637c8578e5d41831a2294af490a968791d4867b..7e60060498ba4359343a2ad00ce187bcf60d5187 100644 --- a/examples/expected/full/c_nested/c_nested_pb.lua +++ b/examples/expected/full/c_nested/c_nested_pb.lua @@ -106,6 +106,11 @@ ---@param t c_nested.L1 ---@return string function M.L1_encode(t) + local _d = M.L1_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_nested.L1, got " .. type(t), 0) end @@ -152,6 +157,11 @@ ---@param b string ---@return c_nested.L1 function M.L1_decode(buf) + local _d = M.L1_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_nested.L1 decode, got " .. type(buf), 0) end @@ -215,6 +225,11 @@ ---@param t c_nested.L2 ---@return string function M.L2_encode(t) + local _d = M.L2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_nested.L2, got " .. type(t), 0) end @@ -261,6 +276,11 @@ ---@param b string ---@return c_nested.L2 function M.L2_decode(buf) + local _d = M.L2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_nested.L2 decode, got " .. type(buf), 0) end @@ -324,6 +344,11 @@ ---@param t c_nested.L3 ---@return string function M.L3_encode(t) + local _d = M.L3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_nested.L3, got " .. type(t), 0) end @@ -370,6 +395,11 @@ ---@param b string ---@return c_nested.L3 function M.L3_decode(buf) + local _d = M.L3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_nested.L3 decode, got " .. type(buf), 0) end @@ -433,6 +463,11 @@ ---@param t c_nested.L4 ---@return string function M.L4_encode(t) + local _d = M.L4_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_nested.L4, got " .. type(t), 0) end @@ -479,6 +514,11 @@ ---@param b string ---@return c_nested.L4 function M.L4_decode(buf) + local _d = M.L4_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_nested.L4 decode, got " .. type(buf), 0) end @@ -542,6 +582,11 @@ ---@param t c_nested.L5 ---@return string function M.L5_encode(t) + local _d = M.L5_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_nested.L5, got " .. type(t), 0) end @@ -575,6 +620,11 @@ ---@param b string ---@return c_nested.L5 function M.L5_decode(buf) + local _d = M.L5_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_nested.L5 decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/c_repeated/c_repeated_pb.lua b/examples/expected/full/c_repeated/c_repeated_pb.lua index ee6fc82145e0013dbcbf37d11bd952c03f1388fe..1702a9d0c7cf11d5e5f00b13de18f649e138602c 100644 --- a/examples/expected/full/c_repeated/c_repeated_pb.lua +++ b/examples/expected/full/c_repeated/c_repeated_pb.lua @@ -96,6 +96,11 @@ ---@param t c_repeated.Inner ---@return string function M.Inner_encode(t) + local _d = M.Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_repeated.Inner, got " .. type(t), 0) end @@ -141,6 +146,11 @@ ---@param b string ---@return c_repeated.Inner function M.Inner_decode(buf) + local _d = M.Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_repeated.Inner decode, got " .. type(buf), 0) end @@ -199,6 +209,11 @@ ---@param t c_repeated.Holder ---@return string function M.Holder_encode(t) + local _d = M.Holder_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for c_repeated.Holder, got " .. type(t), 0) end @@ -454,6 +469,11 @@ ---@param b string ---@return c_repeated.Holder function M.Holder_decode(buf) + local _d = M.Holder_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for c_repeated.Holder decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/conformance/conformance_pb.lua b/examples/expected/full/conformance/conformance_pb.lua index c08e09dec9c99a2b2fce858558210367de7eab99..46d4d2df62823a42525ba28e43a8dfa4771d340b 100644 --- a/examples/expected/full/conformance/conformance_pb.lua +++ b/examples/expected/full/conformance/conformance_pb.lua @@ -202,6 +202,11 @@ ---@param t conformance.TestStatus ---@return string function M.TestStatus_encode(t) + local _d = M.TestStatus_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for conformance.TestStatus, got " .. type(t), 0) end @@ -265,6 +270,11 @@ ---@param b string ---@return conformance.TestStatus function M.TestStatus_decode(buf) + local _d = M.TestStatus_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for conformance.TestStatus decode, got " .. type(buf), 0) end @@ -327,6 +337,11 @@ ---@param t conformance.FailureSet ---@return string function M.FailureSet_encode(t) + local _d = M.FailureSet_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for conformance.FailureSet, got " .. type(t), 0) end @@ -370,6 +385,11 @@ ---@param b string ---@return conformance.FailureSet function M.FailureSet_decode(buf) + local _d = M.FailureSet_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for conformance.FailureSet decode, got " .. type(buf), 0) end @@ -427,6 +447,11 @@ ---@param t conformance.ConformanceRequest ---@return string function M.ConformanceRequest_encode(t) + local _d = M.ConformanceRequest_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for conformance.ConformanceRequest, got " .. type(t), 0) end @@ -564,6 +589,11 @@ ---@param b string ---@return conformance.ConformanceRequest function M.ConformanceRequest_decode(buf) + local _d = M.ConformanceRequest_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for conformance.ConformanceRequest decode, got " .. type(buf), 0) end @@ -667,6 +697,11 @@ ---@param t conformance.ConformanceResponse ---@return string function M.ConformanceResponse_encode(t) + local _d = M.ConformanceResponse_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for conformance.ConformanceResponse, got " .. type(t), 0) end @@ -812,6 +847,11 @@ ---@param b string ---@return conformance.ConformanceResponse function M.ConformanceResponse_decode(buf) + local _d = M.ConformanceResponse_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for conformance.ConformanceResponse decode, got " .. type(buf), 0) end @@ -970,6 +1010,11 @@ ---@param t conformance.JspbEncodingConfig ---@return string function M.JspbEncodingConfig_encode(t) + local _d = M.JspbEncodingConfig_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for conformance.JspbEncodingConfig, got " .. type(t), 0) end @@ -1003,6 +1048,11 @@ ---@param b string ---@return conformance.JspbEncodingConfig function M.JspbEncodingConfig_decode(buf) + local _d = M.JspbEncodingConfig_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for conformance.JspbEncodingConfig decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/hello/hello_pb.lua b/examples/expected/full/hello/hello_pb.lua index 8163623c67d5468c6e16c9c58557fef06f9e43c3..09972e35f3ce51c623b32223b21a51e713ed7876 100644 --- a/examples/expected/full/hello/hello_pb.lua +++ b/examples/expected/full/hello/hello_pb.lua @@ -213,6 +213,11 @@ ---@param t hello.Result ---@return string function M.Result_encode(t) + local _d = M.Result_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.Result, got " .. type(t), 0) end @@ -281,6 +286,11 @@ ---@param b string ---@return hello.Result function M.Result_decode(buf) + local _d = M.Result_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.Result decode, got " .. type(buf), 0) end @@ -358,6 +368,11 @@ ---@param t hello.HelloRequest ---@return string function M.HelloRequest_encode(t) + local _d = M.HelloRequest_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.HelloRequest, got " .. type(t), 0) end @@ -397,6 +412,11 @@ ---@param b string ---@return hello.HelloRequest function M.HelloRequest_decode(buf) + local _d = M.HelloRequest_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.HelloRequest decode, got " .. type(buf), 0) end @@ -451,6 +471,11 @@ ---@param t hello.HelloReply ---@return string function M.HelloReply_encode(t) + local _d = M.HelloReply_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.HelloReply, got " .. type(t), 0) end @@ -490,6 +515,11 @@ ---@param b string ---@return hello.HelloReply function M.HelloReply_decode(buf) + local _d = M.HelloReply_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.HelloReply decode, got " .. type(buf), 0) end @@ -544,6 +574,11 @@ ---@param t hello.Event ---@return string function M.Event_encode(t) + local _d = M.Event_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.Event, got " .. type(t), 0) end @@ -726,6 +761,11 @@ ---@param b string ---@return hello.Event function M.Event_decode(buf) + local _d = M.Event_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.Event decode, got " .. type(buf), 0) end @@ -824,6 +864,11 @@ ---@param t hello.Address ---@return string function M.Address_encode(t) + local _d = M.Address_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.Address, got " .. type(t), 0) end @@ -893,6 +938,11 @@ ---@param b string ---@return hello.Address function M.Address_decode(buf) + local _d = M.Address_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.Address decode, got " .. type(buf), 0) end @@ -964,6 +1014,11 @@ ---@param t hello.Person ---@return string function M.Person_encode(t) + local _d = M.Person_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for hello.Person, got " .. type(t), 0) end @@ -1189,6 +1244,11 @@ ---@param b string ---@return hello.Person function M.Person_decode(buf) + local _d = M.Person_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for hello.Person decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/proto2_basic/proto2_basic_pb.lua b/examples/expected/full/proto2_basic/proto2_basic_pb.lua index c55a29ef23f64f1000bdcfdc98b439beedfae887..de656e18247b72d6fc924179769f7e68829e8ecc 100644 --- a/examples/expected/full/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/full/proto2_basic/proto2_basic_pb.lua @@ -240,6 +240,11 @@ ---@param t proto2_basic.Defaults ---@return string function M.Defaults_encode(t) + local _d = M.Defaults_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.Defaults, got " .. type(t), 0) end @@ -338,6 +343,11 @@ ---@param b string ---@return proto2_basic.Defaults function M.Defaults_decode(buf) + local _d = M.Defaults_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.Defaults decode, got " .. type(buf), 0) end @@ -469,6 +479,11 @@ ---@param t proto2_basic.Cardinality ---@return string function M.Cardinality_encode(t) + local _d = M.Cardinality_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.Cardinality, got " .. type(t), 0) end @@ -544,6 +559,11 @@ ---@param b string ---@return proto2_basic.Cardinality function M.Cardinality_decode(buf) + local _d = M.Cardinality_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.Cardinality decode, got " .. type(buf), 0) end @@ -661,6 +681,11 @@ ---@param t proto2_basic.Nested ---@return string function M.Nested_encode(t) + local _d = M.Nested_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.Nested, got " .. type(t), 0) end @@ -715,6 +740,11 @@ ---@param b string ---@return proto2_basic.Nested function M.Nested_decode(buf) + local _d = M.Nested_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.Nested decode, got " .. type(buf), 0) end @@ -788,6 +818,11 @@ ---@param t proto2_basic.Nested.Inner ---@return string function M.Nested_Inner_encode(t) + local _d = M.Nested_Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.Nested.Inner, got " .. type(t), 0) end @@ -822,6 +857,11 @@ ---@param b string ---@return proto2_basic.Nested.Inner function M.Nested_Inner_decode(buf) + local _d = M.Nested_Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.Nested.Inner decode, got " .. type(buf), 0) end @@ -876,6 +916,11 @@ ---@param t proto2_basic.WithGroup ---@return string function M.WithGroup_encode(t) + local _d = M.WithGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.WithGroup, got " .. type(t), 0) end @@ -921,6 +966,11 @@ ---@param b string ---@return proto2_basic.WithGroup function M.WithGroup_decode(buf) + local _d = M.WithGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.WithGroup decode, got " .. type(buf), 0) end @@ -992,6 +1042,11 @@ ---@param t proto2_basic.WithGroup.SingleGroup ---@return string function M.WithGroup_SingleGroup_encode(t) + local _d = M.WithGroup_SingleGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.WithGroup.SingleGroup, got " .. type(t), 0) end @@ -1037,6 +1092,11 @@ ---@param b string ---@return proto2_basic.WithGroup.SingleGroup function M.WithGroup_SingleGroup_decode(buf) + local _d = M.WithGroup_SingleGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.WithGroup.SingleGroup decode, got " .. type(buf), 0) end @@ -1105,6 +1165,11 @@ ---@param t proto2_basic.WithGroup.RepGroup ---@return string function M.WithGroup_RepGroup_encode(t) + local _d = M.WithGroup_RepGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.WithGroup.RepGroup, got " .. type(t), 0) end @@ -1138,6 +1203,11 @@ ---@param b string ---@return proto2_basic.WithGroup.RepGroup function M.WithGroup_RepGroup_decode(buf) + local _d = M.WithGroup_RepGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.WithGroup.RepGroup decode, got " .. type(buf), 0) end @@ -1197,6 +1267,11 @@ ---@param t proto2_basic.BenchPayload ---@return string function M.BenchPayload_encode(t) + local _d = M.BenchPayload_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.BenchPayload, got " .. type(t), 0) end @@ -1302,6 +1377,11 @@ ---@param b string ---@return proto2_basic.BenchPayload function M.BenchPayload_decode(buf) + local _d = M.BenchPayload_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.BenchPayload decode, got " .. type(buf), 0) end @@ -1427,6 +1507,11 @@ ---@param t proto2_basic.BenchPayload.Stats ---@return string function M.BenchPayload_Stats_encode(t) + local _d = M.BenchPayload_Stats_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.BenchPayload.Stats, got " .. type(t), 0) end @@ -1466,6 +1551,11 @@ ---@param b string ---@return proto2_basic.BenchPayload.Stats function M.BenchPayload_Stats_decode(buf) + local _d = M.BenchPayload_Stats_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.BenchPayload.Stats decode, got " .. type(buf), 0) end @@ -1534,6 +1624,11 @@ ---@param t proto2_basic.BenchPayload.Inner ---@return string function M.BenchPayload_Inner_encode(t) + local _d = M.BenchPayload_Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for proto2_basic.BenchPayload.Inner, got " .. type(t), 0) end @@ -1580,6 +1675,11 @@ ---@param b string ---@return proto2_basic.BenchPayload.Inner function M.BenchPayload_Inner_decode(buf) + local _d = M.BenchPayload_Inner_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for proto2_basic.BenchPayload.Inner decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua b/examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua index 220abe09c068b2d6b25bcdb46f899717d9a366ed..571731cb6693ec45932ce95aa14d2f1bf566bc7b 100644 --- a/examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua +++ b/examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua @@ -902,6 +902,11 @@ ---@param t protobuf_test_messages.proto2.TestAllTypesProto2 ---@return string function M.TestAllTypesProto2_encode(t) + local _d = M.TestAllTypesProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllTypesProto2, got " .. type(t), 0) end @@ -2606,6 +2611,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllTypesProto2 function M.TestAllTypesProto2_decode(buf) + local _d = M.TestAllTypesProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2 decode, got " .. type(buf), 0) end @@ -4547,6 +4557,11 @@ ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage ---@return string function M.TestAllTypesProto2_NestedMessage_encode(t) + local _d = M.TestAllTypesProto2_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage, got " .. type(t), 0) end @@ -4593,6 +4608,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage function M.TestAllTypesProto2_NestedMessage_decode(buf) + local _d = M.TestAllTypesProto2_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage decode, got " .. type(buf), 0) end @@ -4666,6 +4686,11 @@ ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.Data ---@return string function M.TestAllTypesProto2_Data_encode(t) + local _d = M.TestAllTypesProto2_Data_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllTypesProto2.Data, got " .. type(t), 0) end @@ -4705,6 +4730,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllTypesProto2.Data function M.TestAllTypesProto2_Data_decode(buf) + local _d = M.TestAllTypesProto2_Data_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.Data decode, got " .. type(buf), 0) end @@ -4773,6 +4803,11 @@ ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField ---@return string function M.TestAllTypesProto2_MultiWordGroupField_encode(t) + local _d = M.TestAllTypesProto2_MultiWordGroupField_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField, got " .. type(t), 0) end @@ -4812,6 +4847,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField function M.TestAllTypesProto2_MultiWordGroupField_decode(buf) + local _d = M.TestAllTypesProto2_MultiWordGroupField_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField decode, got " .. type(buf), 0) end @@ -4880,6 +4920,11 @@ ---@param t protobuf_test_messages.proto2.ForeignMessageProto2 ---@return string function M.ForeignMessageProto2_encode(t) + local _d = M.ForeignMessageProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.ForeignMessageProto2, got " .. type(t), 0) end @@ -4913,6 +4958,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.ForeignMessageProto2 function M.ForeignMessageProto2_decode(buf) + local _d = M.ForeignMessageProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.ForeignMessageProto2 decode, got " .. type(buf), 0) end @@ -4972,6 +5022,11 @@ ---@param t protobuf_test_messages.proto2.GroupField ---@return string function M.GroupField_encode(t) + local _d = M.GroupField_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.GroupField, got " .. type(t), 0) end @@ -5011,6 +5066,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.GroupField function M.GroupField_decode(buf) + local _d = M.GroupField_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.GroupField decode, got " .. type(buf), 0) end @@ -5079,6 +5139,11 @@ ---@param t protobuf_test_messages.proto2.UnknownToTestAllTypes ---@return string function M.UnknownToTestAllTypes_encode(t) + local _d = M.UnknownToTestAllTypes_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.UnknownToTestAllTypes, got " .. type(t), 0) end @@ -5159,6 +5224,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.UnknownToTestAllTypes function M.UnknownToTestAllTypes_decode(buf) + local _d = M.UnknownToTestAllTypes_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.UnknownToTestAllTypes decode, got " .. type(buf), 0) end @@ -5282,6 +5352,11 @@ ---@param t protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup ---@return string function M.UnknownToTestAllTypes_OptionalGroup_encode(t) + local _d = M.UnknownToTestAllTypes_OptionalGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup, got " .. type(t), 0) end @@ -5315,6 +5390,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup function M.UnknownToTestAllTypes_OptionalGroup_decode(buf) + local _d = M.UnknownToTestAllTypes_OptionalGroup_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup decode, got " .. type(buf), 0) end @@ -5374,6 +5454,11 @@ ---@param t protobuf_test_messages.proto2.NullHypothesisProto2 ---@return string function M.NullHypothesisProto2_encode(t) + local _d = M.NullHypothesisProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.NullHypothesisProto2, got " .. type(t), 0) end @@ -5401,6 +5486,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.NullHypothesisProto2 function M.NullHypothesisProto2_decode(buf) + local _d = M.NullHypothesisProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.NullHypothesisProto2 decode, got " .. type(buf), 0) end @@ -5452,6 +5542,11 @@ ---@param t protobuf_test_messages.proto2.EnumOnlyProto2 ---@return string function M.EnumOnlyProto2_encode(t) + local _d = M.EnumOnlyProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.EnumOnlyProto2, got " .. type(t), 0) end @@ -5479,6 +5574,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.EnumOnlyProto2 function M.EnumOnlyProto2_decode(buf) + local _d = M.EnumOnlyProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.EnumOnlyProto2 decode, got " .. type(buf), 0) end @@ -5530,6 +5630,11 @@ ---@param t protobuf_test_messages.proto2.OneStringProto2 ---@return string function M.OneStringProto2_encode(t) + local _d = M.OneStringProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.OneStringProto2, got " .. type(t), 0) end @@ -5569,6 +5674,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.OneStringProto2 function M.OneStringProto2_decode(buf) + local _d = M.OneStringProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.OneStringProto2 decode, got " .. type(buf), 0) end @@ -5628,6 +5738,11 @@ ---@param t protobuf_test_messages.proto2.ProtoWithKeywords ---@return string function M.ProtoWithKeywords_encode(t) + local _d = M.ProtoWithKeywords_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.ProtoWithKeywords, got " .. type(t), 0) end @@ -5689,6 +5804,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.ProtoWithKeywords function M.ProtoWithKeywords_decode(buf) + local _d = M.ProtoWithKeywords_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.ProtoWithKeywords decode, got " .. type(buf), 0) end @@ -5764,6 +5884,11 @@ ---@param t protobuf_test_messages.proto2.TestAllRequiredTypesProto2 ---@return string function M.TestAllRequiredTypesProto2_encode(t) + local _d = M.TestAllRequiredTypesProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllRequiredTypesProto2, got " .. type(t), 0) end @@ -6148,6 +6273,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2 function M.TestAllRequiredTypesProto2_decode(buf) + local _d = M.TestAllRequiredTypesProto2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2 decode, got " .. type(buf), 0) end @@ -6384,6 +6514,11 @@ ---@param t protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage ---@return string function M.TestAllRequiredTypesProto2_NestedMessage_encode(t) + local _d = M.TestAllRequiredTypesProto2_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage, got " .. type(t), 0) end @@ -6445,6 +6580,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage function M.TestAllRequiredTypesProto2_NestedMessage_decode(buf) + local _d = M.TestAllRequiredTypesProto2_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage decode, got " .. type(buf), 0) end @@ -6522,6 +6662,11 @@ ---@param t protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data ---@return string function M.TestAllRequiredTypesProto2_Data_encode(t) + local _d = M.TestAllRequiredTypesProto2_Data_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data, got " .. type(t), 0) end @@ -6563,6 +6708,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data function M.TestAllRequiredTypesProto2_Data_decode(buf) + local _d = M.TestAllRequiredTypesProto2_Data_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data decode, got " .. type(buf), 0) end @@ -6621,6 +6771,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof ---@return string function M.TestLargeOneof_encode(t) + local _d = M.TestLargeOneof_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof, got " .. type(t), 0) end @@ -6719,6 +6874,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof function M.TestLargeOneof_decode(buf) + local _d = M.TestLargeOneof_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof decode, got " .. type(buf), 0) end @@ -6834,6 +6994,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof.A1 ---@return string function M.TestLargeOneof_A1_encode(t) + local _d = M.TestLargeOneof_A1_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof.A1, got " .. type(t), 0) end @@ -6861,6 +7026,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof.A1 function M.TestLargeOneof_A1_decode(buf) + local _d = M.TestLargeOneof_A1_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A1 decode, got " .. type(buf), 0) end @@ -6912,6 +7082,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof.A2 ---@return string function M.TestLargeOneof_A2_encode(t) + local _d = M.TestLargeOneof_A2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof.A2, got " .. type(t), 0) end @@ -6939,6 +7114,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof.A2 function M.TestLargeOneof_A2_decode(buf) + local _d = M.TestLargeOneof_A2_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A2 decode, got " .. type(buf), 0) end @@ -6990,6 +7170,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof.A3 ---@return string function M.TestLargeOneof_A3_encode(t) + local _d = M.TestLargeOneof_A3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof.A3, got " .. type(t), 0) end @@ -7017,6 +7202,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof.A3 function M.TestLargeOneof_A3_decode(buf) + local _d = M.TestLargeOneof_A3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A3 decode, got " .. type(buf), 0) end @@ -7068,6 +7258,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof.A4 ---@return string function M.TestLargeOneof_A4_encode(t) + local _d = M.TestLargeOneof_A4_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof.A4, got " .. type(t), 0) end @@ -7095,6 +7290,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof.A4 function M.TestLargeOneof_A4_decode(buf) + local _d = M.TestLargeOneof_A4_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A4 decode, got " .. type(buf), 0) end @@ -7146,6 +7346,11 @@ ---@param t protobuf_test_messages.proto2.TestLargeOneof.A5 ---@return string function M.TestLargeOneof_A5_encode(t) + local _d = M.TestLargeOneof_A5_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto2.TestLargeOneof.A5, got " .. type(t), 0) end @@ -7173,6 +7378,11 @@ ---@param b string ---@return protobuf_test_messages.proto2.TestLargeOneof.A5 function M.TestLargeOneof_A5_decode(buf) + local _d = M.TestLargeOneof_A5_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A5 decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua b/examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua index baca8363f14dfbf8f6273d534f919bb2fcffa9c8..fea5a71521f3081af319159db4f8be60f9f770cd 100644 --- a/examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua +++ b/examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua @@ -596,6 +596,11 @@ ---@param t protobuf_test_messages.proto3.TestAllTypesProto3 ---@return string function M.TestAllTypesProto3_encode(t) + local _d = M.TestAllTypesProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto3.TestAllTypesProto3, got " .. type(t), 0) end @@ -2760,6 +2765,11 @@ ---@param b string ---@return protobuf_test_messages.proto3.TestAllTypesProto3 function M.TestAllTypesProto3_decode(buf) + local _d = M.TestAllTypesProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.TestAllTypesProto3 decode, got " .. type(buf), 0) end @@ -4511,6 +4521,11 @@ ---@param t protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage ---@return string function M.TestAllTypesProto3_NestedMessage_encode(t) + local _d = M.TestAllTypesProto3_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage, got " .. type(t), 0) end @@ -4557,6 +4572,11 @@ ---@param b string ---@return protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage function M.TestAllTypesProto3_NestedMessage_decode(buf) + local _d = M.TestAllTypesProto3_NestedMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage decode, got " .. type(buf), 0) end @@ -4620,6 +4640,11 @@ ---@param t protobuf_test_messages.proto3.ForeignMessage ---@return string function M.ForeignMessage_encode(t) + local _d = M.ForeignMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto3.ForeignMessage, got " .. type(t), 0) end @@ -4653,6 +4678,11 @@ ---@param b string ---@return protobuf_test_messages.proto3.ForeignMessage function M.ForeignMessage_decode(buf) + local _d = M.ForeignMessage_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.ForeignMessage decode, got " .. type(buf), 0) end @@ -4707,6 +4737,11 @@ ---@param t protobuf_test_messages.proto3.NullHypothesisProto3 ---@return string function M.NullHypothesisProto3_encode(t) + local _d = M.NullHypothesisProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto3.NullHypothesisProto3, got " .. type(t), 0) end @@ -4734,6 +4769,11 @@ ---@param b string ---@return protobuf_test_messages.proto3.NullHypothesisProto3 function M.NullHypothesisProto3_decode(buf) + local _d = M.NullHypothesisProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.NullHypothesisProto3 decode, got " .. type(buf), 0) end @@ -4785,6 +4825,11 @@ ---@param t protobuf_test_messages.proto3.EnumOnlyProto3 ---@return string function M.EnumOnlyProto3_encode(t) + local _d = M.EnumOnlyProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for protobuf_test_messages.proto3.EnumOnlyProto3, got " .. type(t), 0) end @@ -4812,6 +4857,11 @@ ---@param b string ---@return protobuf_test_messages.proto3.EnumOnlyProto3 function M.EnumOnlyProto3_decode(buf) + local _d = M.EnumOnlyProto3_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.EnumOnlyProto3 decode, got " .. type(buf), 0) end diff --git a/examples/expected/full/quickstart/quickstart_pb.lua b/examples/expected/full/quickstart/quickstart_pb.lua index fd14ad0d420fc9e5a00b21ae0e509082cb514959..11cf3fb2623635cbb2c1468a6919e491a75060fc 100644 --- a/examples/expected/full/quickstart/quickstart_pb.lua +++ b/examples/expected/full/quickstart/quickstart_pb.lua @@ -57,6 +57,11 @@ ---@param t quickstart.User ---@return string function M.User_encode(t) + local _d = M.User_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.encode(_p, t) + end if type(t) ~= 'table' then error("expected table for quickstart.User, got " .. type(t), 0) end @@ -131,6 +136,11 @@ ---@param b string ---@return quickstart.User function M.User_decode(buf) + local _d = M.User_descriptor + if pb.c_runtime ~= nil then + local _p = _d.c_plan or pb.c_runtime.compile_plan(_d) + return pb.c_runtime.decode(_p, buf) + end if type(buf) ~= 'string' then error("expected string for quickstart.User decode, got " .. type(buf), 0) end diff --git a/runtime/pb/init.lua b/runtime/pb/init.lua index cce0b9766df28f9adaf5da8ff54934ac3c69e8df..a8300785c6e0ce6d9302394a8ba2cb2a9d1e6aa8 100644 --- a/runtime/pb/init.lua +++ b/runtime/pb/init.lua @@ -29,11 +29,35 @@ local ok, mod = pcall(require, 'pb.c_runtime') if ok then c_runtime = mod end end +-- High-level codec entry points. When the C runtime is loaded, dispatch +-- on desc.c_plan and lazily compile it on first call. Lazy compile is +-- required because compile_plan eagerly chases sub-message refs and +-- codegen forward-declares descriptors (see finalize_message above). +local pb_encode = codec.encode +local pb_decode = codec.decode +if c_runtime ~= nil then + local c_encode = c_runtime.encode + local c_decode = c_runtime.decode + local c_compile = c_runtime.compile_plan + local lua_encode = pb_encode + local lua_decode = pb_decode + pb_encode = function(desc, t) + local plan = desc.c_plan or c_compile(desc) + if plan ~= nil then return c_encode(plan, t) end + return lua_encode(desc, t) + end + pb_decode = function(desc, b) + local plan = desc.c_plan or c_compile(desc) + if plan ~= nil then return c_decode(plan, b) end + return lua_decode(desc, b) + end +end + ---@type pb.Module return { -- High-level codec - encode = codec.encode, - decode = codec.decode, + encode = pb_encode, + decode = pb_decode, -- Lazy / zero-copy decode view. See runtime/pb/lazy.lua for the -- :get / :has / :which / :iter / :names surface on the returned @@ -202,6 +226,15 @@ -- typed value extraction, list bookkeeping, message-merge -- rules, and oneof sibling clearing. Maps fall through to -- the existing in-loop dispatch. codec.compile_readers(desc) + -- NB: C-acceleration plan compilation is deferred to first + -- encode/decode call (see dispatch wrappers in pb.encode / + -- pb.decode and the generated `M._{encode,decode}` + -- prologues). Eager compile here would fail on forward + -- references — codegen forward-declares all descriptors as + -- `{name=...}` and only fills `.fields` later, so a top-down + -- `pb.finalize_message(Result_descriptor)` at module load + -- runs before `Address_descriptor.fields` exists. Lazy + -- compile sees a fully-populated module table. return desc end,