diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 511ba0badae1236281b4bac0377e37f68e9a4439..78956653bb32e8e92f9b20dbb39a7aa0c900822d 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -48,3 +48,4 @@ {"id":"int-a3f84d37","kind":"field_change","created_at":"2026-05-24T16:53:33.608711Z","actor":"Eugene Blikh","issue_id":"tarantool-protobuf-lkz","extra":{"field":"status","new_value":"closed","old_value":"open"}} {"id":"int-643d6ba3","kind":"field_change","created_at":"2026-05-24T16:53:43.706654Z","actor":"Eugene Blikh","issue_id":"tarantool-protobuf-86g","extra":{"field":"status","new_value":"closed","old_value":"open"}} {"id":"int-7db2afd6","kind":"field_change","created_at":"2026-05-24T17:05:10.538707Z","actor":"Eugene Blikh","issue_id":"tarantool-protobuf-ch2","extra":{"field":"status","new_value":"closed","old_value":"in_progress"}} {"id":"int-b981997e","kind":"field_change","created_at":"2026-05-24T17:20:53.622551Z","actor":"Eugene Blikh","issue_id":"tarantool-protobuf-aah","extra":{"field":"status","new_value":"closed","old_value":"in_progress"}} +{"id":"int-2a1c9c90","kind":"field_change","created_at":"2026-05-24T18:20:11.709034Z","actor":"Eugene Blikh","issue_id":"tarantool-protobuf-6bb","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Full-mode codegen emits _decode_unsafe alongside _decode that skips utf8_len at every string site (singular/repeated/map-kv/extensions/>=128-byte fallback) and recurses into sub-messages' _decode_unsafe. Skips pb.c_runtime dispatch (C runtime validates today; tracked in kyt). Runtime mode deferred to 58u (compile parallel _reader_unsafe closures). 6 tests in test/decode_unsafe_test.lua; full suite + conformance pass; ~20% perf win on string-heavy 1KB Person microbench. Generated code ~35% larger as expected. Docs in docs/api-modes.md."}} diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 654c42d5de29c57359e1ac65c98a0e4f1690ab49..fef400fa38a45d5aaf9313cc40bbaf697f31df37 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -28,7 +28,7 @@ {"_type":"issue","id":"tarantool-protobuf-qwt","title":"Codegen: emit per-extension writers for proto2 extensions (skip pb.codec.encode_field dispatch)","description":"proto2 extensions are the slowest line in the bench: proto2_basic.BenchPayload 'min' fixture encodes at 11.0 MB/s — vs 281 MB/s for the 100B Person. Cause: generated _extensions walk in mode=full falls through to pb.codec.encode_field, the slow runtime dispatch that mode=full otherwise avoids.\n\nFix: at codegen time, when 'extend Foo { ... ext_count = 100; ... }' is seen, emit a dedicated writer per extension. The Foo_encode body's extensions block becomes:\n\n local _ev = _exts['proto2_basic.ext_count']\n if _ev ~= nil then\n -- direct inline write for the int32 ext, just like a regular int32 field\n n = n + 1; out[n] = '\u003cprecomputed tag bytes\u003e'\n n = n + 1; out[n] = wire.encode_int32(_ev)\n end\n -- repeat per extension\n\nDecoder side: extensions_by_id[id] dispatch in the else branch currently calls pb.codec.decode_extension; can similarly be replaced by inline-emitted per-extension decoder blocks alongside the regular field branches.\n\nConcretely closes the proto2 min throughput gap (3.4x vs Go apiv2) which is bench's worst data point. Has zero impact on payloads without extensions.","notes":"Generated code grows by one if-block per registered extension. For a message with 50 extensions this could be significant — but proto2 extensions are typically used sparingly. Worth gating on extension count if size becomes a problem.\n\nExisting extensions_by_id / extensions_list / extensions_by_full_name registries can stay (they're used by text/json/runtime dispatch); the fast path just bypasses them in mode=full.","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T17:14:38Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T10:55:07Z","started_at":"2026-05-24T10:32:44Z","closed_at":"2026-05-24T10:55:07Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-ch2","title":"Encoder: JIT-friendly map\u003cK,V\u003e field iteration (avoid pairs() ISNEXT NYI)","description":"map\u003cK,V\u003e field encoding walks the user-supplied table with pairs() — runtime/pb/codec.lua:162 and every codegen-emitted map block in mode=full. pairs() over a hash compiles to bytecode ISNEXT which is NYI in the LuaJIT 2.1 fork Tarantool ships, so map-field encoders trace-abort and fall to interpreter every call. bench/jit_trace.lua already pins this as the only intentional NYI in the hot path.\n\nUnlike oneofs/extensions (which are flattened to *_list arrays at finalize-time in init.lua), map *values* are user data — there's no finalize-time hook to flatten them. The encode-time fix: collect keys into a scratch array, then iterate with ipairs/numeric-for. Pattern:\n\n local _mkeys, _mn = {}, 0\n for k in pairs(value) do _mn = _mn + 1; _mkeys[_mn] = k end\n for _i = 1, _mn do\n local k = _mkeys[_i]\n local v = value[k]\n -- emit entry as today\n end\n\nCosts one extra alloc (scratch keys table) per map field per call but lets the inner emit-loop stay on a JIT trace. For maps with \u003e3 entries the trace-stable inner loop should net out positive. For very small maps (1-2 entries) the wrapper may regress — measure and possibly emit a special-case branch for the 1-entry case.\n\nPairs naturally with x9f (deterministic map option) — when on, the scratch keys array can be sorted, giving deterministic output for free vs the current pairs()-order-undefined behavior. Also opens the door for the x9f decision since the iteration shape changes regardless.","notes":"Generated code lives in protoc-gen-tarantool. Both runtime mode (codec.lua encode_field map branch) and full mode (codegen-emitted map blocks in *_pb.lua) need updating. Bench fixture: hello.Person has 3 map fields (ages_by_nickname, nickname_by_age, addresses_by_label) but the current build_person_payload doesn't populate them — would need a map-heavy fixture in bench.lua to measure the win.\n2026-05-24 — investigated, intervention regresses across all map sizes.\n\nHand-implemented the materialize-keys-then-ipairs pattern in both\ncodegen (inline.go:emitInlineEncodeMap) and runtime (codec.lua kind=='map'\nbranch). Parity-clean — 752/752 tests pass.\n\nBench (work.lab.local, median of 3 trials, full mode, Person.ages_by_nickname\nmap\u003cstring,int32\u003e):\n\n map size | BEFORE | AFTER | Δ\n ---------|-------------|-------------|-------\n 1 | 1,282,180 | 1,128,545 | -12%\n 3 | 634,880 | 549,761 | -13%\n 10 | 215,745 | 196,800 | -9%\n 50 | 48,162 | 45,614 | -5%\n 200 | 11,613 | 11,282 | -3%\n\nDiagnosis: the issue's prediction that 'inner emit-loop stays on a JIT\ntrace' was theoretically correct but empirically irrelevant. LuaJIT's\nside-trace machinery was already JIT-ing the inner body via a side trace\nfrom the pairs()-induced ISNEXT abort point — the body was already\non-trace before the change. The change adds:\n - scratch _mkeys table allocation per encode\n - O(N) key-collection walk (still pairs(), still off-trace)\n - extra v[_k] hash lookup per entry\n\nThese costs scale with map size. Regression shrinks as N grows (the\nwrapper amortizes) but never crosses zero even at 200 entries.\n\nThe jit_trace.lua [PIN] still passed under the change because pairs()\nis still called for key collection — the NYI was simply moved, not\neliminated. The encoder cannot fully shed the NYI without a\ndifferent data shape (e.g., keys stored as a parallel array at\ntable-construction time, which is a user-visible API change).\n\nConclusion: not viable. The \"for \u003e3 entries net positive\" prediction is\nempirically false on Tarantool's LuaJIT 2.1 fork. Closing.\n\nRelated future direction: if x9f (deterministic map encoding) ships\nwith sorted-keys semantics, the user-side cost of producing a sorted\nkeys array could be amortized at construction time rather than at encode\ntime, opening a different (non-pairs) iteration shape. That's a feature\ndecision, not a perf one.","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T17:13:53Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T17:05:10Z","started_at":"2026-05-24T16:59:19Z","closed_at":"2026-05-24T17:05:10Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-cch","title":"Decoder: use local counter instead of #list at repeated-field append","description":"jit.p profile (Person 1KB): line 1021 'list[#list + 1] = val' is 6.2% of total decode time. Each #list invocation re-traverses to find the array length. Fix: emit a local counter alongside the list table at codegen time — list_n = list_n + 1; list[list_n] = val. Already done on encode side ('out, n' pattern). Tiny 1-line codegen change. Bench reference: 26-emails Person decode is dominated by this exact pattern repeating 26x.","notes":"At decode start, when initializing a repeated-field list, also init the counter: 'local emails, emails_n = result.emails, #(result.emails or {}) ' — for the first-encounter case, counter starts at 0. Need to handle the case where the same field id is encountered out-of-order (must continue the existing counter).","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:52:38Z","created_by":"Eugene Blikh","updated_at":"2026-05-18T19:01:17Z","started_at":"2026-05-18T18:56:39Z","closed_at":"2026-05-18T19:01:17Z","close_reason":"Local counter per repeated non-map field; median-of-3 decode wins +5.0% (1KB), +5.0% (10KB), +7.1% (100KB). Profile target was 6.2%; landed wins of 5-7%. Encode flat, runtime flat. 745/745 tests, 37/37 JIT. See bench/PERF_LOG.md.","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-a6n","title":"Decoder: ffi-cast buffer ptr once per decode; replace buf:byte/buf:sub at fast paths","description":"Decode hot path uses buf:byte(pos) and buf:sub(start, end-1) — both are method calls dispatched via the string metatable per invocation. Wire.lua already has U8CP = ffi.typeof('const uint8_t*'). The fix: at the top of each generated Type_decode, cast once (local ptr = ffi.cast(U8CP, buf)) and use ptr[pos-1] for byte reads. For string returns, keep buf:sub (or use ffi.string per bgu issue) since the result must be a Lua string. Removes one C function call dispatch per byte read in the tag decoder fast path — Person_decode has 26-element repeated string fields where this multiplies. Compatible with bgu (the ffi.string change for decode_string) — both rely on the same cast.","notes":"Caveat: ffi.cast holds the string pinned. Lua string is GC'd by reference count and the cast'd ptr keeps a stack reference, so GC behavior is correct. Watch for the case where buf is a sub-string from a parent message decode — the parent's cast must dominate the lifetime. Easy fix: each Type_decode re-casts the buf it owns.","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:51:24Z","created_by":"Eugene Blikh","updated_at":"2026-05-23T20:48:33Z","started_at":"2026-05-23T20:34:10Z","closed_at":"2026-05-23T20:48:33Z","close_reason":"Inlined 1-byte LEN fast path for string/bytes scalar + repeated fields in generated full-mode _decode; skips wire.decode_string/_bytes function call frame and inlines utf8_len. Dropped the U8CP cast-at-top idea — 24B/decode cdata allocation that LuaJIT couldn't sink, regressed small messages. Person_decode full: 10B -6.9%, 100B -7.2%, 1KB -10.7%, 10KB -12.2%, 100KB -14.0%. Zero alloc impact. Tests: 1043 pass, 37 JIT trace checks pass.","dependency_count":0,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"tarantool-protobuf-6bb","title":"Decoder: opt-in skip_utf8_validation flag for trusted sources","description":"decode_string runs utf8_len (ICU) on every decoded string. Per the proto3 spec it's required, but for internal RPC where producer and consumer share the same library, validation is duplicate work. Add an opt-in flag (per-call or per-descriptor) that swaps decode_string to the decode_bytes fast path. Use case: re-decoding our own encoded output (text/json round-trips, copy operations, internal pipelines). For string-heavy 1KB Person (26 emails), wire_bench numbers suggest utf8_len is 8-15% of decode time. Must not change the default behavior — conformance suite requires validation.","notes":"Plumbing options: pb.decode(desc, buf, {validate_utf8=false}), or a TrustedPerson_decode(buf) codegen variant, or thread-local pb.set_validate_utf8(false). Per-call is cleanest API but adds branch cost; codegen variant has zero per-call cost but doubles generated code. Per-descriptor (desc.skip_validation) is a middle ground. Decide during implementation.","status":"open","priority":2,"issue_type":"task","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:51:23Z","created_by":"Eugene Blikh","updated_at":"2026-05-18T16:58:51Z","dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"tarantool-protobuf-6bb","title":"Decoder: opt-in skip_utf8_validation flag for trusted sources","description":"decode_string runs utf8_len (ICU) on every decoded string. Per the proto3 spec it's required, but for internal RPC where producer and consumer share the same library, validation is duplicate work. Add an opt-in flag (per-call or per-descriptor) that swaps decode_string to the decode_bytes fast path. Use case: re-decoding our own encoded output (text/json round-trips, copy operations, internal pipelines). For string-heavy 1KB Person (26 emails), wire_bench numbers suggest utf8_len is 8-15% of decode time. Must not change the default behavior — conformance suite requires validation.","notes":"Plumbing options: pb.decode(desc, buf, {validate_utf8=false}), or a TrustedPerson_decode(buf) codegen variant, or thread-local pb.set_validate_utf8(false). Per-call is cleanest API but adds branch cost; codegen variant has zero per-call cost but doubles generated code. Per-descriptor (desc.skip_validation) is a middle ground. Decide during implementation.","status":"in_progress","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:51:23Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T18:03:10Z","started_at":"2026-05-24T18:03:10Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-kot","title":"Codegen: localize wire.* upvalues at top of each generated message function","description":"examples/expected/full/hello/hello_pb.lua has 106 wire.* accesses — each is a hash-table lookup on the upvalue. LuaJIT hoists this when traces stay hot, but every nested-message boundary breaks the trace (see gcy notes), forcing re-lookup in the side trace / interpreter. Fix: codegen-emit at the top of each Type_encode and Type_decode function the locals it actually uses — only for the wire.* entries referenced in that function body — so the in-body calls are direct LJ_FUNCC dispatches with no table lookup. One-line codegen change; broad impact whenever traces stitch poorly. Pairs naturally with h8v and 4kj (both move more work into the same generated function bodies, magnifying the per-call lookup cost). Expected: 3-8% across the board; larger when traces break.","notes":"Codegen-side change in the Go plugin (protoc-gen-tarantool). Pre-compute the set of wire.* symbols used in each function (e.g., {encode_varint, decode_string, decode_tag}) and emit 'local encode_varint = wire.encode_varint' style preambles. Keep the existing 'local wire = pb.wire' so non-emitted entries still work. Verify with bench/jit_trace.lua that we don't increase trace size past LuaJIT inline budget on large messages (test_messages_proto3 is 4212 lines).","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:51:23Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T05:40:24Z","started_at":"2026-05-24T04:41:18Z","closed_at":"2026-05-24T05:40:24Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-lkz","title":"Encoder: single-pass two-phase (size + emit) into single buffer","description":"Eliminate the per-call out table and the per-field intermediate string allocations by emitting once into a pre-sized buffer. Two viable shapes (per drm notes):\n\n1. Two-pass: walk fields once to compute exact size, allocate one buffer, walk again to emit. Mirrors vtproto's Size()+MarshalTo() pattern — vtproto's 1-alloc encode is what gives it 13-20x throughput over us at 1KB-10KB Person.\n2. Single-pass with backpatched length varints: write tag + 1-byte placeholder for the length, recurse, fill in (memmove if final length \u003e= 128). Skips the size pass (~3 us at 1KB).\n\nImplementation can live in codegen (mode=full) — emit a _encode_to_buf per message that takes (data, ibuf, offset) and returns new_offset, then a public Person_encode that wraps it with the buffer allocation. Constraint: per-field closure count must stay \u003c= current pb.encode writers count, else the per-field dispatch cost re-emerges (drm: two prior ibuf prototypes both regressed by ~2x because of dispatch).\n\nRelates to h8v (codegen FFI direct writes) which is the per-field building block this work composes.","notes":"drm notes have the deeper analysis including why M6 ibuf path naive byte-write fails (20x interpreter dispatch overhead). The codegen approach sidesteps that by inlining all writes at codegen time so there's no runtime closure dispatch.\n2026-05-24 — verdict: not viable as a pure-Lua path.\n\nHand-written spike (ffi.new uint8_t[?] + two-pass size+emit, all inlined,\nno closures, exact-size buffer) was byte-exact for parity but regressed\nencode throughput across all 5 size buckets:\n\n 10B 0.77x 100B 0.71x 1KB 0.50x 10KB 0.31x 100KB 0.31x\n\nProfile (jit.p) of the current encoder shows 84% of time in the inlined\nmessage bodies (Person_encode + Address_encode); wire.encode_int32 is 2%\nof total. The \"out table + table.concat\" pattern is hitting LuaJIT's\nspecialized table-grow + interned-short-string + C-level concat path —\nffi.copy per string genuinely loses to `out[n] = string` for repeated\nLEN fields. The 136 B/op encode floor is not a perf wall.\n\nWhat WAS in this bucket and shipped: 2ri (replace string.char(_len) with\nCHARS[_len] lookup at the inlined length-prefix sites). That captured the\nsingle hottest line the profile flagged (39% of Person_encode share) for\n+17%-34% encode throughput on 1KB+ payloads.\n\nRemaining encode-perf headroom is in c0i (C-runtime backend) — escape\npure Lua to beat the pure-Lua ceiling. Closing lkz as superseded.","status":"closed","priority":2,"issue_type":"task","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:49:16Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T16:53:34Z","closed_at":"2026-05-24T16:53:34Z","dependencies":[{"issue_id":"tarantool-protobuf-lkz","depends_on_id":"tarantool-protobuf-h8v","type":"blocks","created_at":"2026-05-18T19:49:21Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-2sn","title":"Decoder: emit table.new(N, 0) for repeated-field lists","description":"Decode result table rehashes as nested fields populate. u39 covers table.new(0, N) for the message table itself, but per-field list tables (result.emails = {}, result.lucky_numbers = {}, ...) are also bare {} and re-hash as they grow. Worth a follow-up: emit table.new(N, 0) for repeated lists where the encoded count is recoverable from a single quick scan (count tag occurrences for non-packed, or read the LEN prefix and divide by per-element size for packed). Quick scan cost vs allocation savings is the tradeoff to measure — on the 1KB Person fixture, 26 emails + 5 packed lucky_numbers means 2 re-hash cycles per repeated list. Pairs with u39 to fully close the rehash-on-grow alloc pattern.","notes":"See bench/COMPARISON.md and bd show drm. For packed scalars where per-element size is fixed (fixed32/fixed64/float/double), count = payload_len / elem_size — O(1). For varint-packed and non-packed repeated, count requires a scan; might still be net-positive on payloads with \u003e8 elements but needs measurement.","status":"closed","priority":2,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-18T16:49:15Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T10:55:08Z","started_at":"2026-05-24T10:32:45Z","closed_at":"2026-05-24T10:55:08Z","close_reason":"Closed","dependencies":[{"issue_id":"tarantool-protobuf-2sn","depends_on_id":"tarantool-protobuf-u39","type":"blocks","created_at":"2026-05-18T19:49:20Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} diff --git a/cmd/protoc-gen-tarantool/internal/gen/inline.go b/cmd/protoc-gen-tarantool/internal/gen/inline.go index fe0dd3560e930a061f7825d88fd4470756dd4631..dffec140554426beccb7575368be8828009eccf4 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/inline.go +++ b/cmd/protoc-gen-tarantool/internal/gen/inline.go @@ -100,7 +100,8 @@ w.line("function M.%s_new(t) return t or {} end", name) w.line("") emitInlineEncode(w, name, m, file, selfPath, imports, prefix, exts) - emitInlineDecode(w, name, m, file, selfPath, imports, prefix, exts) + emitInlineDecode(w, name, m, file, selfPath, imports, prefix, exts, true) + emitInlineDecode(w, name, m, file, selfPath, imports, prefix, exts, false) emitEmmyWrapperAnnotations(w, name, full, wrapperDecodeLazy) w.line("function M.%s_decode_lazy(b) return pb.decode_lazy(M.%s_descriptor, b) end", name, name) emitEmmyWrapperAnnotations(w, name, full, wrapperText) @@ -685,16 +686,20 @@ // result._extensions[full_name]. For repeated extensions, appends to the // existing list (creating it on first encounter). Mirrors // pb.codec.decode_extension but inlines the dispatch and skips the // per-call function frame. -func emitInlineDecodeExtension(w *writer, ext *protogen.Extension, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitInlineDecodeExtension(w *writer, ext *protogen.Extension, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { full := string(ext.Desc.FullName()) // Common preamble: ensure result._extensions exists. if ext.Desc.IsList() { - emitInlineDecodeExtensionRepeated(w, ext, full, file, selfPath, imports, prefix) + emitInlineDecodeExtensionRepeated(w, ext, full, file, selfPath, imports, prefix, validateUTF8) return } switch { case ext.Message != nil: - ref := typeRef(file, ext.Message.Desc, selfPath, imports, "_decode", prefix) + decodeSuffix := "_decode" + if !validateUTF8 && !isWellKnownTypeFile(ext.Message.Desc.ParentFile()) { + decodeSuffix = "_decode_unsafe" + } + ref := typeRef(file, ext.Message.Desc, selfPath, imports, decodeSuffix, prefix) if ext.Desc.Kind() == protoreflect.GroupKind { descRef := typeRef(file, ext.Message.Desc, selfPath, imports, "_descriptor", prefix) w.line(" local _payload") @@ -721,6 +726,9 @@ st := scalarName(ext.Desc.Kind()) if st == "" { panic("unhandled extension scalar kind: " + ext.Desc.Kind().String()) } + if st == "string" && !validateUTF8 { + st = "bytes" + } w.line(" local _val") w.line(" _val, pos = wire.decode_%s(buf, pos)", st) w.line(" local _e = result._extensions") @@ -733,14 +741,18 @@ // emitInlineDecodeExtensionRepeated handles the repeated branch. Uses // `#list + 1` rather than a hoisted counter — repeated extensions are // uncommon enough that adding per-extension counters at function scope // isn't worth the prelude noise. -func emitInlineDecodeExtensionRepeated(w *writer, ext *protogen.Extension, full string, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitInlineDecodeExtensionRepeated(w *writer, ext *protogen.Extension, full string, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { w.line(" local _e = result._extensions") w.line(" if _e == nil then _e = {}; result._extensions = _e end") w.line(" local _list = _e[%q]", full) w.line(" if _list == nil then _list = {}; _e[%q] = _list end", full) switch { case ext.Message != nil: - ref := typeRef(file, ext.Message.Desc, selfPath, imports, "_decode", prefix) + decodeSuffix := "_decode" + if !validateUTF8 && !isWellKnownTypeFile(ext.Message.Desc.ParentFile()) { + decodeSuffix = "_decode_unsafe" + } + ref := typeRef(file, ext.Message.Desc, selfPath, imports, decodeSuffix, prefix) if ext.Desc.Kind() == protoreflect.GroupKind { descRef := typeRef(file, ext.Message.Desc, selfPath, imports, "_descriptor", prefix) w.line(" local _payload") @@ -770,6 +782,9 @@ w.line(" end") default: st := scalarName(ext.Desc.Kind()) packable := st != "string" && st != "bytes" + if st == "string" && !validateUTF8 { + st = "bytes" + } if packable { w.line(" if wt == 2 then") w.line(" local _payload") @@ -793,15 +808,31 @@ } } } -func emitInlineDecode(w *writer, name string, m *protogen.Message, file *protogen.File, selfPath string, imports map[string]string, prefix string, exts []*protogen.Extension) { +// emitInlineDecode emits a per-message decoder. When validateUTF8 is true the +// emitted function is `_decode` (proto3-conformant — every decoded string +// field is checked with utf8_len). When false the function is +// `_decode_unsafe`, intended for re-decoding bytes produced by a trusted +// peer (typed RPC against our own encoder, JSON/text round-trips, in-process +// pipelines). The unsafe variant drops the utf8_len check at every string site +// and routes the >=128-byte fallback through wire.decode_bytes instead of +// wire.decode_string. It also skips the C runtime dispatch because the C +// runtime currently validates unconditionally (see runtime/pb/c/c_runtime.c +// is_valid_utf8 use). (6bb) +func emitInlineDecode(w *writer, name string, m *protogen.Message, file *protogen.File, selfPath string, imports map[string]string, prefix string, exts []*protogen.Extension, validateUTF8 bool) { + suffix := "_decode" + if !validateUTF8 { + suffix = "_decode_unsafe" + } emitEmmyWrapperAnnotations(w, name, emmyMessageFullName(m), wrapperDecode) - emitLocalizedFunction(w, fmt.Sprintf("function M.%s_decode(buf)", name), func() { - // C-acceleration: see emitInlineEncode for rationale and lazy-compile. + emitLocalizedFunction(w, fmt.Sprintf("function M.%s%s(buf)", name, suffix), func() { 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") + if validateUTF8 { + // C-acceleration: see emitInlineEncode for rationale and lazy-compile. + 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") @@ -847,7 +878,7 @@ op = "if" first = false } w.line(" %s id == %d then", op, f.Desc.Number()) - emitInlineDecodeFieldBody(w, f, file, selfPath, imports, prefix) + emitInlineDecodeFieldBody(w, f, file, selfPath, imports, prefix, validateUTF8) } // Static extension dispatch arms: route known extension ids // straight into inline decoders that store into @@ -860,7 +891,7 @@ op = "if" first = false } w.line(" %s id == %d then", op, ext.Desc.Number()) - emitInlineDecodeExtension(w, ext, file, selfPath, imports, prefix) + emitInlineDecodeExtension(w, ext, file, selfPath, imports, prefix, validateUTF8) } if first { // No fields — every wire byte is unknown. @@ -886,15 +917,25 @@ w.line(" return result") }) } -func emitInlineDecodeFieldBody(w *writer, f *protogen.Field, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitInlineDecodeFieldBody(w *writer, f *protogen.Field, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { fname := string(f.Desc.Name()) switch { case f.Desc.IsMap(): - emitInlineDecodeMap(w, f, fname, file, selfPath, imports, prefix) + emitInlineDecodeMap(w, f, fname, file, selfPath, imports, prefix, validateUTF8) case f.Desc.IsList(): - emitInlineDecodeRepeated(w, f, fname, file, selfPath, imports, prefix) + emitInlineDecodeRepeated(w, f, fname, file, selfPath, imports, prefix, validateUTF8) case f.Message != nil: - ref := typeRef(file, f.Message.Desc, selfPath, imports, "_decode", prefix) + // Recurse into the sub-message's matching unsafe variant when the + // caller is itself an _decode_unsafe — otherwise nested string + // fields would still be validated. WKT decoders (Timestamp, + // Duration, Any, …) live in pb.wkt and don't have an _unsafe + // twin; they're cheap (no string-validation hot path) so route + // through the normal _decode unconditionally. + decodeSuffix := "_decode" + if !validateUTF8 && !isWellKnownTypeFile(f.Message.Desc.ParentFile()) { + decodeSuffix = "_decode_unsafe" + } + ref := typeRef(file, f.Message.Desc, selfPath, imports, decodeSuffix, prefix) dst := luaFieldAccess("result", fname) descRef := typeRef(file, f.Message.Desc, selfPath, imports, "_descriptor", prefix) if f.Desc.Kind() == protoreflect.GroupKind { @@ -943,7 +984,7 @@ // frame for the typical short-string case; the resulting // straight-line code stays inside the parent JIT trace // instead of stitching through a child trace. (a6n) dst := luaFieldAccess("result", fname) - emitInlineStringBytesScalar(w, st, dst) + emitInlineStringBytesScalar(w, st, dst, validateUTF8) } else { w.line(" local val") w.line(" val, pos = wire.decode_%s(buf, pos)", st) @@ -963,7 +1004,7 @@ } } } -func emitInlineDecodeRepeated(w *writer, f *protogen.Field, fname string, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitInlineDecodeRepeated(w *writer, f *protogen.Field, fname string, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { dst := luaFieldAccess("result", fname) cnt := "_n_" + string(f.Desc.Name()) @@ -1001,7 +1042,11 @@ } switch { case f.Message != nil: - ref := typeRef(file, f.Message.Desc, selfPath, imports, "_decode", prefix) + decodeSuffix := "_decode" + if !validateUTF8 && !isWellKnownTypeFile(f.Message.Desc.ParentFile()) { + decodeSuffix = "_decode_unsafe" + } + ref := typeRef(file, f.Message.Desc, selfPath, imports, decodeSuffix, prefix) if f.Desc.Kind() == protoreflect.GroupKind { descRef := typeRef(file, f.Message.Desc, selfPath, imports, "_descriptor", prefix) w.line(" local payload") @@ -1056,7 +1101,7 @@ w.line(" %s = %s + 1; list[%s] = val", cnt, cnt, cnt) w.line(" end") } else { // Repeated string/bytes — inline 1-byte LEN fast path. (a6n) - emitInlineStringBytesRepeated(w, st, cnt) + emitInlineStringBytesRepeated(w, st, cnt, validateUTF8) } } } @@ -1077,43 +1122,54 @@ } // emitInlineStringBytesScalar emits the singular string/bytes decode with the // 1-byte LEN fast path inlined. Falls back to `wire.decode_` for lengths -// >= 128. UTF-8 validation runs only for `string`, not `bytes`. (a6n) -func emitInlineStringBytesScalar(w *writer, st, dst string) { +// >= 128. UTF-8 validation runs only for `string`, not `bytes`. When +// validateUTF8 is false the inline check is dropped and the >=128-byte +// fallback for strings is routed through wire.decode_bytes (same shape, no +// utf8_len call). (a6n, 6bb) +func emitInlineStringBytesScalar(w *writer, st, dst string, validateUTF8 bool) { + wireCall := st + if st == "string" && !validateUTF8 { + wireCall = "bytes" + } w.line(" local _lb = string_byte(buf, pos)") w.line(" if _lb ~= nil and _lb < 0x80 then") w.line(" local _np = pos + 1") w.line(" local _epos = _np + _lb") w.line(" if _epos - 1 > len then error(\"truncated LEN at offset \" .. pos, 0) end") w.line(" local _s = buf:sub(_np, _epos - 1)") - if st == "string" { + if st == "string" && validateUTF8 { w.line(" if utf8_len(_s) == nil then error(\"invalid UTF-8 in string field at offset \" .. pos, 0) end") } w.line(" %s = _s", dst) w.line(" pos = _epos") w.line(" else") w.line(" local val") - w.line(" val, pos = wire.decode_%s(buf, pos)", st) + w.line(" val, pos = wire.decode_%s(buf, pos)", wireCall) w.line(" %s = val", dst) w.line(" end") } // emitInlineStringBytesRepeated mirrors emitInlineStringBytesScalar but -// appends to the per-field list via the `_n_` counter. (a6n) -func emitInlineStringBytesRepeated(w *writer, st, cnt string) { +// appends to the per-field list via the `_n_` counter. (a6n, 6bb) +func emitInlineStringBytesRepeated(w *writer, st, cnt string, validateUTF8 bool) { + wireCall := st + if st == "string" && !validateUTF8 { + wireCall = "bytes" + } w.line(" local _lb = string_byte(buf, pos)") w.line(" if _lb ~= nil and _lb < 0x80 then") w.line(" local _np = pos + 1") w.line(" local _epos = _np + _lb") w.line(" if _epos - 1 > len then error(\"truncated LEN at offset \" .. pos, 0) end") w.line(" local _s = buf:sub(_np, _epos - 1)") - if st == "string" { + if st == "string" && validateUTF8 { w.line(" if utf8_len(_s) == nil then error(\"invalid UTF-8 in string field at offset \" .. pos, 0) end") } w.line(" %s = %s + 1; list[%s] = _s", cnt, cnt, cnt) w.line(" pos = _epos") w.line(" else") w.line(" local val") - w.line(" val, pos = wire.decode_%s(buf, pos)", st) + w.line(" val, pos = wire.decode_%s(buf, pos)", wireCall) w.line(" %s = %s + 1; list[%s] = val", cnt, cnt, cnt) w.line(" end") } @@ -1246,7 +1302,7 @@ panic("unhandled map sub-field kind: " + f.Desc.Kind().String()) } // emitInlineDecodeMap emits the decode block for a map field. -func emitInlineDecodeMap(w *writer, f *protogen.Field, fname string, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitInlineDecodeMap(w *writer, f *protogen.Field, fname string, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { keyF, valF := f.Message.Fields[0], f.Message.Fields[1] dst := luaFieldAccess("result", fname) @@ -1261,9 +1317,9 @@ w.line(" while _ep <= _elim do") w.line(" local eid, ewt") w.line(" eid, ewt, _ep = wire.decode_tag(payload, _ep)") w.line(" if eid == 1 then") - emitMapDecode(w, "_key", keyF, file, selfPath, imports, prefix) + emitMapDecode(w, "_key", keyF, file, selfPath, imports, prefix, validateUTF8) w.line(" elseif eid == 2 then") - emitMapDecode(w, "_val", valF, file, selfPath, imports, prefix) + emitMapDecode(w, "_val", valF, file, selfPath, imports, prefix, validateUTF8) w.line(" else") w.line(" _ep = wire.skip_field(payload, _ep, ewt, eid)") w.line(" end") @@ -1314,10 +1370,14 @@ } // emitMapDecode emits the per-sub-field decode body inside the map entry's // while-loop. Stores into ; advances _ep. -func emitMapDecode(w *writer, dst string, f *protogen.Field, file *protogen.File, selfPath string, imports map[string]string, prefix string) { +func emitMapDecode(w *writer, dst string, f *protogen.Field, file *protogen.File, selfPath string, imports map[string]string, prefix string, validateUTF8 bool) { switch { case f.Message != nil: - ref := typeRef(file, f.Message.Desc, selfPath, imports, "_decode", prefix) + decodeSuffix := "_decode" + if !validateUTF8 && !isWellKnownTypeFile(f.Message.Desc.ParentFile()) { + decodeSuffix = "_decode_unsafe" + } + ref := typeRef(file, f.Message.Desc, selfPath, imports, decodeSuffix, prefix) w.line(" local _payload") w.line(" _payload, _ep = wire.decode_len(payload, _ep)") w.line(" %s = %s(_payload)", dst, ref) @@ -1327,6 +1387,11 @@ w.line(" _u, _ep = wire.decode_varint(payload, _ep)") w.line(" %s = wire.varint_to_int32(_u)", dst) default: st := scalarName(f.Desc.Kind()) + // Map key/value strings on the unsafe path bypass UTF-8 validation + // by calling wire.decode_bytes (identical wire shape, no utf8_len). + if st == "string" && !validateUTF8 { + st = "bytes" + } w.line(" %s, _ep = wire.decode_%s(payload, _ep)", dst, st) } } diff --git a/docs/api-modes.md b/docs/api-modes.md index ecf54eca704756e7c4be29897e07971ce16ca4ae..9cd65d15d847be5b13381457fdc7e6f774d8d7ef 100644 --- a/docs/api-modes.md +++ b/docs/api-modes.md @@ -68,6 +68,40 @@ This is what `just bench` measures by default. The `bench/baseline.json` numbers under the "full" column are this path. +### `_decode_unsafe` — opt-out of UTF-8 validation + +For string fields, `_decode` runs `utf8.len` on every payload — the proto3 +spec demands it, and the conformance suite enforces it. When the bytes you +are decoding came from a trusted producer (typically your own encoder +across a typed RPC, JSON or text round-trip, or in-process pipeline), that +re-validation is wasted work. Full-mode codegen emits a sister +`M._decode_unsafe(buf)` alongside `_decode` that drops the check at +every string site and recurses into sub-messages' `_decode_unsafe`. + +```lua +-- Trusted source (we encoded these bytes ourselves): +local p = hello.Person_decode_unsafe(bytes) + +-- Untrusted source (arrived over the wire from a peer): keep the safe path. +local p = hello.Person_decode(bytes) +``` + +On a string-heavy ~1KB Person payload (26 emails) the unsafe variant runs +~20-30% faster end-to-end. The variant is **opt-in by an explicit function +name** rather than a per-call flag so the JIT trace shape and inlining +budget for the safe path are unchanged. The cost is generated code size: +each message with string content emits a second decoder body. + +Caveats: +- **Runtime mode does not currently emit the unsafe variant.** The + reflective path (`pb.decode`) always validates. Migrate the hot decode + to full mode if you need the unsafe path. +- **C-acceleration is bypassed in the unsafe variant** — the C runtime + validates unconditionally today, so `_decode_unsafe` skips the + `pb.c_runtime` dispatch and runs the inline Lua decoder. On payloads + where the C runtime wins, the validating `_decode` may still beat the + Lua `_decode_unsafe`; measure before adopting. + ## Runtime (descriptor-driven / reflect) The plugin's `mode=runtime` emits thin wrappers that delegate to diff --git a/examples/expected/full/c_int64/c_int64_pb.lua b/examples/expected/full/c_int64/c_int64_pb.lua index 77130a8e7b8885b56640c85d5b06da1fb5091962..d68d9e9e4061e0c907abb2e52fbc1ee0c90d56b8 100644 --- a/examples/expected/full/c_int64/c_int64_pb.lua +++ b/examples/expected/full/c_int64/c_int64_pb.lua @@ -162,6 +162,65 @@ return result end ---@param b string +---@return c_int64.Wide +function M.Wide_decode_unsafe(buf) + local _d = M.Wide_descriptor + if type(buf) ~= 'string' then + error("expected string for c_int64.Wide decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int64(buf, pos) + result.a_int64 = val + elseif id == 2 then + local val + val, pos = wire.decode_uint64(buf, pos) + result.a_uint64 = val + elseif id == 3 then + local val + val, pos = wire.decode_sint64(buf, pos) + result.a_sint64 = val + elseif id == 4 then + local val + val, pos = wire.decode_fixed64(buf, pos) + result.a_fixed64 = val + elseif id == 5 then + local val + val, pos = wire.decode_sfixed64(buf, pos) + result.a_sfixed64 = val + else + local _ebid = M.Wide_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Wide_decode_lazy(b) return pb.decode_lazy(M.Wide_descriptor, b) end ---@param t c_int64.Wide diff --git a/examples/expected/full/c_nested/c_nested_pb.lua b/examples/expected/full/c_nested/c_nested_pb.lua index c0c0044448da235356d016584e9081f8d1b96415..3b420e2e344730346ee1c74f7e678d24c43386fe 100644 --- a/examples/expected/full/c_nested/c_nested_pb.lua +++ b/examples/expected/full/c_nested/c_nested_pb.lua @@ -200,6 +200,58 @@ return result end ---@param b string +---@return c_nested.L1 +function M.L1_decode_unsafe(buf) + local _d = M.L1_descriptor + if type(buf) ~= 'string' then + error("expected string for c_nested.L1 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.next + if prev == nil then + result.next = M.L2_decode_unsafe(payload) + else + pb.codec.merge_message(M.L2_descriptor, prev, M.L2_decode_unsafe(payload)) + end + elseif id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + else + local _ebid = M.L1_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.L1_decode_lazy(b) return pb.decode_lazy(M.L1_descriptor, b) end ---@param t c_nested.L1 @@ -305,6 +357,58 @@ return result end ---@param b string +---@return c_nested.L2 +function M.L2_decode_unsafe(buf) + local _d = M.L2_descriptor + if type(buf) ~= 'string' then + error("expected string for c_nested.L2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.next + if prev == nil then + result.next = M.L3_decode_unsafe(payload) + else + pb.codec.merge_message(M.L3_descriptor, prev, M.L3_decode_unsafe(payload)) + end + elseif id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + else + local _ebid = M.L2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.L2_decode_lazy(b) return pb.decode_lazy(M.L2_descriptor, b) end ---@param t c_nested.L2 @@ -410,6 +514,58 @@ return result end ---@param b string +---@return c_nested.L3 +function M.L3_decode_unsafe(buf) + local _d = M.L3_descriptor + if type(buf) ~= 'string' then + error("expected string for c_nested.L3 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.next + if prev == nil then + result.next = M.L4_decode_unsafe(payload) + else + pb.codec.merge_message(M.L4_descriptor, prev, M.L4_decode_unsafe(payload)) + end + elseif id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + else + local _ebid = M.L3_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.L3_decode_lazy(b) return pb.decode_lazy(M.L3_descriptor, b) end ---@param t c_nested.L3 @@ -515,6 +671,58 @@ return result end ---@param b string +---@return c_nested.L4 +function M.L4_decode_unsafe(buf) + local _d = M.L4_descriptor + if type(buf) ~= 'string' then + error("expected string for c_nested.L4 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.next + if prev == nil then + result.next = M.L5_decode_unsafe(payload) + else + pb.codec.merge_message(M.L5_descriptor, prev, M.L5_decode_unsafe(payload)) + end + elseif id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + else + local _ebid = M.L4_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.L4_decode_lazy(b) return pb.decode_lazy(M.L4_descriptor, b) end ---@param t c_nested.L4 @@ -558,6 +766,49 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + else + local _ebid = M.L5_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return c_nested.L5 +function M.L5_decode_unsafe(buf) + local _d = M.L5_descriptor 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 c7b5d6a2b54d1ef2e931d4a969a07d42104ff670..8ec61fe6fc1bcc8477944efaec008cc12aeb676e 100644 --- a/examples/expected/full/c_repeated/c_repeated_pb.lua +++ b/examples/expected/full/c_repeated/c_repeated_pb.lua @@ -195,6 +195,63 @@ return result end ---@param b string +---@return c_repeated.Inner +function M.Inner_decode_unsafe(buf) + local _d = M.Inner_descriptor + if type(buf) ~= 'string' then + error("expected string for c_repeated.Inner decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.v = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.s = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.s = val + end + else + local _ebid = M.Inner_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Inner_decode_lazy(b) return pb.decode_lazy(M.Inner_descriptor, b) end ---@param t c_repeated.Inner @@ -804,6 +861,337 @@ if list == nil then list = {}; result.messages = list end local payload payload, pos = decode_len(buf, pos) _n_messages = _n_messages + 1; list[_n_messages] = M.Inner_decode(payload) + else + local _ebid = M.Holder_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return c_repeated.Holder +function M.Holder_decode_unsafe(buf) + local decode_bool = wire.decode_bool + local decode_bytes = wire.decode_bytes + local decode_double = wire.decode_double + local decode_fixed32 = wire.decode_fixed32 + local decode_fixed64 = wire.decode_fixed64 + local decode_float = wire.decode_float + local decode_int32 = wire.decode_int32 + local decode_int64 = wire.decode_int64 + local decode_len = wire.decode_len + local decode_sint32 = wire.decode_sint32 + local decode_uint32 = wire.decode_uint32 + local _d = M.Holder_descriptor + if type(buf) ~= 'string' then + error("expected string for c_repeated.Holder decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_packed_int32 = 0 + local _n_packed_int64 = 0 + local _n_packed_sint32 = 0 + local _n_packed_uint32 = 0 + local _n_packed_fixed32 = 0 + local _n_packed_fixed64 = 0 + local _n_packed_double = 0 + local _n_packed_float = 0 + local _n_packed_bool = 0 + local _n_unpacked_int32 = 0 + local _n_unpacked_fixed64 = 0 + local _n_unpacked_sint32 = 0 + local _n_strings = 0 + local _n_blobs = 0 + local _n_messages = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int32 + if list == nil then list = table_new(lim, 0); result.packed_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + else + local list = result.packed_int32 + if list == nil then list = {}; result.packed_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + elseif id == 2 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int64 + if list == nil then list = table_new(lim, 0); result.packed_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + else + local list = result.packed_int64 + if list == nil then list = {}; result.packed_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + elseif id == 3 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sint32 + if list == nil then list = table_new(lim, 0); result.packed_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + else + local list = result.packed_sint32 + if list == nil then list = {}; result.packed_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + elseif id == 4 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_uint32 + if list == nil then list = table_new(lim, 0); result.packed_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + else + local list = result.packed_uint32 + if list == nil then list = {}; result.packed_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + elseif id == 5 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + else + local list = result.packed_fixed32 + if list == nil then list = {}; result.packed_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + elseif id == 6 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + else + local list = result.packed_fixed64 + if list == nil then list = {}; result.packed_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + elseif id == 7 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + else + local list = result.packed_double + if list == nil then list = {}; result.packed_double = list end + local val + val, pos = decode_double(buf, pos) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + elseif id == 8 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + else + local list = result.packed_float + if list == nil then list = {}; result.packed_float = list end + local val + val, pos = decode_float(buf, pos) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + elseif id == 9 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_bool + if list == nil then list = table_new(lim, 0); result.packed_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + else + local list = result.packed_bool + if list == nil then list = {}; result.packed_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + elseif id == 20 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_int32 + if list == nil then list = table_new(lim, 0); result.unpacked_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + else + local list = result.unpacked_int32 + if list == nil then list = {}; result.unpacked_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + elseif id == 21 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + else + local list = result.unpacked_fixed64 + if list == nil then list = {}; result.unpacked_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + elseif id == 22 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sint32 + if list == nil then list = table_new(lim, 0); result.unpacked_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + else + local list = result.unpacked_sint32 + if list == nil then list = {}; result.unpacked_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + elseif id == 30 then + local list = result.strings + if list == nil then list = {}; result.strings = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_strings = _n_strings + 1; list[_n_strings] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_strings = _n_strings + 1; list[_n_strings] = val + end + elseif id == 31 then + local list = result.blobs + if list == nil then list = {}; result.blobs = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_blobs = _n_blobs + 1; list[_n_blobs] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_blobs = _n_blobs + 1; list[_n_blobs] = val + end + elseif id == 40 then + local list = result.messages + if list == nil then list = {}; result.messages = list end + local payload + payload, pos = decode_len(buf, pos) + _n_messages = _n_messages + 1; list[_n_messages] = M.Inner_decode_unsafe(payload) else local _ebid = M.Holder_descriptor.extensions_by_id local _ext = _ebid and _ebid[id] or nil diff --git a/examples/expected/full/conformance/conformance_pb.lua b/examples/expected/full/conformance/conformance_pb.lua index c2425ffc18569818f97f6824ff16ad35821bf696..7cc0d7d4cfe8739181a266989cc63adbf29b507c 100644 --- a/examples/expected/full/conformance/conformance_pb.lua +++ b/examples/expected/full/conformance/conformance_pb.lua @@ -347,6 +347,88 @@ return result end ---@param b string +---@return conformance.TestStatus +function M.TestStatus_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.TestStatus_descriptor + if type(buf) ~= 'string' then + error("expected string for conformance.TestStatus decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.name = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.name = val + end + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.failure_message = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.failure_message = val + end + elseif id == 3 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.matched_name = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.matched_name = val + end + else + local _ebid = M.TestStatus_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestStatus_decode_lazy(b) return pb.decode_lazy(M.TestStatus_descriptor, b) end ---@param t conformance.TestStatus @@ -426,6 +508,52 @@ if list == nil then list = {}; result.test = list end local payload payload, pos = wire.decode_len(buf, pos) _n_test = _n_test + 1; list[_n_test] = M.TestStatus_decode(payload) + else + local _ebid = M.FailureSet_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return conformance.FailureSet +function M.FailureSet_decode_unsafe(buf) + local _d = M.FailureSet_descriptor + if type(buf) ~= 'string' then + error("expected string for conformance.FailureSet decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_test = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 2 then + local list = result.test + if list == nil then list = {}; result.test = list end + local payload + payload, pos = wire.decode_len(buf, pos) + _n_test = _n_test + 1; list[_n_test] = M.TestStatus_decode_unsafe(payload) else local _ebid = M.FailureSet_descriptor.extensions_by_id local _ext = _ebid and _ebid[id] or nil @@ -738,6 +866,151 @@ return result end ---@param b string +---@return conformance.ConformanceRequest +function M.ConformanceRequest_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local decode_varint = wire.decode_varint + local varint_to_int32 = wire.varint_to_int32 + local _d = M.ConformanceRequest_descriptor + if type(buf) ~= 'string' then + error("expected string for conformance.ConformanceRequest decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.protobuf_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.protobuf_payload = val + end + result.json_payload = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.json_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.json_payload = val + end + result.protobuf_payload = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 7 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.jspb_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.jspb_payload = val + end + result.protobuf_payload = nil + result.json_payload = nil + result.text_payload = nil + elseif id == 8 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.text_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.text_payload = val + end + result.protobuf_payload = nil + result.json_payload = nil + result.jspb_payload = nil + elseif id == 3 then + local u + u, pos = decode_varint(buf, pos) + result.requested_output_format = varint_to_int32(u) + elseif id == 4 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.message_type = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.message_type = val + end + elseif id == 5 then + local u + u, pos = decode_varint(buf, pos) + result.test_category = varint_to_int32(u) + elseif id == 6 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.jspb_encoding_options + if prev == nil then + result.jspb_encoding_options = M.JspbEncodingConfig_decode_unsafe(payload) + else + pb.codec.merge_message(M.JspbEncodingConfig_descriptor, prev, M.JspbEncodingConfig_decode_unsafe(payload)) + end + elseif id == 9 then + local val + val, pos = wire.decode_bool(buf, pos) + result.print_unknown_fields = val + else + local _ebid = M.ConformanceRequest_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.ConformanceRequest_decode_lazy(b) return pb.decode_lazy(M.ConformanceRequest_descriptor, b) end ---@param t conformance.ConformanceRequest @@ -1137,6 +1410,244 @@ return result end ---@param b string +---@return conformance.ConformanceResponse +function M.ConformanceResponse_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.ConformanceResponse_descriptor + if type(buf) ~= 'string' then + error("expected string for conformance.ConformanceResponse decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.parse_error = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.parse_error = val + end + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 6 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.serialize_error = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.serialize_error = val + end + result.parse_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 9 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.timeout_error = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.timeout_error = val + end + result.parse_error = nil + result.serialize_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.runtime_error = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.runtime_error = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 3 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.protobuf_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.protobuf_payload = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 4 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.json_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.json_payload = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.skipped = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 5 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.skipped = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.skipped = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.jspb_payload = nil + result.text_payload = nil + elseif id == 7 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.jspb_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.jspb_payload = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.text_payload = nil + elseif id == 8 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.text_payload = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.text_payload = val + end + result.parse_error = nil + result.serialize_error = nil + result.timeout_error = nil + result.runtime_error = nil + result.protobuf_payload = nil + result.json_payload = nil + result.skipped = nil + result.jspb_payload = nil + else + local _ebid = M.ConformanceResponse_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.ConformanceResponse_decode_lazy(b) return pb.decode_lazy(M.ConformanceResponse_descriptor, b) end ---@param t conformance.ConformanceResponse @@ -1180,6 +1691,49 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_bool(buf, pos) + result.use_jspb_array_any_format = val + else + local _ebid = M.JspbEncodingConfig_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return conformance.JspbEncodingConfig +function M.JspbEncodingConfig_decode_unsafe(buf) + local _d = M.JspbEncodingConfig_descriptor 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 0c1874d07f3dcea7e0efd83e53e47a3f3161c96f..e1605166246fbe777a351b95dc19b5eacc3f6b41 100644 --- a/examples/expected/full/hello/hello_pb.lua +++ b/examples/expected/full/hello/hello_pb.lua @@ -357,6 +357,83 @@ return result end ---@param b string +---@return hello.Result +function M.Result_decode_unsafe(buf) + local decode_int32 = wire.decode_int32 + local _d = M.Result_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.Result decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.id = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.text = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.text = val + end + result.code = nil + result.details = nil + elseif id == 3 then + local val + val, pos = decode_int32(buf, pos) + result.code = val + result.text = nil + result.details = nil + elseif id == 4 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.details + if prev == nil then + result.details = M.Address_decode_unsafe(payload) + else + pb.codec.merge_message(M.Address_descriptor, prev, M.Address_decode_unsafe(payload)) + end + result.text = nil + result.code = nil + else + local _ebid = M.Result_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Result_decode_lazy(b) return pb.decode_lazy(M.Result_descriptor, b) end ---@param t hello.Result @@ -457,6 +534,59 @@ return result end ---@param b string +---@return hello.HelloRequest +function M.HelloRequest_decode_unsafe(buf) + local _d = M.HelloRequest_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.HelloRequest decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.name = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.name = val + end + else + local _ebid = M.HelloRequest_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.HelloRequest_decode_lazy(b) return pb.decode_lazy(M.HelloRequest_descriptor, b) end ---@param t hello.HelloRequest @@ -557,6 +687,59 @@ return result end ---@param b string +---@return hello.HelloReply +function M.HelloReply_decode_unsafe(buf) + local _d = M.HelloReply_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.HelloReply decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.greeting = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.greeting = val + end + else + local _ebid = M.HelloReply_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.HelloReply_decode_lazy(b) return pb.decode_lazy(M.HelloReply_descriptor, b) end ---@param t hello.HelloReply @@ -846,6 +1029,104 @@ return result end ---@param b string +---@return hello.Event +function M.Event_decode_unsafe(buf) + local decode_len = wire.decode_len + local _d = M.Event_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.Event decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.title = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.title = val + end + elseif id == 2 then + local payload + payload, pos = decode_len(buf, pos) + result.created_at = pb.wkt.Timestamp_decode(payload) + elseif id == 3 then + local payload + payload, pos = decode_len(buf, pos) + result.duration = pb.wkt.Duration_decode(payload) + elseif id == 4 then + local payload + payload, pos = decode_len(buf, pos) + result.ack = pb.wkt.Empty_decode(payload) + elseif id == 5 then + local payload + payload, pos = decode_len(buf, pos) + result.retry_count = pb.wkt.Int32Value_decode(payload) + elseif id == 6 then + local payload + payload, pos = decode_len(buf, pos) + result.note = pb.wkt.StringValue_decode(payload) + elseif id == 7 then + local payload + payload, pos = decode_len(buf, pos) + result.is_admin = pb.wkt.BoolValue_decode(payload) + elseif id == 8 then + local payload + payload, pos = decode_len(buf, pos) + result.payload = pb.wkt.Struct_decode(payload) + elseif id == 9 then + local payload + payload, pos = decode_len(buf, pos) + result.attribute = pb.wkt.Value_decode(payload) + elseif id == 10 then + local payload + payload, pos = decode_len(buf, pos) + result.tags = pb.wkt.ListValue_decode(payload) + elseif id == 11 then + local payload + payload, pos = decode_len(buf, pos) + result.extension = pb.wkt.Any_decode(payload) + elseif id == 12 then + local payload + payload, pos = decode_len(buf, pos) + result.update_mask = pb.wkt.FieldMask_decode(payload) + else + local _ebid = M.Event_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Event_decode_lazy(b) return pb.decode_lazy(M.Event_descriptor, b) end ---@param t hello.Event @@ -1012,6 +1293,92 @@ return result end ---@param b string +---@return hello.Address +function M.Address_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.Address_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.Address decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.street = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.street = val + end + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.city = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.city = val + end + elseif id == 3 then + local val + val, pos = wire.decode_int32(buf, pos) + result.zip = val + elseif id == 4 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.apartment = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.apartment = val + end + else + local _ebid = M.Address_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Address_decode_lazy(b) return pb.decode_lazy(M.Address_descriptor, b) end ---@param t hello.Address @@ -1442,6 +1809,210 @@ elseif eid == 2 then local _payload _payload, _ep = decode_len(payload, _ep) _val = M.Address_decode(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + else + local _ebid = M.Person_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return hello.Person +function M.Person_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local decode_int32 = wire.decode_int32 + local decode_len = wire.decode_len + local decode_tag = wire.decode_tag + local skip_field = wire.skip_field + local _d = M.Person_descriptor + if type(buf) ~= 'string' then + error("expected string for hello.Person decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_emails = 0 + local _n_friends = 0 + local _n_lucky_numbers = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.name = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.name = val + end + elseif id == 2 then + local val + val, pos = decode_int32(buf, pos) + result.age = val + elseif id == 3 then + local list = result.emails + if list == nil then list = {}; result.emails = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_emails = _n_emails + 1; list[_n_emails] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_emails = _n_emails + 1; list[_n_emails] = val + end + elseif id == 4 then + local u + u, pos = wire.decode_varint(buf, pos) + result.status = wire.varint_to_int32(u) + elseif id == 5 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.address + if prev == nil then + result.address = M.Address_decode_unsafe(payload) + else + pb.codec.merge_message(M.Address_descriptor, prev, M.Address_decode_unsafe(payload)) + end + elseif id == 6 then + local list = result.friends + if list == nil then list = {}; result.friends = list end + local payload + payload, pos = decode_len(buf, pos) + _n_friends = _n_friends + 1; list[_n_friends] = M.Person_decode_unsafe(payload) + elseif id == 7 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.lucky_numbers + if list == nil then list = table_new(lim, 0); result.lucky_numbers = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_lucky_numbers = _n_lucky_numbers + 1; list[_n_lucky_numbers] = val + end + else + local list = result.lucky_numbers + if list == nil then list = {}; result.lucky_numbers = list end + local val + val, pos = decode_int32(buf, pos) + _n_lucky_numbers = _n_lucky_numbers + 1; list[_n_lucky_numbers] = val + end + elseif id == 8 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.avatar = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.avatar = val + end + elseif id == 9 then + local val + val, pos = wire.decode_fixed64(buf, pos) + result.user_id = val + elseif id == 10 then + local val + val, pos = wire.decode_sint32(buf, pos) + result.balance = val + elseif id == 11 then + local val + val, pos = wire.decode_double(buf, pos) + result.weight_kg = val + elseif id == 13 then + local map = result.ages_by_nickname + if map == nil then map = {}; result.ages_by_nickname = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_int32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 14 then + local map = result.nickname_by_age + if map == nil then map = {}; result.nickname_by_age = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, '' + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bytes(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 15 then + local map = result.addresses_by_label + if map == nil then map = {}; result.addresses_by_label = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.Address_decode_unsafe(_payload) else _ep = skip_field(payload, _ep, ewt, eid) end diff --git a/examples/expected/full/proto2_basic/proto2_basic_pb.lua b/examples/expected/full/proto2_basic/proto2_basic_pb.lua index 3e40529265347455a26b7c97f3362a894578f8a2..fde484f61157cf32a0e9a3fd1e4c85e2e46f8fbc 100644 --- a/examples/expected/full/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/full/proto2_basic/proto2_basic_pb.lua @@ -432,6 +432,102 @@ return result end ---@param b string +---@return proto2_basic.Defaults +function M.Defaults_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.Defaults_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.Defaults decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.i = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.s = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.s = val + end + elseif id == 3 then + local val + val, pos = wire.decode_bool(buf, pos) + result.b = val + elseif id == 4 then + local val + val, pos = wire.decode_float(buf, pos) + result.f = val + elseif id == 5 then + local val + val, pos = wire.decode_double(buf, pos) + result.d = val + elseif id == 6 then + local val + val, pos = wire.decode_int64(buf, pos) + result.i64 = val + elseif id == 7 then + local val + val, pos = wire.decode_uint64(buf, pos) + result.u64 = val + elseif id == 8 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.by = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.by = val + end + elseif id == 9 then + local u + u, pos = wire.decode_varint(buf, pos) + result.color = wire.varint_to_int32(u) + else + local _ebid = M.Defaults_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Defaults_decode_lazy(b) return pb.decode_lazy(M.Defaults_descriptor, b) end ---@param t proto2_basic.Defaults @@ -675,6 +771,115 @@ return result end ---@param b string +---@return proto2_basic.Cardinality +function M.Cardinality_decode_unsafe(buf) + local decode_int32 = wire.decode_int32 + local decode_len = wire.decode_len + local _d = M.Cardinality_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.Cardinality decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_packed_default = 0 + local _n_explicitly_packed = 0 + local _n_explicitly_unpacked = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.r = val + elseif id == 2 then + local val + val, pos = decode_int32(buf, pos) + result.o = val + elseif id == 3 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_default + if list == nil then list = table_new(lim, 0); result.packed_default = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_packed_default = _n_packed_default + 1; list[_n_packed_default] = val + end + else + local list = result.packed_default + if list == nil then list = {}; result.packed_default = list end + local val + val, pos = decode_int32(buf, pos) + _n_packed_default = _n_packed_default + 1; list[_n_packed_default] = val + end + elseif id == 4 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.explicitly_packed + if list == nil then list = table_new(lim, 0); result.explicitly_packed = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_explicitly_packed = _n_explicitly_packed + 1; list[_n_explicitly_packed] = val + end + else + local list = result.explicitly_packed + if list == nil then list = {}; result.explicitly_packed = list end + local val + val, pos = decode_int32(buf, pos) + _n_explicitly_packed = _n_explicitly_packed + 1; list[_n_explicitly_packed] = val + end + elseif id == 5 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.explicitly_unpacked + if list == nil then list = table_new(lim, 0); result.explicitly_unpacked = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_explicitly_unpacked = _n_explicitly_unpacked + 1; list[_n_explicitly_unpacked] = val + end + else + local list = result.explicitly_unpacked + if list == nil then list = {}; result.explicitly_unpacked = list end + local val + val, pos = decode_int32(buf, pos) + _n_explicitly_unpacked = _n_explicitly_unpacked + 1; list[_n_explicitly_unpacked] = val + end + else + local _ebid = M.Cardinality_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Cardinality_decode_lazy(b) return pb.decode_lazy(M.Cardinality_descriptor, b) end ---@param t proto2_basic.Cardinality @@ -800,6 +1005,64 @@ return result end ---@param b string +---@return proto2_basic.Nested +function M.Nested_decode_unsafe(buf) + local decode_len = wire.decode_len + local _d = M.Nested_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.Nested decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.inner + if prev == nil then + result.inner = M.Nested_Inner_decode_unsafe(payload) + else + pb.codec.merge_message(M.Nested_Inner_descriptor, prev, M.Nested_Inner_decode_unsafe(payload)) + end + elseif id == 2 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.inner_opt + if prev == nil then + result.inner_opt = M.Nested_Inner_decode_unsafe(payload) + else + pb.codec.merge_message(M.Nested_Inner_descriptor, prev, M.Nested_Inner_decode_unsafe(payload)) + end + else + local _ebid = M.Nested_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.Nested_decode_lazy(b) return pb.decode_lazy(M.Nested_descriptor, b) end ---@param t proto2_basic.Nested @@ -849,6 +1112,49 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.x = val + else + local _ebid = M.Nested_Inner_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return proto2_basic.Nested.Inner +function M.Nested_Inner_decode_unsafe(buf) + local _d = M.Nested_Inner_descriptor if type(buf) ~= 'string' then error("expected string for proto2_basic.Nested.Inner decode, got " .. type(buf), 0) end @@ -996,6 +1302,61 @@ return result end ---@param b string +---@return proto2_basic.WithGroup +function M.WithGroup_decode_unsafe(buf) + local _d = M.WithGroup_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.WithGroup decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_repgroup = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = pb.codec.decode_group(M.WithGroup_SingleGroup_descriptor, buf, pos, 1) + local prev = result.singlegroup + if prev == nil then + result.singlegroup = payload + else + pb.codec.merge_message(M.WithGroup_SingleGroup_descriptor, prev, payload) + end + elseif id == 4 then + local list = result.repgroup + if list == nil then list = {}; result.repgroup = list end + local payload + payload, pos = pb.codec.decode_group(M.WithGroup_RepGroup_descriptor, buf, pos, 4) + _n_repgroup = _n_repgroup + 1; list[_n_repgroup] = payload + else + local _ebid = M.WithGroup_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.WithGroup_decode_lazy(b) return pb.decode_lazy(M.WithGroup_descriptor, b) end ---@param t proto2_basic.WithGroup @@ -1111,6 +1472,63 @@ return result end ---@param b string +---@return proto2_basic.WithGroup.SingleGroup +function M.WithGroup_SingleGroup_decode_unsafe(buf) + local _d = M.WithGroup_SingleGroup_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.WithGroup.SingleGroup decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.a = val + elseif id == 3 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.s = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.s = val + end + else + local _ebid = M.WithGroup_SingleGroup_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.WithGroup_SingleGroup_decode_lazy(b) return pb.decode_lazy(M.WithGroup_SingleGroup_descriptor, b) end ---@param t proto2_basic.WithGroup.SingleGroup @@ -1204,6 +1622,49 @@ return result end ---@param b string +---@return proto2_basic.WithGroup.RepGroup +function M.WithGroup_RepGroup_decode_unsafe(buf) + local _d = M.WithGroup_RepGroup_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.WithGroup.RepGroup decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 5 then + local val + val, pos = wire.decode_int32(buf, pos) + result.n = val + else + local _ebid = M.WithGroup_RepGroup_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.WithGroup_RepGroup_decode_lazy(b) return pb.decode_lazy(M.WithGroup_RepGroup_descriptor, b) end ---@param t proto2_basic.WithGroup.RepGroup @@ -1498,6 +1959,137 @@ return result end ---@param b string +---@return proto2_basic.BenchPayload +function M.BenchPayload_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local decode_int32 = wire.decode_int32 + local decode_len = wire.decode_len + local _d = M.BenchPayload_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.BenchPayload decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_lucky_numbers = 0 + local _n_tags = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.id = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.name = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.name = val + end + elseif id == 3 then + local val + val, pos = decode_int32(buf, pos) + result.retries = val + elseif id == 4 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.lucky_numbers + if list == nil then list = table_new(lim, 0); result.lucky_numbers = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_lucky_numbers = _n_lucky_numbers + 1; list[_n_lucky_numbers] = val + end + else + local list = result.lucky_numbers + if list == nil then list = {}; result.lucky_numbers = list end + local val + val, pos = decode_int32(buf, pos) + _n_lucky_numbers = _n_lucky_numbers + 1; list[_n_lucky_numbers] = val + end + elseif id == 5 then + local list = result.tags + if list == nil then list = {}; result.tags = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_tags = _n_tags + 1; list[_n_tags] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_tags = _n_tags + 1; list[_n_tags] = val + end + elseif id == 6 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.inner + if prev == nil then + result.inner = M.BenchPayload_Inner_decode_unsafe(payload) + else + pb.codec.merge_message(M.BenchPayload_Inner_descriptor, prev, M.BenchPayload_Inner_decode_unsafe(payload)) + end + elseif id == 7 then + local payload + payload, pos = pb.codec.decode_group(M.BenchPayload_Stats_descriptor, buf, pos, 7) + local prev = result.stats + if prev == nil then + result.stats = payload + else + pb.codec.merge_message(M.BenchPayload_Stats_descriptor, prev, payload) + end + elseif id == 100 then + local _val + _val, pos = decode_int32(buf, pos) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["proto2_basic.ext_count"] = _val + elseif id == 101 then + local _val + _val, pos = decode_bytes(buf, pos) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["proto2_basic.ext_label"] = _val + else + local _ebid = M.BenchPayload_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.BenchPayload_decode_lazy(b) return pb.decode_lazy(M.BenchPayload_descriptor, b) end ---@param t proto2_basic.BenchPayload @@ -1613,6 +2205,54 @@ return result end ---@param b string +---@return proto2_basic.BenchPayload.Stats +function M.BenchPayload_Stats_decode_unsafe(buf) + local decode_int32 = wire.decode_int32 + local _d = M.BenchPayload_Stats_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.BenchPayload.Stats decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 8 then + local val + val, pos = decode_int32(buf, pos) + result.latency_ns = val + elseif id == 9 then + local val + val, pos = decode_int32(buf, pos) + result.attempts = val + else + local _ebid = M.BenchPayload_Stats_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.BenchPayload_Stats_decode_lazy(b) return pb.decode_lazy(M.BenchPayload_Stats_descriptor, b) end ---@param t proto2_basic.BenchPayload.Stats @@ -1711,6 +2351,63 @@ pos = _epos else local val val, pos = wire.decode_string(buf, pos) + result.key = val + end + elseif id == 2 then + local val + val, pos = wire.decode_int32(buf, pos) + result.weight = val + else + local _ebid = M.BenchPayload_Inner_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return proto2_basic.BenchPayload.Inner +function M.BenchPayload_Inner_decode_unsafe(buf) + local _d = M.BenchPayload_Inner_descriptor + if type(buf) ~= 'string' then + error("expected string for proto2_basic.BenchPayload.Inner decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.key = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) result.key = val end elseif id == 2 then 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 d3c395788a1fa320f69d11707297031d353a595d..2697a27654a37ac1ef1bd40127b3691c4eaaa0b3 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 @@ -4643,6 +4643,1900 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllTypesProto2 +function M.TestAllTypesProto2_decode_unsafe(buf) + local decode_bool = wire.decode_bool + local decode_bytes = wire.decode_bytes + local decode_double = wire.decode_double + local decode_fixed32 = wire.decode_fixed32 + local decode_fixed64 = wire.decode_fixed64 + local decode_float = wire.decode_float + local decode_int32 = wire.decode_int32 + local decode_int64 = wire.decode_int64 + local decode_len = wire.decode_len + local decode_sfixed32 = wire.decode_sfixed32 + local decode_sfixed64 = wire.decode_sfixed64 + local decode_sint32 = wire.decode_sint32 + local decode_sint64 = wire.decode_sint64 + local decode_tag = wire.decode_tag + local decode_uint32 = wire.decode_uint32 + local decode_uint64 = wire.decode_uint64 + local decode_varint = wire.decode_varint + local skip_field = wire.skip_field + local varint_to_int32 = wire.varint_to_int32 + local _d = M.TestAllTypesProto2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_repeated_int32 = 0 + local _n_repeated_int64 = 0 + local _n_repeated_uint32 = 0 + local _n_repeated_uint64 = 0 + local _n_repeated_sint32 = 0 + local _n_repeated_sint64 = 0 + local _n_repeated_fixed32 = 0 + local _n_repeated_fixed64 = 0 + local _n_repeated_sfixed32 = 0 + local _n_repeated_sfixed64 = 0 + local _n_repeated_float = 0 + local _n_repeated_double = 0 + local _n_repeated_bool = 0 + local _n_repeated_string = 0 + local _n_repeated_bytes = 0 + local _n_repeated_nested_message = 0 + local _n_repeated_foreign_message = 0 + local _n_repeated_nested_enum = 0 + local _n_repeated_foreign_enum = 0 + local _n_repeated_string_piece = 0 + local _n_repeated_cord = 0 + local _n_packed_int32 = 0 + local _n_packed_int64 = 0 + local _n_packed_uint32 = 0 + local _n_packed_uint64 = 0 + local _n_packed_sint32 = 0 + local _n_packed_sint64 = 0 + local _n_packed_fixed32 = 0 + local _n_packed_fixed64 = 0 + local _n_packed_sfixed32 = 0 + local _n_packed_sfixed64 = 0 + local _n_packed_float = 0 + local _n_packed_double = 0 + local _n_packed_bool = 0 + local _n_packed_nested_enum = 0 + local _n_unpacked_int32 = 0 + local _n_unpacked_int64 = 0 + local _n_unpacked_uint32 = 0 + local _n_unpacked_uint64 = 0 + local _n_unpacked_sint32 = 0 + local _n_unpacked_sint64 = 0 + local _n_unpacked_fixed32 = 0 + local _n_unpacked_fixed64 = 0 + local _n_unpacked_sfixed32 = 0 + local _n_unpacked_sfixed64 = 0 + local _n_unpacked_float = 0 + local _n_unpacked_double = 0 + local _n_unpacked_bool = 0 + local _n_unpacked_nested_enum = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.optional_int32 = val + elseif id == 2 then + local val + val, pos = decode_int64(buf, pos) + result.optional_int64 = val + elseif id == 3 then + local val + val, pos = decode_uint32(buf, pos) + result.optional_uint32 = val + elseif id == 4 then + local val + val, pos = decode_uint64(buf, pos) + result.optional_uint64 = val + elseif id == 5 then + local val + val, pos = decode_sint32(buf, pos) + result.optional_sint32 = val + elseif id == 6 then + local val + val, pos = decode_sint64(buf, pos) + result.optional_sint64 = val + elseif id == 7 then + local val + val, pos = decode_fixed32(buf, pos) + result.optional_fixed32 = val + elseif id == 8 then + local val + val, pos = decode_fixed64(buf, pos) + result.optional_fixed64 = val + elseif id == 9 then + local val + val, pos = decode_sfixed32(buf, pos) + result.optional_sfixed32 = val + elseif id == 10 then + local val + val, pos = decode_sfixed64(buf, pos) + result.optional_sfixed64 = val + elseif id == 11 then + local val + val, pos = decode_float(buf, pos) + result.optional_float = val + elseif id == 12 then + local val + val, pos = decode_double(buf, pos) + result.optional_double = val + elseif id == 13 then + local val + val, pos = decode_bool(buf, pos) + result.optional_bool = val + elseif id == 14 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_string = val + end + elseif id == 15 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_bytes = val + end + elseif id == 18 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_nested_message + if prev == nil then + result.optional_nested_message = M.TestAllTypesProto2_NestedMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto2_NestedMessage_descriptor, prev, M.TestAllTypesProto2_NestedMessage_decode_unsafe(payload)) + end + elseif id == 19 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_foreign_message + if prev == nil then + result.optional_foreign_message = M.ForeignMessageProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.ForeignMessageProto2_descriptor, prev, M.ForeignMessageProto2_decode_unsafe(payload)) + end + elseif id == 21 then + local u + u, pos = decode_varint(buf, pos) + result.optional_nested_enum = varint_to_int32(u) + elseif id == 22 then + local u + u, pos = decode_varint(buf, pos) + result.optional_foreign_enum = varint_to_int32(u) + elseif id == 24 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_string_piece = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_string_piece = val + end + elseif id == 25 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_cord = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_cord = val + end + elseif id == 27 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.recursive_message + if prev == nil then + result.recursive_message = M.TestAllTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto2_descriptor, prev, M.TestAllTypesProto2_decode_unsafe(payload)) + end + elseif id == 31 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_int32 + if list == nil then list = table_new(lim, 0); result.repeated_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + else + local list = result.repeated_int32 + if list == nil then list = {}; result.repeated_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + elseif id == 32 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_int64 + if list == nil then list = table_new(lim, 0); result.repeated_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_repeated_int64 = _n_repeated_int64 + 1; list[_n_repeated_int64] = val + end + else + local list = result.repeated_int64 + if list == nil then list = {}; result.repeated_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_repeated_int64 = _n_repeated_int64 + 1; list[_n_repeated_int64] = val + end + elseif id == 33 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_uint32 + if list == nil then list = table_new(lim, 0); result.repeated_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_repeated_uint32 = _n_repeated_uint32 + 1; list[_n_repeated_uint32] = val + end + else + local list = result.repeated_uint32 + if list == nil then list = {}; result.repeated_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_repeated_uint32 = _n_repeated_uint32 + 1; list[_n_repeated_uint32] = val + end + elseif id == 34 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_uint64 + if list == nil then list = table_new(lim, 0); result.repeated_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_repeated_uint64 = _n_repeated_uint64 + 1; list[_n_repeated_uint64] = val + end + else + local list = result.repeated_uint64 + if list == nil then list = {}; result.repeated_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_repeated_uint64 = _n_repeated_uint64 + 1; list[_n_repeated_uint64] = val + end + elseif id == 35 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sint32 + if list == nil then list = table_new(lim, 0); result.repeated_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_repeated_sint32 = _n_repeated_sint32 + 1; list[_n_repeated_sint32] = val + end + else + local list = result.repeated_sint32 + if list == nil then list = {}; result.repeated_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_repeated_sint32 = _n_repeated_sint32 + 1; list[_n_repeated_sint32] = val + end + elseif id == 36 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sint64 + if list == nil then list = table_new(lim, 0); result.repeated_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_repeated_sint64 = _n_repeated_sint64 + 1; list[_n_repeated_sint64] = val + end + else + local list = result.repeated_sint64 + if list == nil then list = {}; result.repeated_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_repeated_sint64 = _n_repeated_sint64 + 1; list[_n_repeated_sint64] = val + end + elseif id == 37 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_repeated_fixed32 = _n_repeated_fixed32 + 1; list[_n_repeated_fixed32] = val + end + else + local list = result.repeated_fixed32 + if list == nil then list = {}; result.repeated_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_repeated_fixed32 = _n_repeated_fixed32 + 1; list[_n_repeated_fixed32] = val + end + elseif id == 38 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_repeated_fixed64 = _n_repeated_fixed64 + 1; list[_n_repeated_fixed64] = val + end + else + local list = result.repeated_fixed64 + if list == nil then list = {}; result.repeated_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_repeated_fixed64 = _n_repeated_fixed64 + 1; list[_n_repeated_fixed64] = val + end + elseif id == 39 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_repeated_sfixed32 = _n_repeated_sfixed32 + 1; list[_n_repeated_sfixed32] = val + end + else + local list = result.repeated_sfixed32 + if list == nil then list = {}; result.repeated_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_repeated_sfixed32 = _n_repeated_sfixed32 + 1; list[_n_repeated_sfixed32] = val + end + elseif id == 40 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_repeated_sfixed64 = _n_repeated_sfixed64 + 1; list[_n_repeated_sfixed64] = val + end + else + local list = result.repeated_sfixed64 + if list == nil then list = {}; result.repeated_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_repeated_sfixed64 = _n_repeated_sfixed64 + 1; list[_n_repeated_sfixed64] = val + end + elseif id == 41 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_repeated_float = _n_repeated_float + 1; list[_n_repeated_float] = val + end + else + local list = result.repeated_float + if list == nil then list = {}; result.repeated_float = list end + local val + val, pos = decode_float(buf, pos) + _n_repeated_float = _n_repeated_float + 1; list[_n_repeated_float] = val + end + elseif id == 42 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_repeated_double = _n_repeated_double + 1; list[_n_repeated_double] = val + end + else + local list = result.repeated_double + if list == nil then list = {}; result.repeated_double = list end + local val + val, pos = decode_double(buf, pos) + _n_repeated_double = _n_repeated_double + 1; list[_n_repeated_double] = val + end + elseif id == 43 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_bool + if list == nil then list = table_new(lim, 0); result.repeated_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_repeated_bool = _n_repeated_bool + 1; list[_n_repeated_bool] = val + end + else + local list = result.repeated_bool + if list == nil then list = {}; result.repeated_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_repeated_bool = _n_repeated_bool + 1; list[_n_repeated_bool] = val + end + elseif id == 44 then + local list = result.repeated_string + if list == nil then list = {}; result.repeated_string = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_string = _n_repeated_string + 1; list[_n_repeated_string] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_string = _n_repeated_string + 1; list[_n_repeated_string] = val + end + elseif id == 45 then + local list = result.repeated_bytes + if list == nil then list = {}; result.repeated_bytes = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_bytes = _n_repeated_bytes + 1; list[_n_repeated_bytes] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_bytes = _n_repeated_bytes + 1; list[_n_repeated_bytes] = val + end + elseif id == 48 then + local list = result.repeated_nested_message + if list == nil then list = {}; result.repeated_nested_message = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_nested_message = _n_repeated_nested_message + 1; list[_n_repeated_nested_message] = M.TestAllTypesProto2_NestedMessage_decode_unsafe(payload) + elseif id == 49 then + local list = result.repeated_foreign_message + if list == nil then list = {}; result.repeated_foreign_message = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_foreign_message = _n_repeated_foreign_message + 1; list[_n_repeated_foreign_message] = M.ForeignMessageProto2_decode_unsafe(payload) + elseif id == 51 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_nested_enum + if list == nil then list = table_new(lim, 0); result.repeated_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_repeated_nested_enum = _n_repeated_nested_enum + 1; list[_n_repeated_nested_enum] = varint_to_int32(u) + end + else + local list = result.repeated_nested_enum + if list == nil then list = {}; result.repeated_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_repeated_nested_enum = _n_repeated_nested_enum + 1; list[_n_repeated_nested_enum] = varint_to_int32(u) + end + elseif id == 52 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_foreign_enum + if list == nil then list = table_new(lim, 0); result.repeated_foreign_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_repeated_foreign_enum = _n_repeated_foreign_enum + 1; list[_n_repeated_foreign_enum] = varint_to_int32(u) + end + else + local list = result.repeated_foreign_enum + if list == nil then list = {}; result.repeated_foreign_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_repeated_foreign_enum = _n_repeated_foreign_enum + 1; list[_n_repeated_foreign_enum] = varint_to_int32(u) + end + elseif id == 54 then + local list = result.repeated_string_piece + if list == nil then list = {}; result.repeated_string_piece = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_string_piece = _n_repeated_string_piece + 1; list[_n_repeated_string_piece] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_string_piece = _n_repeated_string_piece + 1; list[_n_repeated_string_piece] = val + end + elseif id == 55 then + local list = result.repeated_cord + if list == nil then list = {}; result.repeated_cord = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_cord = _n_repeated_cord + 1; list[_n_repeated_cord] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_cord = _n_repeated_cord + 1; list[_n_repeated_cord] = val + end + elseif id == 75 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int32 + if list == nil then list = table_new(lim, 0); result.packed_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + else + local list = result.packed_int32 + if list == nil then list = {}; result.packed_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + elseif id == 76 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int64 + if list == nil then list = table_new(lim, 0); result.packed_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + else + local list = result.packed_int64 + if list == nil then list = {}; result.packed_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + elseif id == 77 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_uint32 + if list == nil then list = table_new(lim, 0); result.packed_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + else + local list = result.packed_uint32 + if list == nil then list = {}; result.packed_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + elseif id == 78 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_uint64 + if list == nil then list = table_new(lim, 0); result.packed_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_packed_uint64 = _n_packed_uint64 + 1; list[_n_packed_uint64] = val + end + else + local list = result.packed_uint64 + if list == nil then list = {}; result.packed_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_packed_uint64 = _n_packed_uint64 + 1; list[_n_packed_uint64] = val + end + elseif id == 79 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sint32 + if list == nil then list = table_new(lim, 0); result.packed_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + else + local list = result.packed_sint32 + if list == nil then list = {}; result.packed_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + elseif id == 80 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sint64 + if list == nil then list = table_new(lim, 0); result.packed_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_packed_sint64 = _n_packed_sint64 + 1; list[_n_packed_sint64] = val + end + else + local list = result.packed_sint64 + if list == nil then list = {}; result.packed_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_packed_sint64 = _n_packed_sint64 + 1; list[_n_packed_sint64] = val + end + elseif id == 81 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + else + local list = result.packed_fixed32 + if list == nil then list = {}; result.packed_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + elseif id == 82 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + else + local list = result.packed_fixed64 + if list == nil then list = {}; result.packed_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + elseif id == 83 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_packed_sfixed32 = _n_packed_sfixed32 + 1; list[_n_packed_sfixed32] = val + end + else + local list = result.packed_sfixed32 + if list == nil then list = {}; result.packed_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_packed_sfixed32 = _n_packed_sfixed32 + 1; list[_n_packed_sfixed32] = val + end + elseif id == 84 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_packed_sfixed64 = _n_packed_sfixed64 + 1; list[_n_packed_sfixed64] = val + end + else + local list = result.packed_sfixed64 + if list == nil then list = {}; result.packed_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_packed_sfixed64 = _n_packed_sfixed64 + 1; list[_n_packed_sfixed64] = val + end + elseif id == 85 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + else + local list = result.packed_float + if list == nil then list = {}; result.packed_float = list end + local val + val, pos = decode_float(buf, pos) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + elseif id == 86 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + else + local list = result.packed_double + if list == nil then list = {}; result.packed_double = list end + local val + val, pos = decode_double(buf, pos) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + elseif id == 87 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_bool + if list == nil then list = table_new(lim, 0); result.packed_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + else + local list = result.packed_bool + if list == nil then list = {}; result.packed_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + elseif id == 88 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_nested_enum + if list == nil then list = table_new(lim, 0); result.packed_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_packed_nested_enum = _n_packed_nested_enum + 1; list[_n_packed_nested_enum] = varint_to_int32(u) + end + else + local list = result.packed_nested_enum + if list == nil then list = {}; result.packed_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_packed_nested_enum = _n_packed_nested_enum + 1; list[_n_packed_nested_enum] = varint_to_int32(u) + end + elseif id == 89 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_int32 + if list == nil then list = table_new(lim, 0); result.unpacked_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + else + local list = result.unpacked_int32 + if list == nil then list = {}; result.unpacked_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + elseif id == 90 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_int64 + if list == nil then list = table_new(lim, 0); result.unpacked_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_unpacked_int64 = _n_unpacked_int64 + 1; list[_n_unpacked_int64] = val + end + else + local list = result.unpacked_int64 + if list == nil then list = {}; result.unpacked_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_unpacked_int64 = _n_unpacked_int64 + 1; list[_n_unpacked_int64] = val + end + elseif id == 91 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_uint32 + if list == nil then list = table_new(lim, 0); result.unpacked_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_unpacked_uint32 = _n_unpacked_uint32 + 1; list[_n_unpacked_uint32] = val + end + else + local list = result.unpacked_uint32 + if list == nil then list = {}; result.unpacked_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_unpacked_uint32 = _n_unpacked_uint32 + 1; list[_n_unpacked_uint32] = val + end + elseif id == 92 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_uint64 + if list == nil then list = table_new(lim, 0); result.unpacked_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_unpacked_uint64 = _n_unpacked_uint64 + 1; list[_n_unpacked_uint64] = val + end + else + local list = result.unpacked_uint64 + if list == nil then list = {}; result.unpacked_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_unpacked_uint64 = _n_unpacked_uint64 + 1; list[_n_unpacked_uint64] = val + end + elseif id == 93 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sint32 + if list == nil then list = table_new(lim, 0); result.unpacked_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + else + local list = result.unpacked_sint32 + if list == nil then list = {}; result.unpacked_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + elseif id == 94 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sint64 + if list == nil then list = table_new(lim, 0); result.unpacked_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_unpacked_sint64 = _n_unpacked_sint64 + 1; list[_n_unpacked_sint64] = val + end + else + local list = result.unpacked_sint64 + if list == nil then list = {}; result.unpacked_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_unpacked_sint64 = _n_unpacked_sint64 + 1; list[_n_unpacked_sint64] = val + end + elseif id == 95 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_unpacked_fixed32 = _n_unpacked_fixed32 + 1; list[_n_unpacked_fixed32] = val + end + else + local list = result.unpacked_fixed32 + if list == nil then list = {}; result.unpacked_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_unpacked_fixed32 = _n_unpacked_fixed32 + 1; list[_n_unpacked_fixed32] = val + end + elseif id == 96 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + else + local list = result.unpacked_fixed64 + if list == nil then list = {}; result.unpacked_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + elseif id == 97 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_unpacked_sfixed32 = _n_unpacked_sfixed32 + 1; list[_n_unpacked_sfixed32] = val + end + else + local list = result.unpacked_sfixed32 + if list == nil then list = {}; result.unpacked_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_unpacked_sfixed32 = _n_unpacked_sfixed32 + 1; list[_n_unpacked_sfixed32] = val + end + elseif id == 98 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_unpacked_sfixed64 = _n_unpacked_sfixed64 + 1; list[_n_unpacked_sfixed64] = val + end + else + local list = result.unpacked_sfixed64 + if list == nil then list = {}; result.unpacked_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_unpacked_sfixed64 = _n_unpacked_sfixed64 + 1; list[_n_unpacked_sfixed64] = val + end + elseif id == 99 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_unpacked_float = _n_unpacked_float + 1; list[_n_unpacked_float] = val + end + else + local list = result.unpacked_float + if list == nil then list = {}; result.unpacked_float = list end + local val + val, pos = decode_float(buf, pos) + _n_unpacked_float = _n_unpacked_float + 1; list[_n_unpacked_float] = val + end + elseif id == 100 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_unpacked_double = _n_unpacked_double + 1; list[_n_unpacked_double] = val + end + else + local list = result.unpacked_double + if list == nil then list = {}; result.unpacked_double = list end + local val + val, pos = decode_double(buf, pos) + _n_unpacked_double = _n_unpacked_double + 1; list[_n_unpacked_double] = val + end + elseif id == 101 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_bool + if list == nil then list = table_new(lim, 0); result.unpacked_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_unpacked_bool = _n_unpacked_bool + 1; list[_n_unpacked_bool] = val + end + else + local list = result.unpacked_bool + if list == nil then list = {}; result.unpacked_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_unpacked_bool = _n_unpacked_bool + 1; list[_n_unpacked_bool] = val + end + elseif id == 102 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_nested_enum + if list == nil then list = table_new(lim, 0); result.unpacked_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_unpacked_nested_enum = _n_unpacked_nested_enum + 1; list[_n_unpacked_nested_enum] = varint_to_int32(u) + end + else + local list = result.unpacked_nested_enum + if list == nil then list = {}; result.unpacked_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_unpacked_nested_enum = _n_unpacked_nested_enum + 1; list[_n_unpacked_nested_enum] = varint_to_int32(u) + end + elseif id == 56 then + local map = result.map_int32_int32 + if map == nil then map = {}; result.map_int32_int32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_int32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 57 then + local map = result.map_int64_int64 + if map == nil then map = {}; result.map_int64_int64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_int64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 58 then + local map = result.map_uint32_uint32 + if map == nil then map = {}; result.map_uint32_uint32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_uint32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_uint32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 59 then + local map = result.map_uint64_uint64 + if map == nil then map = {}; result.map_uint64_uint64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_uint64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_uint64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 60 then + local map = result.map_sint32_sint32 + if map == nil then map = {}; result.map_sint32_sint32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sint32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sint32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 61 then + local map = result.map_sint64_sint64 + if map == nil then map = {}; result.map_sint64_sint64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sint64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sint64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 62 then + local map = result.map_fixed32_fixed32 + if map == nil then map = {}; result.map_fixed32_fixed32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_fixed32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_fixed32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 63 then + local map = result.map_fixed64_fixed64 + if map == nil then map = {}; result.map_fixed64_fixed64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_fixed64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_fixed64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 64 then + local map = result.map_sfixed32_sfixed32 + if map == nil then map = {}; result.map_sfixed32_sfixed32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sfixed32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sfixed32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 65 then + local map = result.map_sfixed64_sfixed64 + if map == nil then map = {}; result.map_sfixed64_sfixed64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sfixed64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sfixed64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 104 then + local map = result.map_int32_bool + if map == nil then map = {}; result.map_int32_bool = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, false + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bool(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 66 then + local map = result.map_int32_float + if map == nil then map = {}; result.map_int32_float = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_float(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 67 then + local map = result.map_int32_double + if map == nil then map = {}; result.map_int32_double = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_double(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 103 then + local map = result.map_int32_nested_message + if map == nil then map = {}; result.map_int32_nested_message = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.TestAllTypesProto2_NestedMessage_decode_unsafe(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 68 then + local map = result.map_bool_bool + if map == nil then map = {}; result.map_bool_bool = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = false, false + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bool(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bool(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 69 then + local map = result.map_string_string + if map == nil then map = {}; result.map_string_string = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', '' + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bytes(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 70 then + local map = result.map_string_bytes + if map == nil then map = {}; result.map_string_bytes = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', '' + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bytes(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 71 then + local map = result.map_string_nested_message + if map == nil then map = {}; result.map_string_nested_message = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.TestAllTypesProto2_NestedMessage_decode_unsafe(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 72 then + local map = result.map_string_foreign_message + if map == nil then map = {}; result.map_string_foreign_message = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.ForeignMessageProto2_decode_unsafe(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 73 then + local map = result.map_string_nested_enum + if map == nil then map = {}; result.map_string_nested_enum = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _u + _u, _ep = decode_varint(payload, _ep) + _val = varint_to_int32(_u) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 74 then + local map = result.map_string_foreign_enum + if map == nil then map = {}; result.map_string_foreign_enum = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _u + _u, _ep = decode_varint(payload, _ep) + _val = varint_to_int32(_u) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 111 then + local val + val, pos = decode_uint32(buf, pos) + result.oneof_uint32 = val + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 112 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.oneof_nested_message + if prev == nil then + result.oneof_nested_message = M.TestAllTypesProto2_NestedMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto2_NestedMessage_descriptor, prev, M.TestAllTypesProto2_NestedMessage_decode_unsafe(payload)) + end + result.oneof_uint32 = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 113 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.oneof_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.oneof_string = val + end + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 114 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.oneof_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.oneof_bytes = val + end + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 115 then + local val + val, pos = decode_bool(buf, pos) + result.oneof_bool = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 116 then + local val + val, pos = decode_uint64(buf, pos) + result.oneof_uint64 = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 117 then + local val + val, pos = decode_float(buf, pos) + result.oneof_float = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 118 then + local val + val, pos = decode_double(buf, pos) + result.oneof_double = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_enum = nil + elseif id == 119 then + local u + u, pos = decode_varint(buf, pos) + result.oneof_enum = varint_to_int32(u) + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + elseif id == 201 then + local payload + payload, pos = pb.codec.decode_group(M.TestAllTypesProto2_Data_descriptor, buf, pos, 201) + local prev = result.data + if prev == nil then + result.data = payload + else + pb.codec.merge_message(M.TestAllTypesProto2_Data_descriptor, prev, payload) + end + elseif id == 204 then + local payload + payload, pos = pb.codec.decode_group(M.TestAllTypesProto2_MultiWordGroupField_descriptor, buf, pos, 204) + local prev = result.multiwordgroupfield + if prev == nil then + result.multiwordgroupfield = payload + else + pb.codec.merge_message(M.TestAllTypesProto2_MultiWordGroupField_descriptor, prev, payload) + end + elseif id == 241 then + local val + val, pos = decode_int32(buf, pos) + result.default_int32 = val + elseif id == 242 then + local val + val, pos = decode_int64(buf, pos) + result.default_int64 = val + elseif id == 243 then + local val + val, pos = decode_uint32(buf, pos) + result.default_uint32 = val + elseif id == 244 then + local val + val, pos = decode_uint64(buf, pos) + result.default_uint64 = val + elseif id == 245 then + local val + val, pos = decode_sint32(buf, pos) + result.default_sint32 = val + elseif id == 246 then + local val + val, pos = decode_sint64(buf, pos) + result.default_sint64 = val + elseif id == 247 then + local val + val, pos = decode_fixed32(buf, pos) + result.default_fixed32 = val + elseif id == 248 then + local val + val, pos = decode_fixed64(buf, pos) + result.default_fixed64 = val + elseif id == 249 then + local val + val, pos = decode_sfixed32(buf, pos) + result.default_sfixed32 = val + elseif id == 250 then + local val + val, pos = decode_sfixed64(buf, pos) + result.default_sfixed64 = val + elseif id == 251 then + local val + val, pos = decode_float(buf, pos) + result.default_float = val + elseif id == 252 then + local val + val, pos = decode_double(buf, pos) + result.default_double = val + elseif id == 253 then + local val + val, pos = decode_bool(buf, pos) + result.default_bool = val + elseif id == 254 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.default_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.default_string = val + end + elseif id == 255 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.default_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.default_bytes = val + end + elseif id == 401 then + local val + val, pos = decode_int32(buf, pos) + result.fieldname1 = val + elseif id == 402 then + local val + val, pos = decode_int32(buf, pos) + result.field_name2 = val + elseif id == 403 then + local val + val, pos = decode_int32(buf, pos) + result._field_name3 = val + elseif id == 404 then + local val + val, pos = decode_int32(buf, pos) + result.field__name4_ = val + elseif id == 405 then + local val + val, pos = decode_int32(buf, pos) + result.field0name5 = val + elseif id == 406 then + local val + val, pos = decode_int32(buf, pos) + result.field_0_name6 = val + elseif id == 407 then + local val + val, pos = decode_int32(buf, pos) + result.fieldName7 = val + elseif id == 408 then + local val + val, pos = decode_int32(buf, pos) + result.FieldName8 = val + elseif id == 409 then + local val + val, pos = decode_int32(buf, pos) + result.field_Name9 = val + elseif id == 410 then + local val + val, pos = decode_int32(buf, pos) + result.Field_Name10 = val + elseif id == 411 then + local val + val, pos = decode_int32(buf, pos) + result.FIELD_NAME11 = val + elseif id == 412 then + local val + val, pos = decode_int32(buf, pos) + result.FIELD_name12 = val + elseif id == 413 then + local val + val, pos = decode_int32(buf, pos) + result.__field_name13 = val + elseif id == 414 then + local val + val, pos = decode_int32(buf, pos) + result.__Field_name14 = val + elseif id == 415 then + local val + val, pos = decode_int32(buf, pos) + result.field__name15 = val + elseif id == 416 then + local val + val, pos = decode_int32(buf, pos) + result.field__Name16 = val + elseif id == 417 then + local val + val, pos = decode_int32(buf, pos) + result.field_name17__ = val + elseif id == 418 then + local val + val, pos = decode_int32(buf, pos) + result.Field_name18__ = val + elseif id == 120 then + local _val + _val, pos = decode_int32(buf, pos) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["protobuf_test_messages.proto2.extension_int32"] = _val + elseif id == 121 then + local _payload + _payload, pos = pb.codec.decode_group(M.GroupField_descriptor, buf, pos, 121) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["protobuf_test_messages.proto2.groupfield"] = _payload + elseif id == 133 then + local _val + _val, pos = decode_bytes(buf, pos) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["protobuf_test_messages.proto2.extension_string"] = _val + elseif id == 134 then + local _val + _val, pos = decode_bytes(buf, pos) + local _e = result._extensions + if _e == nil then _e = {}; result._extensions = _e end + _e["protobuf_test_messages.proto2.extension_bytes"] = _val + else + local _ebid = M.TestAllTypesProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto2_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto2_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllTypesProto2 @@ -5033,6 +6927,58 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage +function M.TestAllTypesProto2_NestedMessage_decode_unsafe(buf) + local _d = M.TestAllTypesProto2_NestedMessage_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.a = val + elseif id == 2 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.corecursive + if prev == nil then + result.corecursive = M.TestAllTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto2_descriptor, prev, M.TestAllTypesProto2_decode_unsafe(payload)) + end + else + local _ebid = M.TestAllTypesProto2_NestedMessage_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto2_NestedMessage_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto2_NestedMessage_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.NestedMessage @@ -5136,6 +7082,53 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllTypesProto2.Data +function M.TestAllTypesProto2_Data_decode_unsafe(buf) + local _d = M.TestAllTypesProto2_Data_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.Data decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 202 then + local val + val, pos = wire.decode_int32(buf, pos) + result.group_int32 = val + elseif id == 203 then + local val + val, pos = wire.decode_uint32(buf, pos) + result.group_uint32 = val + else + local _ebid = M.TestAllTypesProto2_Data_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto2_Data_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto2_Data_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.Data @@ -5239,6 +7232,53 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField +function M.TestAllTypesProto2_MultiWordGroupField_decode_unsafe(buf) + local _d = M.TestAllTypesProto2_MultiWordGroupField_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 205 then + local val + val, pos = wire.decode_int32(buf, pos) + result.group_int32 = val + elseif id == 206 then + local val + val, pos = wire.decode_uint32(buf, pos) + result.group_uint32 = val + else + local _ebid = M.TestAllTypesProto2_MultiWordGroupField_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto2_MultiWordGroupField_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto2_MultiWordGroupField_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllTypesProto2.MultiWordGroupField @@ -5332,6 +7372,49 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.ForeignMessageProto2 +function M.ForeignMessageProto2_decode_unsafe(buf) + local _d = M.ForeignMessageProto2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.ForeignMessageProto2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.c = val + else + local _ebid = M.ForeignMessageProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.ForeignMessageProto2_decode_lazy(b) return pb.decode_lazy(M.ForeignMessageProto2_descriptor, b) end ---@param t protobuf_test_messages.proto2.ForeignMessageProto2 @@ -5430,6 +7513,53 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.GroupField +function M.GroupField_decode_unsafe(buf) + local _d = M.GroupField_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.GroupField decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 122 then + local val + val, pos = wire.decode_int32(buf, pos) + result.group_int32 = val + elseif id == 123 then + local val + val, pos = wire.decode_uint32(buf, pos) + result.group_uint32 = val + else + local _ebid = M.GroupField_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.GroupField_decode_lazy(b) return pb.decode_lazy(M.GroupField_descriptor, b) end ---@param t protobuf_test_messages.proto2.GroupField @@ -5631,6 +7761,107 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.UnknownToTestAllTypes +function M.UnknownToTestAllTypes_decode_unsafe(buf) + local decode_int32 = wire.decode_int32 + local decode_len = wire.decode_len + local _d = M.UnknownToTestAllTypes_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.UnknownToTestAllTypes decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_repeated_int32 = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1001 then + local val + val, pos = decode_int32(buf, pos) + result.optional_int32 = val + elseif id == 1002 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_string = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.optional_string = val + end + elseif id == 1003 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.nested_message + if prev == nil then + result.nested_message = M.ForeignMessageProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.ForeignMessageProto2_descriptor, prev, M.ForeignMessageProto2_decode_unsafe(payload)) + end + elseif id == 1004 then + local payload + payload, pos = pb.codec.decode_group(M.UnknownToTestAllTypes_OptionalGroup_descriptor, buf, pos, 1004) + local prev = result.optionalgroup + if prev == nil then + result.optionalgroup = payload + else + pb.codec.merge_message(M.UnknownToTestAllTypes_OptionalGroup_descriptor, prev, payload) + end + elseif id == 1006 then + local val + val, pos = wire.decode_bool(buf, pos) + result.optional_bool = val + elseif id == 1011 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_int32 + if list == nil then list = table_new(lim, 0); result.repeated_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + else + local list = result.repeated_int32 + if list == nil then list = {}; result.repeated_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + else + local _ebid = M.UnknownToTestAllTypes_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.UnknownToTestAllTypes_decode_lazy(b) return pb.decode_lazy(M.UnknownToTestAllTypes_descriptor, b) end ---@param t protobuf_test_messages.proto2.UnknownToTestAllTypes @@ -5739,6 +7970,49 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup +function M.UnknownToTestAllTypes_OptionalGroup_decode_unsafe(buf) + local _d = M.UnknownToTestAllTypes_OptionalGroup_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.a = val + else + local _ebid = M.UnknownToTestAllTypes_OptionalGroup_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.UnknownToTestAllTypes_OptionalGroup_decode_lazy(b) return pb.decode_lazy(M.UnknownToTestAllTypes_OptionalGroup_descriptor, b) end ---@param t protobuf_test_messages.proto2.UnknownToTestAllTypes.OptionalGroup @@ -5818,6 +8092,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.NullHypothesisProto2 +function M.NullHypothesisProto2_decode_unsafe(buf) + local _d = M.NullHypothesisProto2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.NullHypothesisProto2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.NullHypothesisProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.NullHypothesisProto2_decode_lazy(b) return pb.decode_lazy(M.NullHypothesisProto2_descriptor, b) end ---@param t protobuf_test_messages.proto2.NullHypothesisProto2 @@ -5855,6 +8169,46 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.EnumOnlyProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto2.EnumOnlyProto2 +function M.EnumOnlyProto2_decode_unsafe(buf) + local _d = M.EnumOnlyProto2_descriptor if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.EnumOnlyProto2 decode, got " .. type(buf), 0) end @@ -5992,6 +8346,59 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.OneStringProto2 +function M.OneStringProto2_decode_unsafe(buf) + local _d = M.OneStringProto2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.OneStringProto2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.data = _s + pos = _epos + else + local val + val, pos = wire.decode_bytes(buf, pos) + result.data = val + end + else + local _ebid = M.OneStringProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.OneStringProto2_decode_lazy(b) return pb.decode_lazy(M.OneStringProto2_descriptor, b) end ---@param t protobuf_test_messages.proto2.OneStringProto2 @@ -6124,6 +8531,81 @@ pos = _epos else local val val, pos = decode_string(buf, pos) + _n_requires = _n_requires + 1; list[_n_requires] = val + end + else + local _ebid = M.ProtoWithKeywords_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto2.ProtoWithKeywords +function M.ProtoWithKeywords_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.ProtoWithKeywords_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.ProtoWithKeywords decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_requires = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.inline = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.concept = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.concept = val + end + elseif id == 3 then + local list = result.requires + if list == nil then list = {}; result.requires = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_requires = _n_requires + 1; list[_n_requires] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) _n_requires = _n_requires + 1; list[_n_requires] = val end else @@ -6860,6 +9342,303 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2 +function M.TestAllRequiredTypesProto2_decode_unsafe(buf) + local decode_bool = wire.decode_bool + local decode_bytes = wire.decode_bytes + local decode_double = wire.decode_double + local decode_fixed32 = wire.decode_fixed32 + local decode_fixed64 = wire.decode_fixed64 + local decode_float = wire.decode_float + local decode_int32 = wire.decode_int32 + local decode_int64 = wire.decode_int64 + local decode_len = wire.decode_len + local decode_sfixed32 = wire.decode_sfixed32 + local decode_sfixed64 = wire.decode_sfixed64 + local decode_sint32 = wire.decode_sint32 + local decode_sint64 = wire.decode_sint64 + local decode_uint32 = wire.decode_uint32 + local decode_uint64 = wire.decode_uint64 + local decode_varint = wire.decode_varint + local varint_to_int32 = wire.varint_to_int32 + local _d = M.TestAllRequiredTypesProto2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.required_int32 = val + elseif id == 2 then + local val + val, pos = decode_int64(buf, pos) + result.required_int64 = val + elseif id == 3 then + local val + val, pos = decode_uint32(buf, pos) + result.required_uint32 = val + elseif id == 4 then + local val + val, pos = decode_uint64(buf, pos) + result.required_uint64 = val + elseif id == 5 then + local val + val, pos = decode_sint32(buf, pos) + result.required_sint32 = val + elseif id == 6 then + local val + val, pos = decode_sint64(buf, pos) + result.required_sint64 = val + elseif id == 7 then + local val + val, pos = decode_fixed32(buf, pos) + result.required_fixed32 = val + elseif id == 8 then + local val + val, pos = decode_fixed64(buf, pos) + result.required_fixed64 = val + elseif id == 9 then + local val + val, pos = decode_sfixed32(buf, pos) + result.required_sfixed32 = val + elseif id == 10 then + local val + val, pos = decode_sfixed64(buf, pos) + result.required_sfixed64 = val + elseif id == 11 then + local val + val, pos = decode_float(buf, pos) + result.required_float = val + elseif id == 12 then + local val + val, pos = decode_double(buf, pos) + result.required_double = val + elseif id == 13 then + local val + val, pos = decode_bool(buf, pos) + result.required_bool = val + elseif id == 14 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.required_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.required_string = val + end + elseif id == 15 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.required_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.required_bytes = val + end + elseif id == 18 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.required_nested_message + if prev == nil then + result.required_nested_message = M.TestAllRequiredTypesProto2_NestedMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_NestedMessage_descriptor, prev, M.TestAllRequiredTypesProto2_NestedMessage_decode_unsafe(payload)) + end + elseif id == 19 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.required_foreign_message + if prev == nil then + result.required_foreign_message = M.ForeignMessageProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.ForeignMessageProto2_descriptor, prev, M.ForeignMessageProto2_decode_unsafe(payload)) + end + elseif id == 21 then + local u + u, pos = decode_varint(buf, pos) + result.required_nested_enum = varint_to_int32(u) + elseif id == 22 then + local u + u, pos = decode_varint(buf, pos) + result.required_foreign_enum = varint_to_int32(u) + elseif id == 24 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.required_string_piece = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.required_string_piece = val + end + elseif id == 25 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.required_cord = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.required_cord = val + end + elseif id == 27 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.recursive_message + if prev == nil then + result.recursive_message = M.TestAllRequiredTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_descriptor, prev, M.TestAllRequiredTypesProto2_decode_unsafe(payload)) + end + elseif id == 28 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_recursive_message + if prev == nil then + result.optional_recursive_message = M.TestAllRequiredTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_descriptor, prev, M.TestAllRequiredTypesProto2_decode_unsafe(payload)) + end + elseif id == 201 then + local payload + payload, pos = pb.codec.decode_group(M.TestAllRequiredTypesProto2_Data_descriptor, buf, pos, 201) + local prev = result.data + if prev == nil then + result.data = payload + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_Data_descriptor, prev, payload) + end + elseif id == 241 then + local val + val, pos = decode_int32(buf, pos) + result.default_int32 = val + elseif id == 242 then + local val + val, pos = decode_int64(buf, pos) + result.default_int64 = val + elseif id == 243 then + local val + val, pos = decode_uint32(buf, pos) + result.default_uint32 = val + elseif id == 244 then + local val + val, pos = decode_uint64(buf, pos) + result.default_uint64 = val + elseif id == 245 then + local val + val, pos = decode_sint32(buf, pos) + result.default_sint32 = val + elseif id == 246 then + local val + val, pos = decode_sint64(buf, pos) + result.default_sint64 = val + elseif id == 247 then + local val + val, pos = decode_fixed32(buf, pos) + result.default_fixed32 = val + elseif id == 248 then + local val + val, pos = decode_fixed64(buf, pos) + result.default_fixed64 = val + elseif id == 249 then + local val + val, pos = decode_sfixed32(buf, pos) + result.default_sfixed32 = val + elseif id == 250 then + local val + val, pos = decode_sfixed64(buf, pos) + result.default_sfixed64 = val + elseif id == 251 then + local val + val, pos = decode_float(buf, pos) + result.default_float = val + elseif id == 252 then + local val + val, pos = decode_double(buf, pos) + result.default_double = val + elseif id == 253 then + local val + val, pos = decode_bool(buf, pos) + result.default_bool = val + elseif id == 254 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.default_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.default_string = val + end + elseif id == 255 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.default_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.default_bytes = val + end + else + local _ebid = M.TestAllRequiredTypesProto2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllRequiredTypesProto2_decode_lazy(b) return pb.decode_lazy(M.TestAllRequiredTypesProto2_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllRequiredTypesProto2 @@ -6996,6 +9775,68 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage +function M.TestAllRequiredTypesProto2_NestedMessage_decode_unsafe(buf) + local decode_len = wire.decode_len + local _d = M.TestAllRequiredTypesProto2_NestedMessage_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.a = val + elseif id == 2 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.corecursive + if prev == nil then + result.corecursive = M.TestAllRequiredTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_descriptor, prev, M.TestAllRequiredTypesProto2_decode_unsafe(payload)) + end + elseif id == 3 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_corecursive + if prev == nil then + result.optional_corecursive = M.TestAllRequiredTypesProto2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllRequiredTypesProto2_descriptor, prev, M.TestAllRequiredTypesProto2_decode_unsafe(payload)) + end + else + local _ebid = M.TestAllRequiredTypesProto2_NestedMessage_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllRequiredTypesProto2_NestedMessage_decode_lazy(b) return pb.decode_lazy(M.TestAllRequiredTypesProto2_NestedMessage_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage @@ -7052,6 +9893,53 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 202 then + local val + val, pos = wire.decode_int32(buf, pos) + result.group_int32 = val + elseif id == 203 then + local val + val, pos = wire.decode_uint32(buf, pos) + result.group_uint32 = val + else + local _ebid = M.TestAllRequiredTypesProto2_Data_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data +function M.TestAllRequiredTypesProto2_Data_decode_unsafe(buf) + local _d = M.TestAllRequiredTypesProto2_Data_descriptor if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data decode, got " .. type(buf), 0) end @@ -7307,6 +10195,111 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof +function M.TestLargeOneof_decode_unsafe(buf) + local decode_len = wire.decode_len + local _d = M.TestLargeOneof_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestLargeOneof decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.a1 + if prev == nil then + result.a1 = M.TestLargeOneof_A1_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestLargeOneof_A1_descriptor, prev, M.TestLargeOneof_A1_decode_unsafe(payload)) + end + result.a2 = nil + result.a3 = nil + result.a4 = nil + result.a5 = nil + elseif id == 2 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.a2 + if prev == nil then + result.a2 = M.TestLargeOneof_A2_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestLargeOneof_A2_descriptor, prev, M.TestLargeOneof_A2_decode_unsafe(payload)) + end + result.a1 = nil + result.a3 = nil + result.a4 = nil + result.a5 = nil + elseif id == 3 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.a3 + if prev == nil then + result.a3 = M.TestLargeOneof_A3_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestLargeOneof_A3_descriptor, prev, M.TestLargeOneof_A3_decode_unsafe(payload)) + end + result.a1 = nil + result.a2 = nil + result.a4 = nil + result.a5 = nil + elseif id == 4 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.a4 + if prev == nil then + result.a4 = M.TestLargeOneof_A4_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestLargeOneof_A4_descriptor, prev, M.TestLargeOneof_A4_decode_unsafe(payload)) + end + result.a1 = nil + result.a2 = nil + result.a3 = nil + result.a5 = nil + elseif id == 5 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.a5 + if prev == nil then + result.a5 = M.TestLargeOneof_A5_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestLargeOneof_A5_descriptor, prev, M.TestLargeOneof_A5_decode_unsafe(payload)) + end + result.a1 = nil + result.a2 = nil + result.a3 = nil + result.a4 = nil + else + local _ebid = M.TestLargeOneof_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestLargeOneof_decode_lazy(b) return pb.decode_lazy(M.TestLargeOneof_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestLargeOneof @@ -7381,6 +10374,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof.A1 +function M.TestLargeOneof_A1_decode_unsafe(buf) + local _d = M.TestLargeOneof_A1_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A1 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.TestLargeOneof_A1_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestLargeOneof_A1_decode_lazy(b) return pb.decode_lazy(M.TestLargeOneof_A1_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestLargeOneof.A1 @@ -7455,6 +10488,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof.A2 +function M.TestLargeOneof_A2_decode_unsafe(buf) + local _d = M.TestLargeOneof_A2_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A2 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.TestLargeOneof_A2_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestLargeOneof_A2_decode_lazy(b) return pb.decode_lazy(M.TestLargeOneof_A2_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestLargeOneof.A2 @@ -7529,6 +10602,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof.A3 +function M.TestLargeOneof_A3_decode_unsafe(buf) + local _d = M.TestLargeOneof_A3_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A3 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.TestLargeOneof_A3_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestLargeOneof_A3_decode_lazy(b) return pb.decode_lazy(M.TestLargeOneof_A3_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestLargeOneof.A3 @@ -7603,6 +10716,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof.A4 +function M.TestLargeOneof_A4_decode_unsafe(buf) + local _d = M.TestLargeOneof_A4_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto2.TestLargeOneof.A4 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.TestLargeOneof_A4_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestLargeOneof_A4_decode_lazy(b) return pb.decode_lazy(M.TestLargeOneof_A4_descriptor, b) end ---@param t protobuf_test_messages.proto2.TestLargeOneof.A4 @@ -7640,6 +10793,46 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.TestLargeOneof_A5_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto2.TestLargeOneof.A5 +function M.TestLargeOneof_A5_decode_unsafe(buf) + local _d = M.TestLargeOneof_A5_descriptor 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 3add91ac2ca5105dc1e50cbe468d23415040f43b..e3be783f42dabac34263f825abe18dc2dde0434e 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 @@ -4835,6 +4835,1951 @@ return result end ---@param b string +---@return protobuf_test_messages.proto3.TestAllTypesProto3 +function M.TestAllTypesProto3_decode_unsafe(buf) + local decode_bool = wire.decode_bool + local decode_bytes = wire.decode_bytes + local decode_double = wire.decode_double + local decode_fixed32 = wire.decode_fixed32 + local decode_fixed64 = wire.decode_fixed64 + local decode_float = wire.decode_float + local decode_int32 = wire.decode_int32 + local decode_int64 = wire.decode_int64 + local decode_len = wire.decode_len + local decode_sfixed32 = wire.decode_sfixed32 + local decode_sfixed64 = wire.decode_sfixed64 + local decode_sint32 = wire.decode_sint32 + local decode_sint64 = wire.decode_sint64 + local decode_tag = wire.decode_tag + local decode_uint32 = wire.decode_uint32 + local decode_uint64 = wire.decode_uint64 + local decode_varint = wire.decode_varint + local skip_field = wire.skip_field + local varint_to_int32 = wire.varint_to_int32 + local _d = M.TestAllTypesProto3_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto3.TestAllTypesProto3 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_repeated_int32 = 0 + local _n_repeated_int64 = 0 + local _n_repeated_uint32 = 0 + local _n_repeated_uint64 = 0 + local _n_repeated_sint32 = 0 + local _n_repeated_sint64 = 0 + local _n_repeated_fixed32 = 0 + local _n_repeated_fixed64 = 0 + local _n_repeated_sfixed32 = 0 + local _n_repeated_sfixed64 = 0 + local _n_repeated_float = 0 + local _n_repeated_double = 0 + local _n_repeated_bool = 0 + local _n_repeated_string = 0 + local _n_repeated_bytes = 0 + local _n_repeated_nested_message = 0 + local _n_repeated_foreign_message = 0 + local _n_repeated_nested_enum = 0 + local _n_repeated_foreign_enum = 0 + local _n_repeated_string_piece = 0 + local _n_repeated_cord = 0 + local _n_packed_int32 = 0 + local _n_packed_int64 = 0 + local _n_packed_uint32 = 0 + local _n_packed_uint64 = 0 + local _n_packed_sint32 = 0 + local _n_packed_sint64 = 0 + local _n_packed_fixed32 = 0 + local _n_packed_fixed64 = 0 + local _n_packed_sfixed32 = 0 + local _n_packed_sfixed64 = 0 + local _n_packed_float = 0 + local _n_packed_double = 0 + local _n_packed_bool = 0 + local _n_packed_nested_enum = 0 + local _n_unpacked_int32 = 0 + local _n_unpacked_int64 = 0 + local _n_unpacked_uint32 = 0 + local _n_unpacked_uint64 = 0 + local _n_unpacked_sint32 = 0 + local _n_unpacked_sint64 = 0 + local _n_unpacked_fixed32 = 0 + local _n_unpacked_fixed64 = 0 + local _n_unpacked_sfixed32 = 0 + local _n_unpacked_sfixed64 = 0 + local _n_unpacked_float = 0 + local _n_unpacked_double = 0 + local _n_unpacked_bool = 0 + local _n_unpacked_nested_enum = 0 + local _n_repeated_bool_wrapper = 0 + local _n_repeated_int32_wrapper = 0 + local _n_repeated_int64_wrapper = 0 + local _n_repeated_uint32_wrapper = 0 + local _n_repeated_uint64_wrapper = 0 + local _n_repeated_float_wrapper = 0 + local _n_repeated_double_wrapper = 0 + local _n_repeated_string_wrapper = 0 + local _n_repeated_bytes_wrapper = 0 + local _n_repeated_duration = 0 + local _n_repeated_timestamp = 0 + local _n_repeated_fieldmask = 0 + local _n_repeated_struct = 0 + local _n_repeated_any = 0 + local _n_repeated_value = 0 + local _n_repeated_list_value = 0 + local _n_repeated_empty = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = decode_int32(buf, pos) + result.optional_int32 = val + elseif id == 2 then + local val + val, pos = decode_int64(buf, pos) + result.optional_int64 = val + elseif id == 3 then + local val + val, pos = decode_uint32(buf, pos) + result.optional_uint32 = val + elseif id == 4 then + local val + val, pos = decode_uint64(buf, pos) + result.optional_uint64 = val + elseif id == 5 then + local val + val, pos = decode_sint32(buf, pos) + result.optional_sint32 = val + elseif id == 6 then + local val + val, pos = decode_sint64(buf, pos) + result.optional_sint64 = val + elseif id == 7 then + local val + val, pos = decode_fixed32(buf, pos) + result.optional_fixed32 = val + elseif id == 8 then + local val + val, pos = decode_fixed64(buf, pos) + result.optional_fixed64 = val + elseif id == 9 then + local val + val, pos = decode_sfixed32(buf, pos) + result.optional_sfixed32 = val + elseif id == 10 then + local val + val, pos = decode_sfixed64(buf, pos) + result.optional_sfixed64 = val + elseif id == 11 then + local val + val, pos = decode_float(buf, pos) + result.optional_float = val + elseif id == 12 then + local val + val, pos = decode_double(buf, pos) + result.optional_double = val + elseif id == 13 then + local val + val, pos = decode_bool(buf, pos) + result.optional_bool = val + elseif id == 14 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_string = val + end + elseif id == 15 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_bytes = val + end + elseif id == 18 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_nested_message + if prev == nil then + result.optional_nested_message = M.TestAllTypesProto3_NestedMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto3_NestedMessage_descriptor, prev, M.TestAllTypesProto3_NestedMessage_decode_unsafe(payload)) + end + elseif id == 19 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.optional_foreign_message + if prev == nil then + result.optional_foreign_message = M.ForeignMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.ForeignMessage_descriptor, prev, M.ForeignMessage_decode_unsafe(payload)) + end + elseif id == 21 then + local u + u, pos = decode_varint(buf, pos) + result.optional_nested_enum = varint_to_int32(u) + elseif id == 22 then + local u + u, pos = decode_varint(buf, pos) + result.optional_foreign_enum = varint_to_int32(u) + elseif id == 23 then + local u + u, pos = decode_varint(buf, pos) + result.optional_aliased_enum = varint_to_int32(u) + elseif id == 24 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_string_piece = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_string_piece = val + end + elseif id == 25 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.optional_cord = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.optional_cord = val + end + elseif id == 27 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.recursive_message + if prev == nil then + result.recursive_message = M.TestAllTypesProto3_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto3_descriptor, prev, M.TestAllTypesProto3_decode_unsafe(payload)) + end + elseif id == 31 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_int32 + if list == nil then list = table_new(lim, 0); result.repeated_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + else + local list = result.repeated_int32 + if list == nil then list = {}; result.repeated_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_repeated_int32 = _n_repeated_int32 + 1; list[_n_repeated_int32] = val + end + elseif id == 32 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_int64 + if list == nil then list = table_new(lim, 0); result.repeated_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_repeated_int64 = _n_repeated_int64 + 1; list[_n_repeated_int64] = val + end + else + local list = result.repeated_int64 + if list == nil then list = {}; result.repeated_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_repeated_int64 = _n_repeated_int64 + 1; list[_n_repeated_int64] = val + end + elseif id == 33 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_uint32 + if list == nil then list = table_new(lim, 0); result.repeated_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_repeated_uint32 = _n_repeated_uint32 + 1; list[_n_repeated_uint32] = val + end + else + local list = result.repeated_uint32 + if list == nil then list = {}; result.repeated_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_repeated_uint32 = _n_repeated_uint32 + 1; list[_n_repeated_uint32] = val + end + elseif id == 34 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_uint64 + if list == nil then list = table_new(lim, 0); result.repeated_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_repeated_uint64 = _n_repeated_uint64 + 1; list[_n_repeated_uint64] = val + end + else + local list = result.repeated_uint64 + if list == nil then list = {}; result.repeated_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_repeated_uint64 = _n_repeated_uint64 + 1; list[_n_repeated_uint64] = val + end + elseif id == 35 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sint32 + if list == nil then list = table_new(lim, 0); result.repeated_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_repeated_sint32 = _n_repeated_sint32 + 1; list[_n_repeated_sint32] = val + end + else + local list = result.repeated_sint32 + if list == nil then list = {}; result.repeated_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_repeated_sint32 = _n_repeated_sint32 + 1; list[_n_repeated_sint32] = val + end + elseif id == 36 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sint64 + if list == nil then list = table_new(lim, 0); result.repeated_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_repeated_sint64 = _n_repeated_sint64 + 1; list[_n_repeated_sint64] = val + end + else + local list = result.repeated_sint64 + if list == nil then list = {}; result.repeated_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_repeated_sint64 = _n_repeated_sint64 + 1; list[_n_repeated_sint64] = val + end + elseif id == 37 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_repeated_fixed32 = _n_repeated_fixed32 + 1; list[_n_repeated_fixed32] = val + end + else + local list = result.repeated_fixed32 + if list == nil then list = {}; result.repeated_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_repeated_fixed32 = _n_repeated_fixed32 + 1; list[_n_repeated_fixed32] = val + end + elseif id == 38 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_repeated_fixed64 = _n_repeated_fixed64 + 1; list[_n_repeated_fixed64] = val + end + else + local list = result.repeated_fixed64 + if list == nil then list = {}; result.repeated_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_repeated_fixed64 = _n_repeated_fixed64 + 1; list[_n_repeated_fixed64] = val + end + elseif id == 39 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_repeated_sfixed32 = _n_repeated_sfixed32 + 1; list[_n_repeated_sfixed32] = val + end + else + local list = result.repeated_sfixed32 + if list == nil then list = {}; result.repeated_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_repeated_sfixed32 = _n_repeated_sfixed32 + 1; list[_n_repeated_sfixed32] = val + end + elseif id == 40 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_repeated_sfixed64 = _n_repeated_sfixed64 + 1; list[_n_repeated_sfixed64] = val + end + else + local list = result.repeated_sfixed64 + if list == nil then list = {}; result.repeated_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_repeated_sfixed64 = _n_repeated_sfixed64 + 1; list[_n_repeated_sfixed64] = val + end + elseif id == 41 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.repeated_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_repeated_float = _n_repeated_float + 1; list[_n_repeated_float] = val + end + else + local list = result.repeated_float + if list == nil then list = {}; result.repeated_float = list end + local val + val, pos = decode_float(buf, pos) + _n_repeated_float = _n_repeated_float + 1; list[_n_repeated_float] = val + end + elseif id == 42 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.repeated_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_repeated_double = _n_repeated_double + 1; list[_n_repeated_double] = val + end + else + local list = result.repeated_double + if list == nil then list = {}; result.repeated_double = list end + local val + val, pos = decode_double(buf, pos) + _n_repeated_double = _n_repeated_double + 1; list[_n_repeated_double] = val + end + elseif id == 43 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_bool + if list == nil then list = table_new(lim, 0); result.repeated_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_repeated_bool = _n_repeated_bool + 1; list[_n_repeated_bool] = val + end + else + local list = result.repeated_bool + if list == nil then list = {}; result.repeated_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_repeated_bool = _n_repeated_bool + 1; list[_n_repeated_bool] = val + end + elseif id == 44 then + local list = result.repeated_string + if list == nil then list = {}; result.repeated_string = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_string = _n_repeated_string + 1; list[_n_repeated_string] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_string = _n_repeated_string + 1; list[_n_repeated_string] = val + end + elseif id == 45 then + local list = result.repeated_bytes + if list == nil then list = {}; result.repeated_bytes = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_bytes = _n_repeated_bytes + 1; list[_n_repeated_bytes] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_bytes = _n_repeated_bytes + 1; list[_n_repeated_bytes] = val + end + elseif id == 48 then + local list = result.repeated_nested_message + if list == nil then list = {}; result.repeated_nested_message = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_nested_message = _n_repeated_nested_message + 1; list[_n_repeated_nested_message] = M.TestAllTypesProto3_NestedMessage_decode_unsafe(payload) + elseif id == 49 then + local list = result.repeated_foreign_message + if list == nil then list = {}; result.repeated_foreign_message = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_foreign_message = _n_repeated_foreign_message + 1; list[_n_repeated_foreign_message] = M.ForeignMessage_decode_unsafe(payload) + elseif id == 51 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_nested_enum + if list == nil then list = table_new(lim, 0); result.repeated_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_repeated_nested_enum = _n_repeated_nested_enum + 1; list[_n_repeated_nested_enum] = varint_to_int32(u) + end + else + local list = result.repeated_nested_enum + if list == nil then list = {}; result.repeated_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_repeated_nested_enum = _n_repeated_nested_enum + 1; list[_n_repeated_nested_enum] = varint_to_int32(u) + end + elseif id == 52 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.repeated_foreign_enum + if list == nil then list = table_new(lim, 0); result.repeated_foreign_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_repeated_foreign_enum = _n_repeated_foreign_enum + 1; list[_n_repeated_foreign_enum] = varint_to_int32(u) + end + else + local list = result.repeated_foreign_enum + if list == nil then list = {}; result.repeated_foreign_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_repeated_foreign_enum = _n_repeated_foreign_enum + 1; list[_n_repeated_foreign_enum] = varint_to_int32(u) + end + elseif id == 54 then + local list = result.repeated_string_piece + if list == nil then list = {}; result.repeated_string_piece = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_string_piece = _n_repeated_string_piece + 1; list[_n_repeated_string_piece] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_string_piece = _n_repeated_string_piece + 1; list[_n_repeated_string_piece] = val + end + elseif id == 55 then + local list = result.repeated_cord + if list == nil then list = {}; result.repeated_cord = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_repeated_cord = _n_repeated_cord + 1; list[_n_repeated_cord] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_repeated_cord = _n_repeated_cord + 1; list[_n_repeated_cord] = val + end + elseif id == 75 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int32 + if list == nil then list = table_new(lim, 0); result.packed_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + else + local list = result.packed_int32 + if list == nil then list = {}; result.packed_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_packed_int32 = _n_packed_int32 + 1; list[_n_packed_int32] = val + end + elseif id == 76 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_int64 + if list == nil then list = table_new(lim, 0); result.packed_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + else + local list = result.packed_int64 + if list == nil then list = {}; result.packed_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_packed_int64 = _n_packed_int64 + 1; list[_n_packed_int64] = val + end + elseif id == 77 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_uint32 + if list == nil then list = table_new(lim, 0); result.packed_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + else + local list = result.packed_uint32 + if list == nil then list = {}; result.packed_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_packed_uint32 = _n_packed_uint32 + 1; list[_n_packed_uint32] = val + end + elseif id == 78 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_uint64 + if list == nil then list = table_new(lim, 0); result.packed_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_packed_uint64 = _n_packed_uint64 + 1; list[_n_packed_uint64] = val + end + else + local list = result.packed_uint64 + if list == nil then list = {}; result.packed_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_packed_uint64 = _n_packed_uint64 + 1; list[_n_packed_uint64] = val + end + elseif id == 79 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sint32 + if list == nil then list = table_new(lim, 0); result.packed_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + else + local list = result.packed_sint32 + if list == nil then list = {}; result.packed_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_packed_sint32 = _n_packed_sint32 + 1; list[_n_packed_sint32] = val + end + elseif id == 80 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sint64 + if list == nil then list = table_new(lim, 0); result.packed_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_packed_sint64 = _n_packed_sint64 + 1; list[_n_packed_sint64] = val + end + else + local list = result.packed_sint64 + if list == nil then list = {}; result.packed_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_packed_sint64 = _n_packed_sint64 + 1; list[_n_packed_sint64] = val + end + elseif id == 81 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + else + local list = result.packed_fixed32 + if list == nil then list = {}; result.packed_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_packed_fixed32 = _n_packed_fixed32 + 1; list[_n_packed_fixed32] = val + end + elseif id == 82 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + else + local list = result.packed_fixed64 + if list == nil then list = {}; result.packed_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_packed_fixed64 = _n_packed_fixed64 + 1; list[_n_packed_fixed64] = val + end + elseif id == 83 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_packed_sfixed32 = _n_packed_sfixed32 + 1; list[_n_packed_sfixed32] = val + end + else + local list = result.packed_sfixed32 + if list == nil then list = {}; result.packed_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_packed_sfixed32 = _n_packed_sfixed32 + 1; list[_n_packed_sfixed32] = val + end + elseif id == 84 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_packed_sfixed64 = _n_packed_sfixed64 + 1; list[_n_packed_sfixed64] = val + end + else + local list = result.packed_sfixed64 + if list == nil then list = {}; result.packed_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_packed_sfixed64 = _n_packed_sfixed64 + 1; list[_n_packed_sfixed64] = val + end + elseif id == 85 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.packed_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + else + local list = result.packed_float + if list == nil then list = {}; result.packed_float = list end + local val + val, pos = decode_float(buf, pos) + _n_packed_float = _n_packed_float + 1; list[_n_packed_float] = val + end + elseif id == 86 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.packed_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + else + local list = result.packed_double + if list == nil then list = {}; result.packed_double = list end + local val + val, pos = decode_double(buf, pos) + _n_packed_double = _n_packed_double + 1; list[_n_packed_double] = val + end + elseif id == 87 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_bool + if list == nil then list = table_new(lim, 0); result.packed_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + else + local list = result.packed_bool + if list == nil then list = {}; result.packed_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_packed_bool = _n_packed_bool + 1; list[_n_packed_bool] = val + end + elseif id == 88 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.packed_nested_enum + if list == nil then list = table_new(lim, 0); result.packed_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_packed_nested_enum = _n_packed_nested_enum + 1; list[_n_packed_nested_enum] = varint_to_int32(u) + end + else + local list = result.packed_nested_enum + if list == nil then list = {}; result.packed_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_packed_nested_enum = _n_packed_nested_enum + 1; list[_n_packed_nested_enum] = varint_to_int32(u) + end + elseif id == 89 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_int32 + if list == nil then list = table_new(lim, 0); result.unpacked_int32 = list end + while p2 <= lim do + local val + val, p2 = decode_int32(payload, p2) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + else + local list = result.unpacked_int32 + if list == nil then list = {}; result.unpacked_int32 = list end + local val + val, pos = decode_int32(buf, pos) + _n_unpacked_int32 = _n_unpacked_int32 + 1; list[_n_unpacked_int32] = val + end + elseif id == 90 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_int64 + if list == nil then list = table_new(lim, 0); result.unpacked_int64 = list end + while p2 <= lim do + local val + val, p2 = decode_int64(payload, p2) + _n_unpacked_int64 = _n_unpacked_int64 + 1; list[_n_unpacked_int64] = val + end + else + local list = result.unpacked_int64 + if list == nil then list = {}; result.unpacked_int64 = list end + local val + val, pos = decode_int64(buf, pos) + _n_unpacked_int64 = _n_unpacked_int64 + 1; list[_n_unpacked_int64] = val + end + elseif id == 91 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_uint32 + if list == nil then list = table_new(lim, 0); result.unpacked_uint32 = list end + while p2 <= lim do + local val + val, p2 = decode_uint32(payload, p2) + _n_unpacked_uint32 = _n_unpacked_uint32 + 1; list[_n_unpacked_uint32] = val + end + else + local list = result.unpacked_uint32 + if list == nil then list = {}; result.unpacked_uint32 = list end + local val + val, pos = decode_uint32(buf, pos) + _n_unpacked_uint32 = _n_unpacked_uint32 + 1; list[_n_unpacked_uint32] = val + end + elseif id == 92 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_uint64 + if list == nil then list = table_new(lim, 0); result.unpacked_uint64 = list end + while p2 <= lim do + local val + val, p2 = decode_uint64(payload, p2) + _n_unpacked_uint64 = _n_unpacked_uint64 + 1; list[_n_unpacked_uint64] = val + end + else + local list = result.unpacked_uint64 + if list == nil then list = {}; result.unpacked_uint64 = list end + local val + val, pos = decode_uint64(buf, pos) + _n_unpacked_uint64 = _n_unpacked_uint64 + 1; list[_n_unpacked_uint64] = val + end + elseif id == 93 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sint32 + if list == nil then list = table_new(lim, 0); result.unpacked_sint32 = list end + while p2 <= lim do + local val + val, p2 = decode_sint32(payload, p2) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + else + local list = result.unpacked_sint32 + if list == nil then list = {}; result.unpacked_sint32 = list end + local val + val, pos = decode_sint32(buf, pos) + _n_unpacked_sint32 = _n_unpacked_sint32 + 1; list[_n_unpacked_sint32] = val + end + elseif id == 94 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sint64 + if list == nil then list = table_new(lim, 0); result.unpacked_sint64 = list end + while p2 <= lim do + local val + val, p2 = decode_sint64(payload, p2) + _n_unpacked_sint64 = _n_unpacked_sint64 + 1; list[_n_unpacked_sint64] = val + end + else + local list = result.unpacked_sint64 + if list == nil then list = {}; result.unpacked_sint64 = list end + local val + val, pos = decode_sint64(buf, pos) + _n_unpacked_sint64 = _n_unpacked_sint64 + 1; list[_n_unpacked_sint64] = val + end + elseif id == 95 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_fixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_fixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed32(payload, p2) + _n_unpacked_fixed32 = _n_unpacked_fixed32 + 1; list[_n_unpacked_fixed32] = val + end + else + local list = result.unpacked_fixed32 + if list == nil then list = {}; result.unpacked_fixed32 = list end + local val + val, pos = decode_fixed32(buf, pos) + _n_unpacked_fixed32 = _n_unpacked_fixed32 + 1; list[_n_unpacked_fixed32] = val + end + elseif id == 96 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_fixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_fixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_fixed64(payload, p2) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + else + local list = result.unpacked_fixed64 + if list == nil then list = {}; result.unpacked_fixed64 = list end + local val + val, pos = decode_fixed64(buf, pos) + _n_unpacked_fixed64 = _n_unpacked_fixed64 + 1; list[_n_unpacked_fixed64] = val + end + elseif id == 97 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sfixed32 + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_sfixed32 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed32(payload, p2) + _n_unpacked_sfixed32 = _n_unpacked_sfixed32 + 1; list[_n_unpacked_sfixed32] = val + end + else + local list = result.unpacked_sfixed32 + if list == nil then list = {}; result.unpacked_sfixed32 = list end + local val + val, pos = decode_sfixed32(buf, pos) + _n_unpacked_sfixed32 = _n_unpacked_sfixed32 + 1; list[_n_unpacked_sfixed32] = val + end + elseif id == 98 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_sfixed64 + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_sfixed64 = list end + while p2 <= lim do + local val + val, p2 = decode_sfixed64(payload, p2) + _n_unpacked_sfixed64 = _n_unpacked_sfixed64 + 1; list[_n_unpacked_sfixed64] = val + end + else + local list = result.unpacked_sfixed64 + if list == nil then list = {}; result.unpacked_sfixed64 = list end + local val + val, pos = decode_sfixed64(buf, pos) + _n_unpacked_sfixed64 = _n_unpacked_sfixed64 + 1; list[_n_unpacked_sfixed64] = val + end + elseif id == 99 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_float + if list == nil then list = table_new(rshift(lim, 2), 0); result.unpacked_float = list end + while p2 <= lim do + local val + val, p2 = decode_float(payload, p2) + _n_unpacked_float = _n_unpacked_float + 1; list[_n_unpacked_float] = val + end + else + local list = result.unpacked_float + if list == nil then list = {}; result.unpacked_float = list end + local val + val, pos = decode_float(buf, pos) + _n_unpacked_float = _n_unpacked_float + 1; list[_n_unpacked_float] = val + end + elseif id == 100 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_double + if list == nil then list = table_new(rshift(lim, 3), 0); result.unpacked_double = list end + while p2 <= lim do + local val + val, p2 = decode_double(payload, p2) + _n_unpacked_double = _n_unpacked_double + 1; list[_n_unpacked_double] = val + end + else + local list = result.unpacked_double + if list == nil then list = {}; result.unpacked_double = list end + local val + val, pos = decode_double(buf, pos) + _n_unpacked_double = _n_unpacked_double + 1; list[_n_unpacked_double] = val + end + elseif id == 101 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_bool + if list == nil then list = table_new(lim, 0); result.unpacked_bool = list end + while p2 <= lim do + local val + val, p2 = decode_bool(payload, p2) + _n_unpacked_bool = _n_unpacked_bool + 1; list[_n_unpacked_bool] = val + end + else + local list = result.unpacked_bool + if list == nil then list = {}; result.unpacked_bool = list end + local val + val, pos = decode_bool(buf, pos) + _n_unpacked_bool = _n_unpacked_bool + 1; list[_n_unpacked_bool] = val + end + elseif id == 102 then + if wt == 2 then + local payload + payload, pos = decode_len(buf, pos) + local p2, lim = 1, #payload + local list = result.unpacked_nested_enum + if list == nil then list = table_new(lim, 0); result.unpacked_nested_enum = list end + while p2 <= lim do + local u + u, p2 = decode_varint(payload, p2) + _n_unpacked_nested_enum = _n_unpacked_nested_enum + 1; list[_n_unpacked_nested_enum] = varint_to_int32(u) + end + else + local list = result.unpacked_nested_enum + if list == nil then list = {}; result.unpacked_nested_enum = list end + local u + u, pos = decode_varint(buf, pos) + _n_unpacked_nested_enum = _n_unpacked_nested_enum + 1; list[_n_unpacked_nested_enum] = varint_to_int32(u) + end + elseif id == 56 then + local map = result.map_int32_int32 + if map == nil then map = {}; result.map_int32_int32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_int32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 57 then + local map = result.map_int64_int64 + if map == nil then map = {}; result.map_int64_int64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_int64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 58 then + local map = result.map_uint32_uint32 + if map == nil then map = {}; result.map_uint32_uint32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_uint32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_uint32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 59 then + local map = result.map_uint64_uint64 + if map == nil then map = {}; result.map_uint64_uint64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_uint64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_uint64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 60 then + local map = result.map_sint32_sint32 + if map == nil then map = {}; result.map_sint32_sint32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sint32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sint32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 61 then + local map = result.map_sint64_sint64 + if map == nil then map = {}; result.map_sint64_sint64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sint64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sint64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 62 then + local map = result.map_fixed32_fixed32 + if map == nil then map = {}; result.map_fixed32_fixed32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_fixed32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_fixed32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 63 then + local map = result.map_fixed64_fixed64 + if map == nil then map = {}; result.map_fixed64_fixed64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_fixed64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_fixed64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 64 then + local map = result.map_sfixed32_sfixed32 + if map == nil then map = {}; result.map_sfixed32_sfixed32 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sfixed32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sfixed32(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 65 then + local map = result.map_sfixed64_sfixed64 + if map == nil then map = {}; result.map_sfixed64_sfixed64 = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_sfixed64(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_sfixed64(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + for _k in pairs(map) do + if _k == _key then _key = _k; break end + end + map[_key] = _val + elseif id == 66 then + local map = result.map_int32_float + if map == nil then map = {}; result.map_int32_float = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_float(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 67 then + local map = result.map_int32_double + if map == nil then map = {}; result.map_int32_double = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = 0, 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_int32(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_double(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 68 then + local map = result.map_bool_bool + if map == nil then map = {}; result.map_bool_bool = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = false, false + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bool(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bool(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 69 then + local map = result.map_string_string + if map == nil then map = {}; result.map_string_string = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', '' + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bytes(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 70 then + local map = result.map_string_bytes + if map == nil then map = {}; result.map_string_bytes = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', '' + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + _val, _ep = decode_bytes(payload, _ep) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 71 then + local map = result.map_string_nested_message + if map == nil then map = {}; result.map_string_nested_message = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.TestAllTypesProto3_NestedMessage_decode_unsafe(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 72 then + local map = result.map_string_foreign_message + if map == nil then map = {}; result.map_string_foreign_message = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', {} + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _payload + _payload, _ep = decode_len(payload, _ep) + _val = M.ForeignMessage_decode_unsafe(_payload) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 73 then + local map = result.map_string_nested_enum + if map == nil then map = {}; result.map_string_nested_enum = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _u + _u, _ep = decode_varint(payload, _ep) + _val = varint_to_int32(_u) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 74 then + local map = result.map_string_foreign_enum + if map == nil then map = {}; result.map_string_foreign_enum = map end + local payload + payload, pos = decode_len(buf, pos) + local _ep, _elim = 1, #payload + local _key, _val = '', 0 + while _ep <= _elim do + local eid, ewt + eid, ewt, _ep = decode_tag(payload, _ep) + if eid == 1 then + _key, _ep = decode_bytes(payload, _ep) + elseif eid == 2 then + local _u + _u, _ep = decode_varint(payload, _ep) + _val = varint_to_int32(_u) + else + _ep = skip_field(payload, _ep, ewt, eid) + end + end + map[_key] = _val + elseif id == 111 then + local val + val, pos = decode_uint32(buf, pos) + result.oneof_uint32 = val + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 112 then + local payload + payload, pos = decode_len(buf, pos) + local prev = result.oneof_nested_message + if prev == nil then + result.oneof_nested_message = M.TestAllTypesProto3_NestedMessage_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto3_NestedMessage_descriptor, prev, M.TestAllTypesProto3_NestedMessage_decode_unsafe(payload)) + end + result.oneof_uint32 = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 113 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.oneof_string = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.oneof_string = val + end + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 114 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.oneof_bytes = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.oneof_bytes = val + end + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 115 then + local val + val, pos = decode_bool(buf, pos) + result.oneof_bool = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 116 then + local val + val, pos = decode_uint64(buf, pos) + result.oneof_uint64 = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 117 then + local val + val, pos = decode_float(buf, pos) + result.oneof_float = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_double = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 118 then + local val + val, pos = decode_double(buf, pos) + result.oneof_double = val + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_enum = nil + result.oneof_null_value = nil + elseif id == 119 then + local u + u, pos = decode_varint(buf, pos) + result.oneof_enum = varint_to_int32(u) + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_null_value = nil + elseif id == 120 then + local u + u, pos = decode_varint(buf, pos) + result.oneof_null_value = varint_to_int32(u) + result.oneof_uint32 = nil + result.oneof_nested_message = nil + result.oneof_string = nil + result.oneof_bytes = nil + result.oneof_bool = nil + result.oneof_uint64 = nil + result.oneof_float = nil + result.oneof_double = nil + result.oneof_enum = nil + elseif id == 201 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_bool_wrapper = pb.wkt.BoolValue_decode(payload) + elseif id == 202 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_int32_wrapper = pb.wkt.Int32Value_decode(payload) + elseif id == 203 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_int64_wrapper = pb.wkt.Int64Value_decode(payload) + elseif id == 204 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_uint32_wrapper = pb.wkt.UInt32Value_decode(payload) + elseif id == 205 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_uint64_wrapper = pb.wkt.UInt64Value_decode(payload) + elseif id == 206 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_float_wrapper = pb.wkt.FloatValue_decode(payload) + elseif id == 207 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_double_wrapper = pb.wkt.DoubleValue_decode(payload) + elseif id == 208 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_string_wrapper = pb.wkt.StringValue_decode(payload) + elseif id == 209 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_bytes_wrapper = pb.wkt.BytesValue_decode(payload) + elseif id == 211 then + local list = result.repeated_bool_wrapper + if list == nil then list = {}; result.repeated_bool_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_bool_wrapper = _n_repeated_bool_wrapper + 1; list[_n_repeated_bool_wrapper] = pb.wkt.BoolValue_decode(payload) + elseif id == 212 then + local list = result.repeated_int32_wrapper + if list == nil then list = {}; result.repeated_int32_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_int32_wrapper = _n_repeated_int32_wrapper + 1; list[_n_repeated_int32_wrapper] = pb.wkt.Int32Value_decode(payload) + elseif id == 213 then + local list = result.repeated_int64_wrapper + if list == nil then list = {}; result.repeated_int64_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_int64_wrapper = _n_repeated_int64_wrapper + 1; list[_n_repeated_int64_wrapper] = pb.wkt.Int64Value_decode(payload) + elseif id == 214 then + local list = result.repeated_uint32_wrapper + if list == nil then list = {}; result.repeated_uint32_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_uint32_wrapper = _n_repeated_uint32_wrapper + 1; list[_n_repeated_uint32_wrapper] = pb.wkt.UInt32Value_decode(payload) + elseif id == 215 then + local list = result.repeated_uint64_wrapper + if list == nil then list = {}; result.repeated_uint64_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_uint64_wrapper = _n_repeated_uint64_wrapper + 1; list[_n_repeated_uint64_wrapper] = pb.wkt.UInt64Value_decode(payload) + elseif id == 216 then + local list = result.repeated_float_wrapper + if list == nil then list = {}; result.repeated_float_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_float_wrapper = _n_repeated_float_wrapper + 1; list[_n_repeated_float_wrapper] = pb.wkt.FloatValue_decode(payload) + elseif id == 217 then + local list = result.repeated_double_wrapper + if list == nil then list = {}; result.repeated_double_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_double_wrapper = _n_repeated_double_wrapper + 1; list[_n_repeated_double_wrapper] = pb.wkt.DoubleValue_decode(payload) + elseif id == 218 then + local list = result.repeated_string_wrapper + if list == nil then list = {}; result.repeated_string_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_string_wrapper = _n_repeated_string_wrapper + 1; list[_n_repeated_string_wrapper] = pb.wkt.StringValue_decode(payload) + elseif id == 219 then + local list = result.repeated_bytes_wrapper + if list == nil then list = {}; result.repeated_bytes_wrapper = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_bytes_wrapper = _n_repeated_bytes_wrapper + 1; list[_n_repeated_bytes_wrapper] = pb.wkt.BytesValue_decode(payload) + elseif id == 301 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_duration = pb.wkt.Duration_decode(payload) + elseif id == 302 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_timestamp = pb.wkt.Timestamp_decode(payload) + elseif id == 303 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_field_mask = pb.wkt.FieldMask_decode(payload) + elseif id == 304 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_struct = pb.wkt.Struct_decode(payload) + elseif id == 305 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_any = pb.wkt.Any_decode(payload) + elseif id == 306 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_value = pb.wkt.Value_decode(payload) + elseif id == 307 then + local u + u, pos = decode_varint(buf, pos) + result.optional_null_value = varint_to_int32(u) + elseif id == 308 then + local payload + payload, pos = decode_len(buf, pos) + result.optional_empty = pb.wkt.Empty_decode(payload) + elseif id == 311 then + local list = result.repeated_duration + if list == nil then list = {}; result.repeated_duration = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_duration = _n_repeated_duration + 1; list[_n_repeated_duration] = pb.wkt.Duration_decode(payload) + elseif id == 312 then + local list = result.repeated_timestamp + if list == nil then list = {}; result.repeated_timestamp = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_timestamp = _n_repeated_timestamp + 1; list[_n_repeated_timestamp] = pb.wkt.Timestamp_decode(payload) + elseif id == 313 then + local list = result.repeated_fieldmask + if list == nil then list = {}; result.repeated_fieldmask = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_fieldmask = _n_repeated_fieldmask + 1; list[_n_repeated_fieldmask] = pb.wkt.FieldMask_decode(payload) + elseif id == 324 then + local list = result.repeated_struct + if list == nil then list = {}; result.repeated_struct = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_struct = _n_repeated_struct + 1; list[_n_repeated_struct] = pb.wkt.Struct_decode(payload) + elseif id == 315 then + local list = result.repeated_any + if list == nil then list = {}; result.repeated_any = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_any = _n_repeated_any + 1; list[_n_repeated_any] = pb.wkt.Any_decode(payload) + elseif id == 316 then + local list = result.repeated_value + if list == nil then list = {}; result.repeated_value = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_value = _n_repeated_value + 1; list[_n_repeated_value] = pb.wkt.Value_decode(payload) + elseif id == 317 then + local list = result.repeated_list_value + if list == nil then list = {}; result.repeated_list_value = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_list_value = _n_repeated_list_value + 1; list[_n_repeated_list_value] = pb.wkt.ListValue_decode(payload) + elseif id == 318 then + local list = result.repeated_empty + if list == nil then list = {}; result.repeated_empty = list end + local payload + payload, pos = decode_len(buf, pos) + _n_repeated_empty = _n_repeated_empty + 1; list[_n_repeated_empty] = pb.wkt.Empty_decode(payload) + elseif id == 401 then + local val + val, pos = decode_int32(buf, pos) + result.fieldname1 = val + elseif id == 402 then + local val + val, pos = decode_int32(buf, pos) + result.field_name2 = val + elseif id == 403 then + local val + val, pos = decode_int32(buf, pos) + result._field_name3 = val + elseif id == 404 then + local val + val, pos = decode_int32(buf, pos) + result.field__name4_ = val + elseif id == 405 then + local val + val, pos = decode_int32(buf, pos) + result.field0name5 = val + elseif id == 406 then + local val + val, pos = decode_int32(buf, pos) + result.field_0_name6 = val + elseif id == 407 then + local val + val, pos = decode_int32(buf, pos) + result.fieldName7 = val + elseif id == 408 then + local val + val, pos = decode_int32(buf, pos) + result.FieldName8 = val + elseif id == 409 then + local val + val, pos = decode_int32(buf, pos) + result.field_Name9 = val + elseif id == 410 then + local val + val, pos = decode_int32(buf, pos) + result.Field_Name10 = val + elseif id == 411 then + local val + val, pos = decode_int32(buf, pos) + result.FIELD_NAME11 = val + elseif id == 412 then + local val + val, pos = decode_int32(buf, pos) + result.FIELD_name12 = val + elseif id == 413 then + local val + val, pos = decode_int32(buf, pos) + result.__field_name13 = val + elseif id == 414 then + local val + val, pos = decode_int32(buf, pos) + result.__Field_name14 = val + elseif id == 415 then + local val + val, pos = decode_int32(buf, pos) + result.field__name15 = val + elseif id == 416 then + local val + val, pos = decode_int32(buf, pos) + result.field__Name16 = val + elseif id == 417 then + local val + val, pos = decode_int32(buf, pos) + result.field_name17__ = val + elseif id == 418 then + local val + val, pos = decode_int32(buf, pos) + result.Field_name18__ = val + else + local _ebid = M.TestAllTypesProto3_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto3_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto3_descriptor, b) end ---@param t protobuf_test_messages.proto3.TestAllTypesProto3 @@ -4940,6 +6885,58 @@ return result end ---@param b string +---@return protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage +function M.TestAllTypesProto3_NestedMessage_decode_unsafe(buf) + local _d = M.TestAllTypesProto3_NestedMessage_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.a = val + elseif id == 2 then + local payload + payload, pos = wire.decode_len(buf, pos) + local prev = result.corecursive + if prev == nil then + result.corecursive = M.TestAllTypesProto3_decode_unsafe(payload) + else + pb.codec.merge_message(M.TestAllTypesProto3_descriptor, prev, M.TestAllTypesProto3_decode_unsafe(payload)) + end + else + local _ebid = M.TestAllTypesProto3_NestedMessage_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.TestAllTypesProto3_NestedMessage_decode_lazy(b) return pb.decode_lazy(M.TestAllTypesProto3_NestedMessage_descriptor, b) end ---@param t protobuf_test_messages.proto3.TestAllTypesProto3.NestedMessage @@ -4983,6 +6980,49 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.c = val + else + local _ebid = M.ForeignMessage_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto3.ForeignMessage +function M.ForeignMessage_decode_unsafe(buf) + local _d = M.ForeignMessage_descriptor if type(buf) ~= 'string' then error("expected string for protobuf_test_messages.proto3.ForeignMessage decode, got " .. type(buf), 0) end @@ -5097,6 +7137,46 @@ return result end ---@param b string +---@return protobuf_test_messages.proto3.NullHypothesisProto3 +function M.NullHypothesisProto3_decode_unsafe(buf) + local _d = M.NullHypothesisProto3_descriptor + if type(buf) ~= 'string' then + error("expected string for protobuf_test_messages.proto3.NullHypothesisProto3 decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.NullHypothesisProto3_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.NullHypothesisProto3_decode_lazy(b) return pb.decode_lazy(M.NullHypothesisProto3_descriptor, b) end ---@param t protobuf_test_messages.proto3.NullHypothesisProto3 @@ -5134,6 +7214,46 @@ 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 + local result = {} + local pos, len = 1, #buf + local _uf + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if true then + else + local _ebid = M.EnumOnlyProto3_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string +---@return protobuf_test_messages.proto3.EnumOnlyProto3 +function M.EnumOnlyProto3_decode_unsafe(buf) + local _d = M.EnumOnlyProto3_descriptor 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 0e70cabf4b958dd6a795818b3b6f6a3d01ff3c79..3bdb5c01d445c11afd361254bef2980e0528aa4b 100644 --- a/examples/expected/full/quickstart/quickstart_pb.lua +++ b/examples/expected/full/quickstart/quickstart_pb.lua @@ -210,6 +210,85 @@ return result end ---@param b string +---@return quickstart.User +function M.User_decode_unsafe(buf) + local decode_bytes = wire.decode_bytes + local _d = M.User_descriptor + if type(buf) ~= 'string' then + error("expected string for quickstart.User decode, got " .. type(buf), 0) + end + local result = {} + local pos, len = 1, #buf + local _uf + local _n_emails = 0 + while pos <= len do + local _tag_start = pos + local id, wt + local _b = string_byte(buf, pos) + if _b ~= nil and _b < 0x80 then + wt = band(_b, 7) + if wt >= 6 then error("illegal wire type " .. wt, 0) end + id = rshift(_b, 3) + if id == 0 then error("illegal field number 0", 0) end + pos = pos + 1 + else + id, wt, pos = wire.decode_tag(buf, pos) + end + if id == 1 then + local val + val, pos = wire.decode_int32(buf, pos) + result.id = val + elseif id == 2 then + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + result.name = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + result.name = val + end + elseif id == 3 then + local u + u, pos = wire.decode_varint(buf, pos) + result.role = wire.varint_to_int32(u) + elseif id == 4 then + local list = result.emails + if list == nil then list = {}; result.emails = list end + local _lb = string_byte(buf, pos) + if _lb ~= nil and _lb < 0x80 then + local _np = pos + 1 + local _epos = _np + _lb + if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end + local _s = buf:sub(_np, _epos - 1) + _n_emails = _n_emails + 1; list[_n_emails] = _s + pos = _epos + else + local val + val, pos = decode_bytes(buf, pos) + _n_emails = _n_emails + 1; list[_n_emails] = val + end + else + local _ebid = M.User_descriptor.extensions_by_id + local _ext = _ebid and _ebid[id] or nil + if _ext ~= nil then + pos = pb.codec.decode_extension(_ext, buf, pos, wt, result) + else + pos = wire.skip_field(buf, pos, wt, id) + if _uf == nil then _uf = {} end + _uf[#_uf + 1] = buf:sub(_tag_start, pos - 1) + end + end + end + if _uf ~= nil then result._unknown_fields = table.concat(_uf) end + return result +end + +---@param b string ---@return pb.MessageView function M.User_decode_lazy(b) return pb.decode_lazy(M.User_descriptor, b) end ---@param t quickstart.User diff --git a/test/decode_unsafe_test.lua b/test/decode_unsafe_test.lua new file mode 100644 index 0000000000000000000000000000000000000000..0f7bd9c87cec9676fcf155d04ebf02265e6687e7 --- /dev/null +++ b/test/decode_unsafe_test.lua @@ -0,0 +1,99 @@ +-- decode_unsafe: codegen emits a sister _decode_unsafe alongside +-- _decode that skips the per-string utf8_len validation. Intended +-- for re-decoding bytes from a trusted producer (own encoder, JSON/text +-- round-trip, in-process typed RPC). Emitted in full mode only; runtime +-- mode does not currently expose the unsafe path (compiled f._reader +-- closures capture handler.decode by value, so a swap-on-call would not +-- reach them — a proper runtime-mode unsafe path would need parallel +-- _reader_unsafe closures and is intentionally deferred). (6bb) +local t = require('luatest') +local hello = require('full.hello.hello_pb') + +local g = t.group('decode_unsafe.full') + +-- Hand-rolled wire bytes for hello.Address{street=}. Tag for field 1 +-- (wire 2, LEN) is 0x0A; length-prefix is one varint byte for len<128. +local function address_with_street(s) + return string.char(0x0A, #s) .. s +end + +-- Hand-rolled wire bytes for hello.Person{name=}. Tag for field 1 +-- is identical (0x0A). +local function person_with_name(s) + return string.char(0x0A, #s) .. s +end + +g.test_valid_string_matches_safe_decode = function() + local addr = {street = 'Pushkina 1', city = 'Moscow', zip = 123456} + local bytes = hello.Address_encode(addr) + t.assert_equals(hello.Address_decode_unsafe(bytes), + hello.Address_decode(bytes)) +end + +g.test_safe_decode_rejects_invalid_utf8 = function() + -- 0xC0 0x80 is the classic overlong NUL — rejected by RFC 3629 + -- (also banned in proto3 strings). + local bytes = address_with_street('\xC0\x80') + t.assert_error_msg_contains( + 'invalid UTF-8', + function() hello.Address_decode(bytes) end) +end + +g.test_unsafe_decode_accepts_invalid_utf8 = function() + local bytes = address_with_street('\xC0\x80') + local dec = hello.Address_decode_unsafe(bytes) + t.assert_equals(dec.street, '\xC0\x80') +end + +g.test_unsafe_decode_repeated_string = function() + -- Person.emails is a repeated string; two entries, second is invalid. + -- Tag 0x1A = field 3 (emails), wire 2. + local good = 'alice@example.com' + local bad = '\xFF\xFE' + local bytes = string.char(0x1A, #good) .. good + .. string.char(0x1A, #bad) .. bad + t.assert_error_msg_contains( + 'invalid UTF-8', + function() hello.Person_decode(bytes) end) + local dec = hello.Person_decode_unsafe(bytes) + t.assert_equals(dec.emails, {good, bad}) +end + +g.test_unsafe_decode_recurses_into_sub_messages = function() + -- Person{address = Address{street = '\xC0\x80'}}. + -- Tag 0x2A = field 5 (address), wire 2; payload is the Address bytes. + local inner = address_with_street('\xC0\x80') + local bytes = string.char(0x2A, #inner) .. inner + + -- Safe path: nested string rejected (proves nested validation runs by + -- default). + t.assert_error_msg_contains( + 'invalid UTF-8', + function() hello.Person_decode(bytes) end) + + -- Unsafe path: nested call must also be the unsafe variant. If + -- Person_decode_unsafe were to call Address_decode (the safe variant) + -- for sub-messages, this would still error. The recursive dispatch is + -- emitted by inline.go and pinned by this assertion. + local dec = hello.Person_decode_unsafe(bytes) + t.assert_equals(dec.address.street, '\xC0\x80') +end + +g.test_unsafe_decode_handles_long_string_fallback = function() + -- >=128 byte payload exits the 1-byte LEN inline fast path and falls + -- through to wire.decode_bytes (instead of wire.decode_string) on + -- the unsafe path. Exercises the fallback branch in the emitted code. + local big = string.rep('x', 200) .. '\xFF' -- 201 bytes, trailing bad + local bytes = string.char(0x0A) .. string.char(0xC9, 0x01) .. big + -- 201 in varint = 0xC9 0x01. + t.assert_error_msg_contains( + 'invalid UTF-8', + function() hello.Address_decode(bytes) end) + local dec = hello.Address_decode_unsafe(bytes) + t.assert_equals(#dec.street, 201) + t.assert_equals(dec.street:byte(201), 0xFF) +end + +-- Person.name omitted from the above explicitly to keep tests focused; +-- the singular-string scalar path is already covered by Address.street. +_ = person_with_name -- silence unused-local under future trimming