diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index c119067f5e9c589acb914f9c417c35a654fe4e18..0bf4cfdbc835c5dc513b98d7c290e51f7b537532 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -69,7 +69,7 @@ {"_type":"issue","id":"tarantool-protobuf-b4j","title":"Docs: migration guide from built-in protobuf to pb","description":"Tarantool ships an encode-only require('protobuf') module. Document the migration path for users currently on the built-in. Cover: API surface differences (no decode in builtin; pb has encode+decode+JSON+text+gRPC+WKT), 64-bit cdata convention parity (both use cdata, no surprise), field-name conventions (both snake_case), the rename rationale (we couldn't override 'protobuf' without breaking existing users). Concrete before/after code samples.","status":"open","priority":3,"issue_type":"task","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:17Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T15:47:17Z","labels":["docs","release"],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-o8n","title":"gRPC: reference network transports (http_server, netbox, http_client_unary)","description":"Ship reference transports as separate Tarantool modules (deferred from M4). Designs in docs/specs/grpc_transports.md. Three transports: (1) pb.grpc.transport.http_server — Connect-JSON over HTTP/1.1 via tarantool/http; default external transport; works with browsers and curl without an HTTP/2 proxy. (2) pb.grpc.transport.netbox — gRPC tunneled over net.box calls; first-class in-cluster path. (3) pb.grpc.transport.http_client_unary — outbound unary only via http_client. HTTP/2 termination explicitly out of scope; the transport contract is HTTP/2-shaped so the same generated code works behind Envoy. Conformance anchor: connectrpc/conformance harness (memory: connect_conformance_suite).","status":"open","priority":3,"issue_type":"feature","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:14Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T15:47:14Z","labels":["grpc","transport"],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-2me","title":"Decide lazy-default for repeated string|bytes fields","description":"Open design question. For routing/proxy workloads that decode but don't iterate every element, repeated LEN fields could stay as unread ArrayViews until first access. Eager callers pay one extra table alloc; lazy callers skip N per-element string allocations. At 100KB Person, 26+ emails = 26+ string allocations deferrable. Decide: (a) flip default for repeated LEN, (b) gate behind a codegen mode/option, (c) leave eager as default and rely on _decode_lazy. Surface compatibility implications (callers iterate with ipairs today and expect a real array) before deciding.","status":"open","priority":3,"issue_type":"decision","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:13Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T15:47:13Z","labels":["decoder","design","perf"],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-0u1","title":"Decoder: decode_len-style byte-then-varint symmetry in typed decoders","description":"The single-byte peek shortcut in decode_len (wire.lua:410-419) isn't replicated in decode_int32 / decode_uint32 / decode_int64 / decode_uint64 / decode_bool / decode_enum, which always call decode_varint(). Mirror the fast path in each typed decoder so the dominant 1-byte varint case skips a function call. Expected: 5-10% on scalar-heavy decodes. Memory: wire_2byte_varint_cliff (same shape, encode side, already fixed).","status":"open","priority":3,"issue_type":"task","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:11Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T15:47:11Z","labels":["decoder","perf","wire"],"dependencies":[{"issue_id":"tarantool-protobuf-0u1","depends_on_id":"tarantool-protobuf-0an","type":"blocks","created_at":"2026-05-17T18:47:21Z","created_by":"Eugene Blikh","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"tarantool-protobuf-a7l","title":"Encoder: static type-elision on scalars in mode=full","description":"wire.to_uint64(v) does a type(v) dispatch in three branches (number/cdata/boolean); in mode=full codegen the field's static type is known. Emit UINT64(v) / INT64(v) directly at the call site and let LuaJIT type-guard the trace. Expected: 10-15% on scalar-heavy messages.","status":"open","priority":3,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:07Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T20:14:50Z","started_at":"2026-05-24T20:11:25Z","labels":["codegen","encoder","perf"],"dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"tarantool-protobuf-a7l","title":"Encoder: static type-elision on scalars in mode=full","description":"wire.to_uint64(v) does a type(v) dispatch in three branches (number/cdata/boolean); in mode=full codegen the field's static type is known. Emit UINT64(v) / INT64(v) directly at the call site and let LuaJIT type-guard the trace. Expected: 10-15% on scalar-heavy messages.","status":"closed","priority":3,"issue_type":"task","assignee":"Eugene Blikh","owner":"bigbes@gmail.com","created_at":"2026-05-17T15:47:07Z","created_by":"Eugene Blikh","updated_at":"2026-05-24T21:02:23Z","started_at":"2026-05-24T20:11:25Z","closed_at":"2026-05-24T21:02:23Z","close_reason":"Codegen emits typed fast variants for sint64/fixed64/sfixed64 — wire.encode_sint64_i(INT64(v)), wire.encode_fixed64_u(UINT64(v)), wire.encode_sfixed64_u(UINT64(v)) — skipping the to_int64/to_uint64 runtime type dispatch at every call site where the field type is statically known. Wire-level: added encode_sint64_i / encode_fixed64_u / encode_sfixed64_u alongside the existing encoders; encode_fixed64 is now a thin wrapper over encode_fixed64_u. INT64/UINT64 added as file-header upvalues alongside ffi.\n\nCodegen applied at: singular non-string scalar, singular required scalar, repeated non-packed per-element, extension singular, extension repeated per-element, packed scalar slow path, proto2 extension repeated. int32/int64/uint32/uint64 unchanged since they alias to encode_varint which doesn't call to_uint64 except on the slow-slow path.\n\nMeasured on c_int64.Wide encode (full mode, no PB_ENABLE_C, 4-run median):\n lua-num inputs 2769 -\u003e 2520 ns/op (+9.9% throughput)\n cdata inputs 12993 -\u003e 12935 ns/op (unchanged; to_int64 already takes the cdata fast path there)\n\nJust below the issue's 10-15% claim but real and measurable, and exactly the case where it matters (Lua-number-input is the common case for user code on sint64/fixed64 fields). Suites: test 766/766, test-c 1057/1057.","labels":["codegen","encoder","perf"],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-cma","title":"Encoder: inline zigzag_encode32 into encode_sint32 (one function call vs two)","description":"encode_sint32(v) = encode_varint(zigzag_encode32(v)) — two function calls. Inline as:\n\n local function encode_sint32(v)\n local n = bit.bxor(bit.lshift(v, 1), bit.arshift(v, 31))\n -- existing 1-byte fast path\n if n \u003e= 0 and n \u003c 0x80 then return string.char(n) end\n return encode_varint_slow(n)\n end\n\nSame for encode_sint64 (with the int64 zigzag formula).\n\nTiny win per sint encode — only matters for sint-heavy payloads. Filed for completeness; h8v makes this moot for mode=full (FFI direct writes inline the whole thing anyway). Real applicability: runtime mode encoders.","notes":"If h8v lands first, this becomes runtime-mode-only and may not be worth the duplication. Defer the call until h8v ships.","status":"open","priority":4,"issue_type":"task","owner":"bigbes@gmail.com","created_at":"2026-05-18T17:15:08Z","created_by":"Eugene Blikh","updated_at":"2026-05-18T17:15:08Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-yvc","title":"Feature: gRPC server reflection service","description":"PLAN.md section 8 lists gRPC server reflection as a non-goal until after M5. M5 is complete, so keep this as deferred future work. Implement standard reflection once real transport/server use cases require it.","status":"open","priority":4,"issue_type":"feature","owner":"bigbes@gmail.com","created_at":"2026-05-17T16:29:18Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T16:29:18Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"tarantool-protobuf-0j5","title":"Feature: Tarantool 3.x config integration for schema registration","description":"PLAN.md section 7 mentions a pb.types.\u003cname\u003e declarative config role as a possible Tarantool 3.x integration. Define the use case first, then design how protobuf schemas/descriptors are declared, loaded, validated, and made available to application roles.","status":"open","priority":4,"issue_type":"feature","owner":"bigbes@gmail.com","created_at":"2026-05-17T16:29:17Z","created_by":"Eugene Blikh","updated_at":"2026-05-17T16:29:17Z","dependency_count":0,"dependent_count":0,"comment_count":0} diff --git a/cmd/protoc-gen-tarantool/internal/gen/gen.go b/cmd/protoc-gen-tarantool/internal/gen/gen.go index f089b21e659da34a65a8265d457ad0264d4875af..bfd8c8a41c9aa5bc25c947741855890528211cf2 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/gen.go +++ b/cmd/protoc-gen-tarantool/internal/gen/gen.go @@ -223,6 +223,12 @@ // decoder hot path uses it for packed repeated fields where the // element count is recoverable from the LEN payload (2sn). LuaJIT // 2.1 (Tarantool's bundled fork) ships `table.new`. w.line("local table_new = require('table.new')") + // Pre-typed cdata constructors for sint64/fixed64/sfixed64 singular + // encode sites — the codegen casts at the call site instead of going + // through wire.to_int64 / wire.to_uint64's runtime type dispatch (a7l). + w.line("local ffi = require('ffi')") + w.line("local INT64 = ffi.typeof('int64_t')") + w.line("local UINT64 = ffi.typeof('uint64_t')") } // 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 04cea05616143435ba7f7883704e1feca611251c..77c51b2aaa125639a3b6fce1887c82aa7f4b297b 100644 --- a/cmd/protoc-gen-tarantool/internal/gen/inline.go +++ b/cmd/protoc-gen-tarantool/internal/gen/inline.go @@ -10,6 +10,26 @@ "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) +// encodeCallExpr returns the Lua expression that encodes a single value +// of the given scalar type `st`. For types where mode=full can elide +// wire.to_int64 / wire.to_uint64's runtime type dispatch (sint64, fixed64, +// sfixed64), the expression pre-casts the value to int64_t / uint64_t at +// the call site and routes through the typed fast variant (encode_sint64_i +// / encode_fixed64_u / encode_sfixed64_u). For everything else it emits +// the generic wire.encode_ call. INT64 and UINT64 are localized in +// the file header (see emitHeader). (a7l) +func encodeCallExpr(st, valExpr string) string { + switch st { + case "sint64": + return fmt.Sprintf("wire.encode_sint64_i(INT64(%s))", valExpr) + case "fixed64": + return fmt.Sprintf("wire.encode_fixed64_u(UINT64(%s))", valExpr) + case "sfixed64": + return fmt.Sprintf("wire.encode_sfixed64_u(UINT64(%s))", valExpr) + } + return fmt.Sprintf("wire.encode_%s(%s)", st, valExpr) +} + // wireRefRe matches `wire.` references inside generated function // bodies. Generated code never embeds `wire.` inside a string literal, so a // straight textual sweep is safe here. (Verified: error messages mention @@ -314,8 +334,8 @@ w.line("%sif type(_e) == 'number' and _e >= -64 and _e <= 63 then", indent) w.line("%s %s = %s + 1; %s[%s] = CHARS[bit.bxor(bit.lshift(_e, 1), bit.arshift(_e, 31))]", indent, idx, idx, list, idx) w.line("%selse", indent) - w.line("%s %s = %s + 1; %s[%s] = wire.encode_%s(_e)", - indent, idx, idx, list, idx, st) + w.line("%s %s = %s + 1; %s[%s] = %s", + indent, idx, idx, list, idx, encodeCallExpr(st, "_e")) w.line("%send", indent) case "int32", "int64", "uint32", "uint64": w.line("%slocal _e = %s", indent, valExpr) @@ -323,12 +343,12 @@ w.line("%sif type(_e) == 'number' and _e >= 0 and _e < 128 then", indent) w.line("%s %s = %s + 1; %s[%s] = CHARS[_e]", indent, idx, idx, list, idx) w.line("%selse", indent) - w.line("%s %s = %s + 1; %s[%s] = wire.encode_%s(_e)", - indent, idx, idx, list, idx, st) + w.line("%s %s = %s + 1; %s[%s] = %s", + indent, idx, idx, list, idx, encodeCallExpr(st, "_e")) w.line("%send", indent) default: - w.line("%s%s = %s + 1; %s[%s] = wire.encode_%s(%s)", - indent, idx, idx, list, idx, st, valExpr) + w.line("%s%s = %s + 1; %s[%s] = %s", + indent, idx, idx, list, idx, encodeCallExpr(st, valExpr)) } } @@ -455,7 +475,7 @@ emitInlineLenPrefix(w, " ", "v") w.line(" n = n + 1; out[n] = v") } else { w.line(" n = n + 1; out[n] = %s", tag) - w.line(" n = n + 1; out[n] = wire.encode_%s(v)", st) + w.line(" n = n + 1; out[n] = %s", encodeCallExpr(st, "v")) } w.line(" end") } @@ -498,7 +518,7 @@ emitInlineLenPrefix(w, " ", "v") w.line(" n = n + 1; out[n] = v") } else { w.line(" n = n + 1; out[n] = %s", tag) - w.line(" n = n + 1; out[n] = wire.encode_%s(v)", st) + w.line(" n = n + 1; out[n] = %s", encodeCallExpr(st, "v")) } } } @@ -579,7 +599,7 @@ w.line(" if v ~= nil and #v > 0 then") w.line(" local _tag = %s", tag) w.line(" for _i = 1, #v do") w.line(" n = n + 1; out[n] = _tag") - w.line(" n = n + 1; out[n] = wire.encode_%s(v[_i])", st) + w.line(" n = n + 1; out[n] = %s", encodeCallExpr(st, "v[_i]")) w.line(" end") w.line(" end") } @@ -646,7 +666,7 @@ emitInlineLenPrefix(w, " ", "_ev") w.line(" n = n + 1; out[n] = _ev") } else { w.line(" n = n + 1; out[n] = %s", tag) - w.line(" n = n + 1; out[n] = wire.encode_%s(_ev)", st) + w.line(" n = n + 1; out[n] = %s", encodeCallExpr(st, "_ev")) } w.line(" end") } @@ -747,7 +767,7 @@ w.line(" if _ev ~= nil and #_ev > 0 then") w.line(" local _tag = %s", tag) w.line(" for _i = 1, #_ev do") w.line(" n = n + 1; out[n] = _tag") - w.line(" n = n + 1; out[n] = wire.encode_%s(_ev[_i])", st) + w.line(" n = n + 1; out[n] = %s", encodeCallExpr(st, "_ev[_i]")) w.line(" end") w.line(" end") } @@ -1373,8 +1393,8 @@ w.line(" %s = %s + 1; %s[%s] = wire.encode_int32(_nv)", idx, idx, list, idx) default: st := scalarName(f.Desc.Kind()) w.line(" %s = %s + 1; %s[%s] = %s", idx, idx, list, idx, tag) - w.line(" %s = %s + 1; %s[%s] = wire.encode_%s(%s)", - idx, idx, list, idx, st, valExpr) + w.line(" %s = %s + 1; %s[%s] = %s", + idx, idx, list, idx, encodeCallExpr(st, valExpr)) } } diff --git a/examples/expected/full/c_int64/c_int64_pb.lua b/examples/expected/full/c_int64/c_int64_pb.lua index 962568f25184ef2a2d0e3e945b9a866d0f608e69..10d2fa6d88c2dac37efbcb105f8bfe3a182df44e 100644 --- a/examples/expected/full/c_int64/c_int64_pb.lua +++ b/examples/expected/full/c_int64/c_int64_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} @@ -79,19 +82,19 @@ -- field 3: a_sint64 v = t.a_sint64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x18" - n = n + 1; out[n] = wire.encode_sint64(v) + n = n + 1; out[n] = wire.encode_sint64_i(INT64(v)) end -- field 4: a_fixed64 v = t.a_fixed64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x21" - n = n + 1; out[n] = wire.encode_fixed64(v) + n = n + 1; out[n] = wire.encode_fixed64_u(UINT64(v)) end -- field 5: a_sfixed64 v = t.a_sfixed64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x29" - n = n + 1; out[n] = wire.encode_sfixed64(v) + n = n + 1; out[n] = wire.encode_sfixed64_u(UINT64(v)) end local _uf = t._unknown_fields if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end diff --git a/examples/expected/full/c_nested/c_nested_pb.lua b/examples/expected/full/c_nested/c_nested_pb.lua index 63e2c67351b3a1140d673b0d2537fe40907903d0..509702ff2daae3a7c40ec46e4c3b6923877a00a2 100644 --- a/examples/expected/full/c_nested/c_nested_pb.lua +++ b/examples/expected/full/c_nested/c_nested_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/full/c_repeated/c_repeated_pb.lua b/examples/expected/full/c_repeated/c_repeated_pb.lua index 1fdaec54f64e8c61059410769713ceb0672e43e7..d67ad930fd95a8300437bebf0907b48b044d1da3 100644 --- a/examples/expected/full/c_repeated/c_repeated_pb.lua +++ b/examples/expected/full/c_repeated/c_repeated_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} @@ -331,7 +334,7 @@ ---@param t c_repeated.Holder ---@return string function M.Holder_encode(t) - local encode_fixed64 = wire.encode_fixed64 + local encode_fixed64_u = wire.encode_fixed64_u local encode_int32 = wire.encode_int32 local encode_sint32 = wire.encode_sint32 local encode_varint = wire.encode_varint @@ -461,7 +464,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_fixed64(v[_i]) + m = m + 1; parts[m] = encode_fixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\x32" @@ -542,7 +545,7 @@ if v ~= nil and #v > 0 then local _tag = "\xa9\x01" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_fixed64(v[_i]) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v[_i])) end end -- field 22: unpacked_sint32 diff --git a/examples/expected/full/conformance/conformance_pb.lua b/examples/expected/full/conformance/conformance_pb.lua index 093431a76ea04b959ba69e1740eb079bf7edefb1..26bc28b9220ac803f918d5927f89f75e7f2c38de 100644 --- a/examples/expected/full/conformance/conformance_pb.lua +++ b/examples/expected/full/conformance/conformance_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/full/hello/hello_pb.lua b/examples/expected/full/hello/hello_pb.lua index f8aa91a5e34f64525d05271a13873b6c2a0ef4d0..69d7082fc354ef5be77fd78d18a0130b29ab4e6e 100644 --- a/examples/expected/full/hello/hello_pb.lua +++ b/examples/expected/full/hello/hello_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} @@ -1915,7 +1918,7 @@ -- field 9: user_id v = t.user_id if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x49" - n = n + 1; out[n] = wire.encode_fixed64(v) + n = n + 1; out[n] = wire.encode_fixed64_u(UINT64(v)) end -- field 10: balance v = t.balance diff --git a/examples/expected/full/proto2_basic/proto2_basic_pb.lua b/examples/expected/full/proto2_basic/proto2_basic_pb.lua index 147bbdb56ce1fe4609084d5cc9429ea7aca54bdc..e71312cae873cb5fc488b3a6b68a39c5fd8bad81 100644 --- a/examples/expected/full/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/full/proto2_basic/proto2_basic_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} 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 5c1d2bfbe35ffbe8946d8f1ce6d99891248a3479..6f14d9b2dfa08c880251e887df415f8c26719a71 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 @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} @@ -908,15 +911,15 @@ function M.TestAllTypesProto2_encode(t) local encode_bool = wire.encode_bool local encode_double = wire.encode_double local encode_fixed32 = wire.encode_fixed32 - local encode_fixed64 = wire.encode_fixed64 + local encode_fixed64_u = wire.encode_fixed64_u local encode_float = wire.encode_float local encode_int32 = wire.encode_int32 local encode_int64 = wire.encode_int64 local encode_len = wire.encode_len local encode_sfixed32 = wire.encode_sfixed32 - local encode_sfixed64 = wire.encode_sfixed64 + local encode_sfixed64_u = wire.encode_sfixed64_u local encode_sint32 = wire.encode_sint32 - local encode_sint64 = wire.encode_sint64 + local encode_sint64_i = wire.encode_sint64_i local encode_string = wire.encode_string local encode_uint32 = wire.encode_uint32 local encode_uint64 = wire.encode_uint64 @@ -975,7 +978,7 @@ -- field 6: optional_sint64 v = t.optional_sint64 if v ~= nil then n = n + 1; out[n] = "\x30" - n = n + 1; out[n] = encode_sint64(v) + n = n + 1; out[n] = encode_sint64_i(INT64(v)) end -- field 7: optional_fixed32 v = t.optional_fixed32 @@ -987,7 +990,7 @@ -- field 8: optional_fixed64 v = t.optional_fixed64 if v ~= nil then n = n + 1; out[n] = "\x41" - n = n + 1; out[n] = encode_fixed64(v) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v)) end -- field 9: optional_sfixed32 v = t.optional_sfixed32 @@ -999,7 +1002,7 @@ -- field 10: optional_sfixed64 v = t.optional_sfixed64 if v ~= nil then n = n + 1; out[n] = "\x51" - n = n + 1; out[n] = encode_sfixed64(v) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v)) end -- field 11: optional_float v = t.optional_float @@ -1179,7 +1182,7 @@ if v ~= nil and #v > 0 then local _tag = "\xa0\x02" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sint64(v[_i]) + n = n + 1; out[n] = encode_sint64_i(INT64(v[_i])) end end -- field 37: repeated_fixed32 @@ -1197,7 +1200,7 @@ if v ~= nil and #v > 0 then local _tag = "\xb1\x02" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_fixed64(v[_i]) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v[_i])) end end -- field 39: repeated_sfixed32 @@ -1215,7 +1218,7 @@ if v ~= nil and #v > 0 then local _tag = "\xc1\x02" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sfixed64(v[_i]) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v[_i])) end end -- field 41: repeated_float @@ -1524,7 +1527,7 @@ local _e = v[_i] if type(_e) == 'number' and _e >= -64 and _e <= 63 then m = m + 1; parts[m] = CHARS[bit.bxor(bit.lshift(_e, 1), bit.arshift(_e, 31))] else - m = m + 1; parts[m] = encode_sint64(_e) + m = m + 1; parts[m] = encode_sint64_i(INT64(_e)) end end local _b = table.concat(parts) @@ -1561,7 +1564,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_fixed64(v[_i]) + m = m + 1; parts[m] = encode_fixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\x92\x05" @@ -1597,7 +1600,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_sfixed64(v[_i]) + m = m + 1; parts[m] = encode_sfixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\xa2\x05" @@ -1743,7 +1746,7 @@ if v ~= nil and #v > 0 then local _tag = "\xf0\x05" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sint64(v[_i]) + n = n + 1; out[n] = encode_sint64_i(INT64(v[_i])) end end -- field 95: unpacked_fixed32 @@ -1761,7 +1764,7 @@ if v ~= nil and #v > 0 then local _tag = "\x81\x06" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_fixed64(v[_i]) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v[_i])) end end -- field 97: unpacked_sfixed32 @@ -1779,7 +1782,7 @@ if v ~= nil and #v > 0 then local _tag = "\x91\x06" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sfixed64(v[_i]) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v[_i])) end end -- field 99: unpacked_float @@ -1971,11 +1974,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_sint64(_k) + _m = _m + 1; entry[_m] = encode_sint64_i(INT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_sint64(_val) + _m = _m + 1; entry[_m] = encode_sint64_i(INT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) @@ -2021,11 +2024,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_fixed64(_k) + _m = _m + 1; entry[_m] = encode_fixed64_u(UINT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_fixed64(_val) + _m = _m + 1; entry[_m] = encode_fixed64_u(UINT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) @@ -2071,11 +2074,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_sfixed64(_k) + _m = _m + 1; entry[_m] = encode_sfixed64_u(UINT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_sfixed64(_val) + _m = _m + 1; entry[_m] = encode_sfixed64_u(UINT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) @@ -2499,7 +2502,7 @@ -- field 246: default_sint64 v = t.default_sint64 if v ~= nil then n = n + 1; out[n] = "\xb0\x0f" - n = n + 1; out[n] = encode_sint64(v) + n = n + 1; out[n] = encode_sint64_i(INT64(v)) end -- field 247: default_fixed32 v = t.default_fixed32 @@ -2511,7 +2514,7 @@ -- field 248: default_fixed64 v = t.default_fixed64 if v ~= nil then n = n + 1; out[n] = "\xc1\x0f" - n = n + 1; out[n] = encode_fixed64(v) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v)) end -- field 249: default_sfixed32 v = t.default_sfixed32 @@ -2523,7 +2526,7 @@ -- field 250: default_sfixed64 v = t.default_sfixed64 if v ~= nil then n = n + 1; out[n] = "\xd1\x0f" - n = n + 1; out[n] = encode_sfixed64(v) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v)) end -- field 251: default_float v = t.default_float @@ -9920,14 +9923,14 @@ function M.TestAllRequiredTypesProto2_encode(t) local encode_bool = wire.encode_bool local encode_double = wire.encode_double local encode_fixed32 = wire.encode_fixed32 - local encode_fixed64 = wire.encode_fixed64 + local encode_fixed64_u = wire.encode_fixed64_u local encode_float = wire.encode_float local encode_int32 = wire.encode_int32 local encode_int64 = wire.encode_int64 local encode_sfixed32 = wire.encode_sfixed32 - local encode_sfixed64 = wire.encode_sfixed64 + local encode_sfixed64_u = wire.encode_sfixed64_u local encode_sint32 = wire.encode_sint32 - local encode_sint64 = wire.encode_sint64 + local encode_sint64_i = wire.encode_sint64_i local encode_uint32 = wire.encode_uint32 local encode_uint64 = wire.encode_uint64 local encode_varint = wire.encode_varint @@ -9982,7 +9985,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_sint64", 0) end n = n + 1; out[n] = "\x30" - n = n + 1; out[n] = encode_sint64(v) + n = n + 1; out[n] = encode_sint64_i(INT64(v)) -- field 7: required_fixed32 v = t.required_fixed32 if v == nil then @@ -9996,7 +9999,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_fixed64", 0) end n = n + 1; out[n] = "\x41" - n = n + 1; out[n] = encode_fixed64(v) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v)) -- field 9: required_sfixed32 v = t.required_sfixed32 if v == nil then @@ -10010,7 +10013,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_sfixed64", 0) end n = n + 1; out[n] = "\x51" - n = n + 1; out[n] = encode_sfixed64(v) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v)) -- field 11: required_float v = t.required_float if v == nil then @@ -10222,7 +10225,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.default_sint64", 0) end n = n + 1; out[n] = "\xb0\x0f" - n = n + 1; out[n] = encode_sint64(v) + n = n + 1; out[n] = encode_sint64_i(INT64(v)) -- field 247: default_fixed32 v = t.default_fixed32 if v == nil then @@ -10236,7 +10239,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.default_fixed64", 0) end n = n + 1; out[n] = "\xc1\x0f" - n = n + 1; out[n] = encode_fixed64(v) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v)) -- field 249: default_sfixed32 v = t.default_sfixed32 if v == nil then @@ -10250,7 +10253,7 @@ if v == nil then error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.default_sfixed64", 0) end n = n + 1; out[n] = "\xd1\x0f" - n = n + 1; out[n] = encode_sfixed64(v) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v)) -- field 251: default_float v = t.default_float if v == nil then 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 ea2f6c04947810c5e85071fd7c4e934302846ec5..918bb8e5d5fdaf15de943453490fae48bcca342e 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 @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} @@ -602,15 +605,15 @@ function M.TestAllTypesProto3_encode(t) local encode_bool = wire.encode_bool local encode_double = wire.encode_double local encode_fixed32 = wire.encode_fixed32 - local encode_fixed64 = wire.encode_fixed64 + local encode_fixed64_u = wire.encode_fixed64_u local encode_float = wire.encode_float local encode_int32 = wire.encode_int32 local encode_int64 = wire.encode_int64 local encode_len = wire.encode_len local encode_sfixed32 = wire.encode_sfixed32 - local encode_sfixed64 = wire.encode_sfixed64 + local encode_sfixed64_u = wire.encode_sfixed64_u local encode_sint32 = wire.encode_sint32 - local encode_sint64 = wire.encode_sint64 + local encode_sint64_i = wire.encode_sint64_i local encode_string = wire.encode_string local encode_uint32 = wire.encode_uint32 local encode_uint64 = wire.encode_uint64 @@ -670,7 +673,7 @@ -- field 6: optional_sint64 v = t.optional_sint64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x30" - n = n + 1; out[n] = encode_sint64(v) + n = n + 1; out[n] = encode_sint64_i(INT64(v)) end -- field 7: optional_fixed32 v = t.optional_fixed32 @@ -682,7 +685,7 @@ -- field 8: optional_fixed64 v = t.optional_fixed64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x41" - n = n + 1; out[n] = encode_fixed64(v) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v)) end -- field 9: optional_sfixed32 v = t.optional_sfixed32 @@ -694,7 +697,7 @@ -- field 10: optional_sfixed64 v = t.optional_sfixed64 if v ~= nil and v ~= 0 then n = n + 1; out[n] = "\x51" - n = n + 1; out[n] = encode_sfixed64(v) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v)) end -- field 11: optional_float v = t.optional_float @@ -965,7 +968,7 @@ local _e = v[_i] if type(_e) == 'number' and _e >= -64 and _e <= 63 then m = m + 1; parts[m] = CHARS[bit.bxor(bit.lshift(_e, 1), bit.arshift(_e, 31))] else - m = m + 1; parts[m] = encode_sint64(_e) + m = m + 1; parts[m] = encode_sint64_i(INT64(_e)) end end local _b = table.concat(parts) @@ -1002,7 +1005,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_fixed64(v[_i]) + m = m + 1; parts[m] = encode_fixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\xb2\x02" @@ -1038,7 +1041,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_sfixed64(v[_i]) + m = m + 1; parts[m] = encode_sfixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\xc2\x02" @@ -1383,7 +1386,7 @@ local _e = v[_i] if type(_e) == 'number' and _e >= -64 and _e <= 63 then m = m + 1; parts[m] = CHARS[bit.bxor(bit.lshift(_e, 1), bit.arshift(_e, 31))] else - m = m + 1; parts[m] = encode_sint64(_e) + m = m + 1; parts[m] = encode_sint64_i(INT64(_e)) end end local _b = table.concat(parts) @@ -1420,7 +1423,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_fixed64(v[_i]) + m = m + 1; parts[m] = encode_fixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\x92\x05" @@ -1456,7 +1459,7 @@ if v ~= nil and #v > 0 then local _n = #v local parts, m = table_new(_n, 0), 0 for _i = 1, _n do - m = m + 1; parts[m] = encode_sfixed64(v[_i]) + m = m + 1; parts[m] = encode_sfixed64_u(UINT64(v[_i])) end local _b = table.concat(parts) n = n + 1; out[n] = "\xa2\x05" @@ -1602,7 +1605,7 @@ if v ~= nil and #v > 0 then local _tag = "\xf0\x05" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sint64(v[_i]) + n = n + 1; out[n] = encode_sint64_i(INT64(v[_i])) end end -- field 95: unpacked_fixed32 @@ -1620,7 +1623,7 @@ if v ~= nil and #v > 0 then local _tag = "\x81\x06" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_fixed64(v[_i]) + n = n + 1; out[n] = encode_fixed64_u(UINT64(v[_i])) end end -- field 97: unpacked_sfixed32 @@ -1638,7 +1641,7 @@ if v ~= nil and #v > 0 then local _tag = "\x91\x06" for _i = 1, #v do n = n + 1; out[n] = _tag - n = n + 1; out[n] = encode_sfixed64(v[_i]) + n = n + 1; out[n] = encode_sfixed64_u(UINT64(v[_i])) end end -- field 99: unpacked_float @@ -1830,11 +1833,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_sint64(_k) + _m = _m + 1; entry[_m] = encode_sint64_i(INT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_sint64(_val) + _m = _m + 1; entry[_m] = encode_sint64_i(INT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) @@ -1880,11 +1883,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_fixed64(_k) + _m = _m + 1; entry[_m] = encode_fixed64_u(UINT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_fixed64(_val) + _m = _m + 1; entry[_m] = encode_fixed64_u(UINT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) @@ -1930,11 +1933,11 @@ for _k, _val in pairs(v) do local entry, _m = {}, 0 if _k ~= 0 then _m = _m + 1; entry[_m] = _ktag - _m = _m + 1; entry[_m] = encode_sfixed64(_k) + _m = _m + 1; entry[_m] = encode_sfixed64_u(UINT64(_k)) end if _val ~= 0 then _m = _m + 1; entry[_m] = _vtag - _m = _m + 1; entry[_m] = encode_sfixed64(_val) + _m = _m + 1; entry[_m] = encode_sfixed64_u(UINT64(_val)) end n = n + 1; out[n] = _tag local _b = table.concat(entry) diff --git a/examples/expected/full/quickstart/quickstart_pb.lua b/examples/expected/full/quickstart/quickstart_pb.lua index d8507f3fa8c6c0cab0515608804e2feb457033fe..4c6b4c4998ed5c0aabfa8bdac623d1fc3f1988eb 100644 --- a/examples/expected/full/quickstart/quickstart_pb.lua +++ b/examples/expected/full/quickstart/quickstart_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/c_int64/c_int64_pb.lua b/examples/expected/runtime/c_int64/c_int64_pb.lua index 6c2c32240f76be8db90edf3f31770c295d844093..05a94014ca4cfc7e8289acf3f42f8c0992c2a538 100644 --- a/examples/expected/runtime/c_int64/c_int64_pb.lua +++ b/examples/expected/runtime/c_int64/c_int64_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/c_nested/c_nested_pb.lua b/examples/expected/runtime/c_nested/c_nested_pb.lua index e6703fceaad5df20f0b37280ba953a28d5c3efab..e2b75235fc0a0152c4b9b0b52aea968d8dffb9e9 100644 --- a/examples/expected/runtime/c_nested/c_nested_pb.lua +++ b/examples/expected/runtime/c_nested/c_nested_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/c_repeated/c_repeated_pb.lua b/examples/expected/runtime/c_repeated/c_repeated_pb.lua index 291e961b951c68aeb45833f34edbfc8f4e1b6c44..438de0870ba18696f6c75c104e0700b2954fe929 100644 --- a/examples/expected/runtime/c_repeated/c_repeated_pb.lua +++ b/examples/expected/runtime/c_repeated/c_repeated_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/conformance/conformance_pb.lua b/examples/expected/runtime/conformance/conformance_pb.lua index 5087cbb0105e3237c93830d93a5379a1adf4e513..6539071f5f7506750dbaeebd86e77a111cac2e70 100644 --- a/examples/expected/runtime/conformance/conformance_pb.lua +++ b/examples/expected/runtime/conformance/conformance_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/hello/hello_pb.lua b/examples/expected/runtime/hello/hello_pb.lua index 2efa22c0752da09e31f00fe4ca6d089e8fa7c326..5045a2ca205ba4a605f5b02680638fd0a47eb846 100644 --- a/examples/expected/runtime/hello/hello_pb.lua +++ b/examples/expected/runtime/hello/hello_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') 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 747fca0f3f5317291876802b65833a1e0c567e8b..66fc20004b2b9c8b045bcd0013fa3f568f66c142 100644 --- a/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua +++ b/examples/expected/runtime/proto2_basic/proto2_basic_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') 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 838c54d509cc4b5338b3d60930f200c571d5275b..edc57c3138aa45c9b694fc3168ed7b9961f1ced1 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 @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') 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 ae0235c377e36a5ccba595aed232696104951f2b..befa95df363b7bbe8d69878cc48259a46121acbe 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 @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/examples/expected/runtime/quickstart/quickstart_pb.lua b/examples/expected/runtime/quickstart/quickstart_pb.lua index ba02be7439622b84980d3295842ed6d5e921ab5a..53a9ccc0606d774ea3a123d1c7ddc595d37d2590 100644 --- a/examples/expected/runtime/quickstart/quickstart_pb.lua +++ b/examples/expected/runtime/quickstart/quickstart_pb.lua @@ -11,6 +11,9 @@ local band = bit.band local rshift = bit.rshift local CHARS = wire.CHARS local table_new = require('table.new') +local ffi = require('ffi') +local INT64 = ffi.typeof('int64_t') +local UINT64 = ffi.typeof('uint64_t') local M = {} diff --git a/runtime/pb/wire.lua b/runtime/pb/wire.lua index 568bd78bd247001052073db49705d483a5085879..beb9b2920dcdcce7637005fb36ce728a6afa88a2 100644 --- a/runtime/pb/wire.lua +++ b/runtime/pb/wire.lua @@ -286,6 +286,16 @@ return bit.bnot(doubled) end M.zigzag_encode64 = zigzag_encode64 +-- Variant that takes an int64_t cdata directly, skipping the to_int64() +-- type-dispatch wrapper. Use from mode=full codegen sites where the field +-- type is statically known (a7l). +local function zigzag_encode64_i(i) + local doubled = bit.lshift(UINT64(i), 1) + if i >= 0 then return doubled end + return bit.bnot(doubled) +end +M.zigzag_encode64_i = zigzag_encode64_i + local function zigzag_decode64(u) u = to_uint64(u) local half = bit.rshift(u, 1) @@ -323,8 +333,8 @@ return b1 + b2 * 0x100 + b3 * 0x10000 + b4 * 0x1000000, pos + 4 end M.decode_fixed32 = decode_fixed32 -local function encode_fixed64(v) - local u = to_uint64(v) +-- Body shared by encode_fixed64 and encode_fixed64_u. Takes a uint64_t cdata. +local function encode_fixed64_u(u) local lo = tonumber(bit.band(u, 0xffffffff)) local hi = tonumber(bit.rshift(u, 32)) return string.char( @@ -337,7 +347,16 @@ bit.band(bit.rshift(hi, 8), 0xff), bit.band(bit.rshift(hi, 16), 0xff), bit.band(bit.rshift(hi, 24), 0xff)) end -M.encode_fixed64 = encode_fixed64 +-- Generic wrapper: accepts Lua number / cdata / boolean via to_uint64. +local function encode_fixed64(v) + return encode_fixed64_u(to_uint64(v)) +end +M.encode_fixed64 = encode_fixed64 +-- Variant for mode=full codegen sites where the value is already a uint64_t +-- cdata (caller wraps with UINT64() at the static-type-known call site). +-- Used for fixed64 and sfixed64 (sfixed64 reuses this body — same bit +-- pattern, different sign interpretation). (a7l) +M.encode_fixed64_u = encode_fixed64_u -- decode_fixed64(buf, pos) -> uint64_t cdata, new_pos -- Reading via the FFI union avoids the multi-step `UINT64(lo) + @@ -461,8 +480,14 @@ M.encode_sint32 = encode_sint32 M.encode_sint64 = encode_sint64 M.encode_bool = encode_bool -M.encode_sfixed32 = encode_fixed32 -- bits are identical, only interpretation differs -M.encode_sfixed64 = encode_fixed64 +-- Fast variant for mode=full codegen: takes an int64_t cdata, skips to_int64. +local function encode_sint64_i(i) return encode_varint(zigzag_encode64_i(i)) end +M.encode_sint64_i = encode_sint64_i + +M.encode_sfixed32 = encode_fixed32 -- bits are identical, only interpretation differs +M.encode_sfixed64 = encode_fixed64 +-- sfixed64 reuses encode_fixed64_u — same 8-byte little-endian shape. +M.encode_sfixed64_u = encode_fixed64_u M.encode_string = encode_len M.encode_bytes = encode_len -- (encode_fixed32, encode_fixed64, encode_float, encode_double already on M)