diff --git a/bench/PERF_LOG.md b/bench/PERF_LOG.md index c4315be73aa492daaf68f7e47772abd2e241fa00..08eb50f08fa09ccca28fb5c18a591da0d4d34074 100644 --- a/bench/PERF_LOG.md +++ b/bench/PERF_LOG.md @@ -84,6 +84,100 @@ --- +## 2026-05-18 — 4kj: inline 1-byte tag fast path at decode call sites + +**Task:** [tarantool-protobuf-4kj] Decoder: generated tag/length fast path +for full-mode decode. Profile attributed ~21% of hello.Person 1KB decode +time to `wire.decode_tag` dispatch. + +**Change:** In `cmd/protoc-gen-tarantool/internal/gen/inline.go`, the +generated `M.X_decode` while-loop now decodes the 1-byte tag form inline +before falling back to `wire.decode_tag` for multi-byte. A header tweak +in `gen.go` localizes `string.byte`, `bit.band`, and `bit.rshift` at the +top of every generated file so each call inside the loop becomes a +straight-line local-call. + +```lua +-- Before: +local id, wt +id, wt, pos = wire.decode_tag(buf, pos) + +-- After: +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 +``` + +Field numbers 1..15 always encode as a single byte; that's the +overwhelmingly dominant case in real payloads, including every Person +field in the bench corpus. + +**Tests:** 745/745 pass. JIT trace gate: 37/37, all bridges still 0. + +**Bench (Person full, msgs/s, median-of-3 vs proper post-h8v median-of-3 +baseline):** + +| size | dir | post-h8v | 4kj | Δ | +|-------|-----|-------------|-----------|-----------| +| 10B | dec | 2,247,620 | 2,579,347 | **+14.7%** | +| 100B | dec | 1,949,565 | 2,122,601 | **+8.9%** | +| 1KB | dec | 102,175 | 109,792 | **+7.5%** | +| 10KB | dec | 14,100 | 15,084 | **+7.0%** | +| 100KB | dec | 1,393 | 1,512 | **+8.5%** | +| 10B | enc | 2,291,108 | 2,272,701 | -0.8% | +| 100B | enc | 2,250,757 | 2,313,101 | +2.8% | +| 1KB | enc | 293,677 | 293,367 | -0.1% | +| 10KB | enc | 60,269 | 59,390 | -1.5% | +| 100KB | enc | 6,746 | 6,570 | -2.6% | + +**Methodology note (lesson from gcy):** the post-h8v "single-run" +baseline I'd captured for h8v was a peak run (the bench is noisier than +I'd expected on macOS arm64). For 4kj I re-baselined post-h8v with a +3-run median *before* comparing, which made the decode win obvious and +exposed the encode -1 to -3% as small/within-noise. Going forward, +medians-of-3 are the comparison standard; PERF_LOG entries earlier than +this one used single-run baselines (h8v's numbers are likely tilted +~3-5% optimistic). + +**Bench (proto2_basic.BenchPayload full):** roughly flat — proto2 mid +encode/decode within ±1% of post-h8v. Expected: BenchPayload doesn't +have a tight decode loop the way Person 1KB does. + +**Bench (runtime mode):** the runtime mode wrappers don't see the +inlined fast path — they delegate to `pb.codec.decode`. Runtime decode +1KB measured at 97,285 vs an earlier baseline 103,503, but that baseline +was single-run and inconsistent with the variance I've seen since. +Treating this as noise; no semantic change is plausible for runtime +mode here (only file-header upvalues added, three locals never +referenced by runtime wrappers). + +**Caveats / leftovers:** +- Multi-byte tags (field ids > 15) still pay the `wire.decode_tag` call. + Generated protobuf rarely uses high field numbers, but extensions + often do; the fallback keeps them correct. +- Encode regressed slightly at 10KB+. Plausible cause: three extra + file-level upvalues (band/rshift/string_byte) shift LuaJIT's + function-prologue layout for `Person_encode` even though that + function doesn't use them. Not currently worth optimizing. +- `wire.decode_len` is still a function call. Inlining its byte-read + half can come next, but the substring it produces is unavoidable. +- The richer "order-prediction" form of this task — emit a literal + tag-byte equality check per declared field — is deferred. It would + double-dispatch (literal-match + id-match fallback) and the simple + inline already captures ~half the available gain. + +**Commit:** see git history for SHA. + +--- + ## 2026-05-18 — gcy: inline nested-message decode at the call site (REVERTED) **Task:** [tarantool-protobuf-gcy] Decoder: inline nested-message decode at diff --git a/cmd/protoc-gen-tarantool/internal/gen/gen.go b/cmd/protoc-gen-tarantool/internal/gen/gen.go index 759130815562d30c0f204d5e33925deb08f296ec..8de1de4023f851622353ddf256776f245521c575 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/gen.go +++ b/cmd/protoc-gen-tarantool/internal/gen/gen.go @@ -177,6 +177,12 @@ } w.line("") w.line("local pb = require(%q)", runtimeRequire) w.line("local wire = pb.wire") + // Hot-path locals used by the inlined tag/length fast paths in each + // generated _decode function. Localizing turns the LuaJIT references + // into upvalue reads on the trace instead of repeated global lookups. + w.line("local string_byte = string.byte") + w.line("local band = bit.band") + w.line("local rshift = bit.rshift") } // collectImports returns the deduplicated set of Lua require paths for all diff --git a/cmd/protoc-gen-tarantool/internal/gen/inline.go b/cmd/protoc-gen-tarantool/internal/gen/inline.go index ed69a34de24a57a34e398bbe4a56d9dddb27ad4b..6f4814714e8f835060b3fa96b9f796fbbc0f28ee 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/inline.go +++ b/cmd/protoc-gen-tarantool/internal/gen/inline.go @@ -373,7 +373,22 @@ w.line(" local _uf") w.line(" while pos <= len do") w.line(" local _tag_start = pos") w.line(" local id, wt") - w.line(" id, wt, pos = wire.decode_tag(buf, pos)") + // Inline the 1-byte tag fast path. The protobuf spec encodes field + // numbers 1..15 (with any wire type) in a single byte, and the + // codegen orderings + our test corpora keep nearly every dispatch + // here on the fast branch. Removes the wire.decode_tag function + // frame for the dominant case; multi-byte tags fall back to the + // generic decoder. + w.line(" local _b = string_byte(buf, pos)") + w.line(" if _b ~= nil and _b < 0x80 then") + w.line(" wt = band(_b, 7)") + w.line(" if wt >= 6 then error(\"illegal wire type \" .. wt, 0) end") + w.line(" id = rshift(_b, 3)") + w.line(" if id == 0 then error(\"illegal field number 0\", 0) end") + w.line(" pos = pos + 1") + w.line(" else") + w.line(" id, wt, pos = wire.decode_tag(buf, pos)") + w.line(" end") first := true for _, f := range m.Fields { diff --git a/examples/expected/full/conformance/conformance_pb.lua b/examples/expected/full/conformance/conformance_pb.lua index 522c8700b1b6daf3d472457a19b5fc2fd34a7dde..2351e38b3f36a06fea998160a902170928debba7 100644 --- a/examples/expected/full/conformance/conformance_pb.lua +++ b/examples/expected/full/conformance/conformance_pb.lua @@ -5,6 +5,9 @@ -- package: conformance local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -271,7 +274,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -367,7 +379,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -551,7 +572,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_bytes(buf, pos) @@ -790,7 +820,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -972,7 +1011,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) diff --git a/examples/expected/full/hello/hello_pb.lua b/examples/expected/full/hello/hello_pb.lua index bbb3c0d17d70d135b12c0de483dcd6258260e8e7..061ad258bf84218245c2d0b378cea539e5b10d6f 100644 --- a/examples/expected/full/hello/hello_pb.lua +++ b/examples/expected/full/hello/hello_pb.lua @@ -5,6 +5,9 @@ -- package: hello local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -287,7 +290,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -394,7 +406,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -478,7 +499,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -705,7 +735,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -863,7 +902,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -1150,7 +1198,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) diff --git a/examples/expected/full/proto2_basic/proto2_basic_pb.lua b/examples/expected/full/proto2_basic/proto2_basic_pb.lua index 18eca881aab36c8197dbbe74cfc90d95ac559a9c..b1f907a88d95c19aceb62108aa0bf9272b2ab8e6 100644 --- a/examples/expected/full/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/full/proto2_basic/proto2_basic_pb.lua @@ -5,6 +5,9 @@ -- package: proto2_basic local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -344,7 +347,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -541,7 +553,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -700,7 +721,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -798,7 +828,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -888,7 +927,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -994,7 +1042,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -1086,7 +1143,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -1241,7 +1307,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -1394,7 +1469,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 = wire.decode_int32(buf, pos) @@ -1499,7 +1583,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) 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 25f1cfa7220d83776c2168f34d685e4695fd2bf2..6a7397b104244b915a404e92bf87c46600bccefd 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 @@ -5,6 +5,9 @@ -- package: protobuf_test_messages.proto2 local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -2612,7 +2615,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4541,7 +4553,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4644,7 +4665,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4742,7 +4772,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4834,7 +4873,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4923,7 +4971,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -5062,7 +5119,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 = wire.decode_int32(buf, pos) @@ -5208,7 +5274,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -5285,7 +5360,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -5354,7 +5438,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -5435,7 +5528,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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_string(buf, pos) @@ -5546,7 +5648,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -5995,7 +6106,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -6283,7 +6403,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -6392,7 +6521,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -6539,7 +6677,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -6672,7 +6819,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -6741,7 +6897,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -6810,7 +6975,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -6879,7 +7053,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -6948,7 +7131,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 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 172eda306a511d290d4797add2edd990a9d02b70..28179f786ffbf02b6dda311a768d1e6be316d91a 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 @@ -5,6 +5,9 @@ -- package: protobuf_test_messages.proto3 local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -2766,7 +2769,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4488,7 +4500,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4575,7 +4596,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) @@ -4647,7 +4677,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 @@ -4716,7 +4755,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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 diff --git a/examples/expected/full/quickstart/quickstart_pb.lua b/examples/expected/full/quickstart/quickstart_pb.lua index 3a210a06808b1510a1aff023e79b082432a1ed0e..708fcccce436a51eec1db2d1517b7357c0a9cb97 100644 --- a/examples/expected/full/quickstart/quickstart_pb.lua +++ b/examples/expected/full/quickstart/quickstart_pb.lua @@ -5,6 +5,9 @@ -- package: quickstart local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} @@ -137,7 +140,16 @@ local _uf while pos <= len do local _tag_start = pos local id, wt - id, wt, pos = wire.decode_tag(buf, pos) + 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) diff --git a/examples/expected/runtime/conformance/conformance_pb.lua b/examples/expected/runtime/conformance/conformance_pb.lua index f80bbca3cd87b6bd8c8458394a2605dc4b425352..7c79ece1019f58b0512a24d8b77eb7ec2b310e56 100644 --- a/examples/expected/runtime/conformance/conformance_pb.lua +++ b/examples/expected/runtime/conformance/conformance_pb.lua @@ -5,6 +5,9 @@ -- package: conformance local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} diff --git a/examples/expected/runtime/hello/hello_pb.lua b/examples/expected/runtime/hello/hello_pb.lua index 8dcbc39464ce9aed705ffd1b8d63847a6136c0aa..41c78290c1d25150f86b354646fe52793a1092be 100644 --- a/examples/expected/runtime/hello/hello_pb.lua +++ b/examples/expected/runtime/hello/hello_pb.lua @@ -5,6 +5,9 @@ -- package: hello local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} diff --git a/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua b/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua index 46b43130c9cd99a63a03a7af17e04bfd2f46de08..82672b26e02947fcb096395eb5063d414afedf91 100644 --- a/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua @@ -5,6 +5,9 @@ -- package: proto2_basic local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} diff --git a/examples/expected/runtime/protobuf_test_messages/proto2/test_messages_proto2_pb.lua b/examples/expected/runtime/protobuf_test_messages/proto2/test_messages_proto2_pb.lua index 35f4b6ba3d610e014b03483daf4e84465e60434c..53c3542fadf859a8658c1424bc32c7a9b377fd98 100644 --- a/examples/expected/runtime/protobuf_test_messages/proto2/test_messages_proto2_pb.lua +++ b/examples/expected/runtime/protobuf_test_messages/proto2/test_messages_proto2_pb.lua @@ -5,6 +5,9 @@ -- package: protobuf_test_messages.proto2 local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} diff --git a/examples/expected/runtime/protobuf_test_messages/proto3/test_messages_proto3_pb.lua b/examples/expected/runtime/protobuf_test_messages/proto3/test_messages_proto3_pb.lua index 0b22565d6df05b579edbe5e7d0500b5449447b33..ff1d5a42ef101cb33bf12cae68f9571e3478c339 100644 --- a/examples/expected/runtime/protobuf_test_messages/proto3/test_messages_proto3_pb.lua +++ b/examples/expected/runtime/protobuf_test_messages/proto3/test_messages_proto3_pb.lua @@ -5,6 +5,9 @@ -- package: protobuf_test_messages.proto3 local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {} diff --git a/examples/expected/runtime/quickstart/quickstart_pb.lua b/examples/expected/runtime/quickstart/quickstart_pb.lua index 93e2f0a393758d2d58d37ad816994ec27c51f69c..b416929f581afa6f713ce20c015e4d103a64dba3 100644 --- a/examples/expected/runtime/quickstart/quickstart_pb.lua +++ b/examples/expected/runtime/quickstart/quickstart_pb.lua @@ -5,6 +5,9 @@ -- package: quickstart local pb = require("pb") local wire = pb.wire +local string_byte = string.byte +local band = bit.band +local rshift = bit.rshift local M = {}