-- Code generated by protoc-gen-tarantool. DO NOT EDIT.
-- source: proto2_basic.proto
-- syntax: proto2
-- package: proto2_basic
local pb = require("pb")
local wire = pb.wire
local string_byte = string.byte
local utf8_len = require('utf8').len
local band = bit.band
local rshift = bit.rshift
local CHARS = wire.CHARS
local table_new = require('table.new')
local M = {}
M.options = {go_package = "tarantoolpb_synthetic/proto2_basic"}
-- Enum: proto2_basic.Defaults.Color
M.Defaults_Color_descriptor = pb.enum("proto2_basic.Defaults.Color", {
RED = 0,
GREEN = 1,
BLUE = 2,
})
M.Defaults_Color_descriptor.closed = true
M.Defaults_Color = M.Defaults_Color_descriptor.by_name
-- Pre-declare message descriptors so cross-references resolve.
M.Defaults_descriptor = {name = "proto2_basic.Defaults"}
M.Cardinality_descriptor = {name = "proto2_basic.Cardinality"}
M.Nested_descriptor = {name = "proto2_basic.Nested"}
M.Nested_Inner_descriptor = {name = "proto2_basic.Nested.Inner"}
M.WithGroup_descriptor = {name = "proto2_basic.WithGroup"}
M.WithGroup_SingleGroup_descriptor = {name = "proto2_basic.WithGroup.SingleGroup"}
M.WithGroup_RepGroup_descriptor = {name = "proto2_basic.WithGroup.RepGroup"}
M.BenchPayload_descriptor = {name = "proto2_basic.BenchPayload"}
M.BenchPayload_Stats_descriptor = {name = "proto2_basic.BenchPayload.Stats"}
M.BenchPayload_Inner_descriptor = {name = "proto2_basic.BenchPayload.Inner"}
-- Message: proto2_basic.Defaults
M.Defaults_descriptor.fields = {
{name="i", id=1, kind='scalar', proto_type="int32", optional=true, default_value=17},
{name="s", id=2, kind='scalar', proto_type="string", optional=true, default_value="hello"},
{name="b", id=3, kind='scalar', proto_type="bool", optional=true, default_value=true},
{name="f", id=4, kind='scalar', proto_type="float", optional=true, default_value=3.5},
{name="d", id=5, kind='scalar', proto_type="double", optional=true, default_value=1.5},
{name="i64", id=6, kind='scalar', proto_type="int64", optional=true, default_value=1234567890123LL},
{name="u64", id=7, kind='scalar', proto_type="uint64", optional=true, default_value=17ULL},
{name="by", id=8, kind='scalar', proto_type="bytes", optional=true, default_value="\x00\xff"},
{name="color", id=9, kind='enum', enum=M.Defaults_Color_descriptor, optional=true, default_value="GREEN"},
}
pb.finalize_message(M.Defaults_descriptor)
M.Defaults_fields = pb.field_names({
i = "i",
s = "s",
b = "b",
f = "f",
d = "d",
i64 = "i64",
u64 = "u64",
by = "by",
color = "color",
})
-- Message: proto2_basic.Cardinality
M.Cardinality_descriptor.fields = {
{name="r", id=1, kind='scalar', proto_type="int32", required=true},
{name="o", id=2, kind='scalar', proto_type="int32", optional=true},
{name="packed_default", id=3, kind='scalar', proto_type="int32", repeated=true, packed=false},
{name="explicitly_packed", id=4, kind='scalar', proto_type="int32", repeated=true, packed=true, options={packed = true}},
{name="explicitly_unpacked", id=5, kind='scalar', proto_type="int32", repeated=true, packed=false, options={packed = false}},
}
pb.finalize_message(M.Cardinality_descriptor)
M.Cardinality_fields = pb.field_names({
r = "r",
o = "o",
packed_default = "packed_default",
explicitly_packed = "explicitly_packed",
explicitly_unpacked = "explicitly_unpacked",
})
-- Message: proto2_basic.Nested
M.Nested_descriptor.fields = {
{name="inner", id=1, kind='message', message=M.Nested_Inner_descriptor, required=true},
{name="inner_opt", id=2, kind='message', message=M.Nested_Inner_descriptor, optional=true},
}
pb.finalize_message(M.Nested_descriptor)
M.Nested_fields = pb.field_names({
inner = "inner",
inner_opt = "inner_opt",
})
-- Message: proto2_basic.Nested.Inner
M.Nested_Inner_descriptor.fields = {
{name="x", id=1, kind='scalar', proto_type="int32", required=true},
}
pb.finalize_message(M.Nested_Inner_descriptor)
M.Nested_Inner_fields = pb.field_names({
x = "x",
})
-- Message: proto2_basic.WithGroup
M.WithGroup_descriptor.fields = {
{name="singlegroup", id=1, kind='group', message=M.WithGroup_SingleGroup_descriptor, optional=true},
{name="repgroup", id=4, kind='group', message=M.WithGroup_RepGroup_descriptor, repeated=true},
}
pb.finalize_message(M.WithGroup_descriptor)
M.WithGroup_fields = pb.field_names({
singlegroup = "singlegroup",
repgroup = "repgroup",
})
-- Message: proto2_basic.WithGroup.SingleGroup
M.WithGroup_SingleGroup_descriptor.fields = {
{name="a", id=2, kind='scalar', proto_type="int32", optional=true},
{name="s", id=3, kind='scalar', proto_type="string", optional=true},
}
pb.finalize_message(M.WithGroup_SingleGroup_descriptor)
M.WithGroup_SingleGroup_fields = pb.field_names({
a = "a",
s = "s",
})
-- Message: proto2_basic.WithGroup.RepGroup
M.WithGroup_RepGroup_descriptor.fields = {
{name="n", id=5, kind='scalar', proto_type="int32", optional=true},
}
pb.finalize_message(M.WithGroup_RepGroup_descriptor)
M.WithGroup_RepGroup_fields = pb.field_names({
n = "n",
})
-- Message: proto2_basic.BenchPayload
M.BenchPayload_descriptor.fields = {
{name="id", id=1, kind='scalar', proto_type="int32", required=true},
{name="name", id=2, kind='scalar', proto_type="string", optional=true, default_value="anonymous"},
{name="retries", id=3, kind='scalar', proto_type="int32", optional=true, default_value=3},
{name="lucky_numbers", id=4, kind='scalar', proto_type="int32", repeated=true, packed=true, options={packed = true}},
{name="tags", id=5, kind='scalar', proto_type="string", repeated=true},
{name="inner", id=6, kind='message', message=M.BenchPayload_Inner_descriptor, optional=true},
{name="stats", id=7, kind='group', message=M.BenchPayload_Stats_descriptor, optional=true},
}
pb.finalize_message(M.BenchPayload_descriptor)
M.BenchPayload_fields = pb.field_names({
id = "id",
name = "name",
retries = "retries",
lucky_numbers = "lucky_numbers",
tags = "tags",
inner = "inner",
stats = "stats",
})
-- Message: proto2_basic.BenchPayload.Stats
M.BenchPayload_Stats_descriptor.fields = {
{name="latency_ns", id=8, kind='scalar', proto_type="int32", optional=true},
{name="attempts", id=9, kind='scalar', proto_type="int32", optional=true},
}
pb.finalize_message(M.BenchPayload_Stats_descriptor)
M.BenchPayload_Stats_fields = pb.field_names({
latency_ns = "latency_ns",
attempts = "attempts",
})
-- Message: proto2_basic.BenchPayload.Inner
M.BenchPayload_Inner_descriptor.fields = {
{name="key", id=1, kind='scalar', proto_type="string", required=true},
{name="weight", id=2, kind='scalar', proto_type="int32", optional=true},
}
pb.finalize_message(M.BenchPayload_Inner_descriptor)
M.BenchPayload_Inner_fields = pb.field_names({
key = "key",
weight = "weight",
})
-- EmmyLua / lua-language-server type annotations.
-- These are comments — no runtime effect. They give editors
-- autocomplete and type-checking for the generated wrappers.
---@alias proto2_basic.Defaults.Color integer
---@class proto2_basic.Defaults
---@field i? integer
---@field s? string
---@field b? boolean
---@field f? number
---@field d? number
---@field i64? integer
---@field u64? integer
---@field by? string
---@field color? proto2_basic.Defaults.Color
---@class proto2_basic.Cardinality
---@field r integer
---@field o? integer
---@field packed_default integer[]
---@field explicitly_packed integer[]
---@field explicitly_unpacked integer[]
---@class proto2_basic.Nested
---@field inner proto2_basic.Nested.Inner
---@field inner_opt? proto2_basic.Nested.Inner
---@class proto2_basic.Nested.Inner
---@field x integer
--- Proto2 legacy groups. Wire format uses SGROUP (3) / EGROUP (4) tag
--- pairs instead of a length-prefixed message body.
---@class proto2_basic.WithGroup
---@field singlegroup? proto2_basic.WithGroup.SingleGroup
---@field repgroup proto2_basic.WithGroup.RepGroup[]
---@class proto2_basic.WithGroup.SingleGroup
---@field a? integer
---@field s? string
---@class proto2_basic.WithGroup.RepGroup
---@field n? integer
--- Bench fixture exercising the proto2-only shapes: required scalar,
--- optional repeated, custom default, a `group` field, and a nested
--- message. Used by bench/bench.lua against both modes.
---@class proto2_basic.BenchPayload
---@field id integer
---@field name? string
---@field retries? integer
---@field lucky_numbers integer[]
---@field tags string[]
---@field inner? proto2_basic.BenchPayload.Inner
---@field stats? proto2_basic.BenchPayload.Stats
---@class proto2_basic.BenchPayload.Stats
---@field latency_ns? integer
---@field attempts? integer
---@class proto2_basic.BenchPayload.Inner
---@field key string
---@field weight? integer
---@param t? proto2_basic.Defaults
---@return proto2_basic.Defaults
function M.Defaults_new(t) return t or {} end
---@param t proto2_basic.Defaults
---@return string
function M.Defaults_encode(t)
local encode_int32 = wire.encode_int32
local encode_varint = wire.encode_varint
local _d = M.Defaults_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.Defaults, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: i
v = t.i
if v ~= nil then
n = n + 1; out[n] = "\x08"
n = n + 1; out[n] = encode_int32(v)
end
-- field 2: s
v = t.s
if v ~= nil then
n = n + 1; out[n] = "\x12"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = v
end
-- field 3: b
v = t.b
if v ~= nil then
n = n + 1; out[n] = "\x18"
n = n + 1; out[n] = wire.encode_bool(v)
end
-- field 4: f
v = t.f
if v ~= nil then
n = n + 1; out[n] = "\x25"
n = n + 1; out[n] = wire.encode_float(v)
end
-- field 5: d
v = t.d
if v ~= nil then
n = n + 1; out[n] = "\x29"
n = n + 1; out[n] = wire.encode_double(v)
end
-- field 6: i64
v = t.i64
if v ~= nil then
n = n + 1; out[n] = "\x30"
n = n + 1; out[n] = wire.encode_int64(v)
end
-- field 7: u64
v = t.u64
if v ~= nil then
n = n + 1; out[n] = "\x38"
n = n + 1; out[n] = wire.encode_uint64(v)
end
-- field 8: by
v = t.by
if v ~= nil then
n = n + 1; out[n] = "\x42"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = v
end
-- field 9: color
v = t.color
if v ~= nil then
local nv = v
if type(v) == 'string' then
nv = M.Defaults_Color[v]
if nv == nil then error("unknown enum value '" .. v .. "' for proto2_basic.Defaults.Color", 0) end
end
n = n + 1; out[n] = "\x48"
n = n + 1; out[n] = encode_int32(nv)
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.Defaults
function M.Defaults_decode(buf)
local _d = M.Defaults_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.Defaults decode, got " .. type(buf), 0)
end
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)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
result.s = _s
pos = _epos
else
local val
val, pos = wire.decode_string(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 = wire.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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.Defaults_text(t, opts) return pb.text.encode(M.Defaults_descriptor, t, opts) end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_i(t) return t.i ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_i(t) t.i = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_s(t) return t.s ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_s(t) t.s = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_b(t) return t.b ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_b(t) t.b = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_f(t) return t.f ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_f(t) t.f = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_d(t) return t.d ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_d(t) t.d = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_i64(t) return t.i64 ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_i64(t) t.i64 = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_u64(t) return t.u64 ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_u64(t) t.u64 = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_by(t) return t.by ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_by(t) t.by = nil end
---@param t proto2_basic.Defaults
---@return boolean
function M.Defaults_has_color(t) return t.color ~= nil end
---@param t proto2_basic.Defaults
function M.Defaults_clear_color(t) t.color = nil end
---@param t? proto2_basic.Cardinality
---@return proto2_basic.Cardinality
function M.Cardinality_new(t) return t or {} end
---@param t proto2_basic.Cardinality
---@return string
function M.Cardinality_encode(t)
local encode_int32 = wire.encode_int32
local _d = M.Cardinality_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.Cardinality, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: r
v = t.r
if v == nil then
error("required field missing on encode: proto2_basic.Cardinality.r", 0)
end
n = n + 1; out[n] = "\x08"
n = n + 1; out[n] = encode_int32(v)
-- field 2: o
v = t.o
if v ~= nil then
n = n + 1; out[n] = "\x10"
n = n + 1; out[n] = encode_int32(v)
end
-- field 3: packed_default
v = t.packed_default
if v ~= nil and #v > 0 then
local _tag = "\x18"
for _i = 1, #v do
n = n + 1; out[n] = _tag
n = n + 1; out[n] = encode_int32(v[_i])
end
end
-- field 4: explicitly_packed
v = t.explicitly_packed
if v ~= nil and #v > 0 then
local parts, m = {}, 0
for _i = 1, #v do
m = m + 1; parts[m] = encode_int32(v[_i])
end
local _b = table.concat(parts)
n = n + 1; out[n] = "\x22"
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = wire.encode_varint(_len)
end
n = n + 1; out[n] = _b
end
-- field 5: explicitly_unpacked
v = t.explicitly_unpacked
if v ~= nil and #v > 0 then
local _tag = "\x28"
for _i = 1, #v do
n = n + 1; out[n] = _tag
n = n + 1; out[n] = encode_int32(v[_i])
end
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.Cardinality
function M.Cardinality_decode(buf)
local decode_int32 = wire.decode_int32
local decode_len = wire.decode_len
local _d = M.Cardinality_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.Cardinality decode, got " .. type(buf), 0)
end
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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.Cardinality_text(t, opts) return pb.text.encode(M.Cardinality_descriptor, t, opts) end
---@param t proto2_basic.Cardinality
---@return boolean
function M.Cardinality_has_o(t) return t.o ~= nil end
---@param t proto2_basic.Cardinality
function M.Cardinality_clear_o(t) t.o = nil end
---@param t? proto2_basic.Nested
---@return proto2_basic.Nested
function M.Nested_new(t) return t or {} end
---@param t proto2_basic.Nested
---@return string
function M.Nested_encode(t)
local encode_varint = wire.encode_varint
local _d = M.Nested_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.Nested, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: inner
v = t.inner
if v == nil then
error("required field missing on encode: proto2_basic.Nested.inner", 0)
end
local _b = M.Nested_Inner_encode(v)
n = n + 1; out[n] = "\x0a"
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _b
-- field 2: inner_opt
v = t.inner_opt
if v ~= nil or type(v) == 'cdata' then
local _b = M.Nested_Inner_encode(v)
n = n + 1; out[n] = "\x12"
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _b
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.Nested
function M.Nested_decode(buf)
local decode_len = wire.decode_len
local _d = M.Nested_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.Nested decode, got " .. type(buf), 0)
end
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(payload)
else
pb.codec.merge_message(M.Nested_Inner_descriptor, prev, M.Nested_Inner_decode(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(payload)
else
pb.codec.merge_message(M.Nested_Inner_descriptor, prev, M.Nested_Inner_decode(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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.Nested_text(t, opts) return pb.text.encode(M.Nested_descriptor, t, opts) end
---@param t proto2_basic.Nested
---@return boolean
function M.Nested_has_inner_opt(t) return t.inner_opt ~= nil end
---@param t proto2_basic.Nested
function M.Nested_clear_inner_opt(t) t.inner_opt = nil end
---@param t? proto2_basic.Nested.Inner
---@return proto2_basic.Nested.Inner
function M.Nested_Inner_new(t) return t or {} end
---@param t proto2_basic.Nested.Inner
---@return string
function M.Nested_Inner_encode(t)
local _d = M.Nested_Inner_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.Nested.Inner, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: x
v = t.x
if v == nil then
error("required field missing on encode: proto2_basic.Nested.Inner.x", 0)
end
n = n + 1; out[n] = "\x08"
n = n + 1; out[n] = wire.encode_int32(v)
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.Nested.Inner
function M.Nested_Inner_decode(buf)
local _d = M.Nested_Inner_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.Nested.Inner decode, got " .. type(buf), 0)
end
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 pb.MessageView
function M.Nested_Inner_decode_lazy(b) return pb.decode_lazy(M.Nested_Inner_descriptor, b) end
---@param t proto2_basic.Nested.Inner
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.Nested_Inner_text(t, opts) return pb.text.encode(M.Nested_Inner_descriptor, t, opts) end
---@param t? proto2_basic.WithGroup
---@return proto2_basic.WithGroup
function M.WithGroup_new(t) return t or {} end
---@param t proto2_basic.WithGroup
---@return string
function M.WithGroup_encode(t)
local _d = M.WithGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.WithGroup, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: singlegroup
v = t.singlegroup
if v ~= nil or type(v) == 'cdata' then
n = n + 1; out[n] = "\x0b"
n = n + 1; out[n] = M.WithGroup_SingleGroup_encode(v)
n = n + 1; out[n] = "\x0c"
end
-- field 4: repgroup
v = t.repgroup
if v ~= nil and #v > 0 then
local _stag = "\x23"
local _etag = "\x24"
for _i = 1, #v do
n = n + 1; out[n] = _stag
n = n + 1; out[n] = M.WithGroup_RepGroup_encode(v[_i])
n = n + 1; out[n] = _etag
end
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.WithGroup
function M.WithGroup_decode(buf)
local _d = M.WithGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.WithGroup decode, got " .. type(buf), 0)
end
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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.WithGroup_text(t, opts) return pb.text.encode(M.WithGroup_descriptor, t, opts) end
---@param t proto2_basic.WithGroup
---@return boolean
function M.WithGroup_has_singlegroup(t) return t.singlegroup ~= nil end
---@param t proto2_basic.WithGroup
function M.WithGroup_clear_singlegroup(t) t.singlegroup = nil end
---@param t? proto2_basic.WithGroup.SingleGroup
---@return proto2_basic.WithGroup.SingleGroup
function M.WithGroup_SingleGroup_new(t) return t or {} end
---@param t proto2_basic.WithGroup.SingleGroup
---@return string
function M.WithGroup_SingleGroup_encode(t)
local _d = M.WithGroup_SingleGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.WithGroup.SingleGroup, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 2: a
v = t.a
if v ~= nil then
n = n + 1; out[n] = "\x10"
n = n + 1; out[n] = wire.encode_int32(v)
end
-- field 3: s
v = t.s
if v ~= nil then
n = n + 1; out[n] = "\x1a"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = wire.encode_varint(_len)
end
n = n + 1; out[n] = v
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.WithGroup.SingleGroup
function M.WithGroup_SingleGroup_decode(buf)
local _d = M.WithGroup_SingleGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.WithGroup.SingleGroup decode, got " .. type(buf), 0)
end
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)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
result.s = _s
pos = _epos
else
local val
val, pos = wire.decode_string(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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.WithGroup_SingleGroup_text(t, opts) return pb.text.encode(M.WithGroup_SingleGroup_descriptor, t, opts) end
---@param t proto2_basic.WithGroup.SingleGroup
---@return boolean
function M.WithGroup_SingleGroup_has_a(t) return t.a ~= nil end
---@param t proto2_basic.WithGroup.SingleGroup
function M.WithGroup_SingleGroup_clear_a(t) t.a = nil end
---@param t proto2_basic.WithGroup.SingleGroup
---@return boolean
function M.WithGroup_SingleGroup_has_s(t) return t.s ~= nil end
---@param t proto2_basic.WithGroup.SingleGroup
function M.WithGroup_SingleGroup_clear_s(t) t.s = nil end
---@param t? proto2_basic.WithGroup.RepGroup
---@return proto2_basic.WithGroup.RepGroup
function M.WithGroup_RepGroup_new(t) return t or {} end
---@param t proto2_basic.WithGroup.RepGroup
---@return string
function M.WithGroup_RepGroup_encode(t)
local _d = M.WithGroup_RepGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.WithGroup.RepGroup, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 5: n
v = t.n
if v ~= nil then
n = n + 1; out[n] = "\x28"
n = n + 1; out[n] = wire.encode_int32(v)
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.WithGroup.RepGroup
function M.WithGroup_RepGroup_decode(buf)
local _d = M.WithGroup_RepGroup_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.WithGroup.RepGroup decode, got " .. type(buf), 0)
end
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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.WithGroup_RepGroup_text(t, opts) return pb.text.encode(M.WithGroup_RepGroup_descriptor, t, opts) end
---@param t proto2_basic.WithGroup.RepGroup
---@return boolean
function M.WithGroup_RepGroup_has_n(t) return t.n ~= nil end
---@param t proto2_basic.WithGroup.RepGroup
function M.WithGroup_RepGroup_clear_n(t) t.n = nil end
---@param t? proto2_basic.BenchPayload
---@return proto2_basic.BenchPayload
function M.BenchPayload_new(t) return t or {} end
---@param t proto2_basic.BenchPayload
---@return string
function M.BenchPayload_encode(t)
local encode_int32 = wire.encode_int32
local encode_varint = wire.encode_varint
local _d = M.BenchPayload_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.BenchPayload, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: id
v = t.id
if v == nil then
error("required field missing on encode: proto2_basic.BenchPayload.id", 0)
end
n = n + 1; out[n] = "\x08"
n = n + 1; out[n] = encode_int32(v)
-- field 2: name
v = t.name
if v ~= nil then
n = n + 1; out[n] = "\x12"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = v
end
-- field 3: retries
v = t.retries
if v ~= nil then
n = n + 1; out[n] = "\x18"
n = n + 1; out[n] = encode_int32(v)
end
-- field 4: lucky_numbers
v = t.lucky_numbers
if v ~= nil and #v > 0 then
local parts, m = {}, 0
for _i = 1, #v do
m = m + 1; parts[m] = encode_int32(v[_i])
end
local _b = table.concat(parts)
n = n + 1; out[n] = "\x22"
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _b
end
-- field 5: tags
v = t.tags
if v ~= nil and #v > 0 then
local _tag = "\x2a"
for _i = 1, #v do
local _b = v[_i]
n = n + 1; out[n] = _tag
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _b
end
end
-- field 6: inner
v = t.inner
if v ~= nil or type(v) == 'cdata' then
local _b = M.BenchPayload_Inner_encode(v)
n = n + 1; out[n] = "\x32"
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _b
end
-- field 7: stats
v = t.stats
if v ~= nil or type(v) == 'cdata' then
n = n + 1; out[n] = "\x3b"
n = n + 1; out[n] = M.BenchPayload_Stats_encode(v)
n = n + 1; out[n] = "\x3c"
end
local _exts = t._extensions
if _exts ~= nil then
local _ev
-- extension 100: proto2_basic.ext_count
_ev = _exts["proto2_basic.ext_count"]
if _ev ~= nil then
n = n + 1; out[n] = "\xa0\x06"
n = n + 1; out[n] = encode_int32(_ev)
end
-- extension 101: proto2_basic.ext_label
_ev = _exts["proto2_basic.ext_label"]
if _ev ~= nil then
n = n + 1; out[n] = "\xaa\x06"
local _len = #_ev
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = encode_varint(_len)
end
n = n + 1; out[n] = _ev
end
end
local _elist = M.BenchPayload_descriptor.extensions_list
if _elist ~= nil and #_elist > 2 then
local _exts2 = t._extensions
if _exts2 ~= nil then
for _i = 3, #_elist do
local _ext = _elist[_i]
local _ev = _exts2[_ext.full_name]
if _ev ~= nil then
pb.codec.encode_field(_ext, _ev, out, true)
end
end
n = #out
end
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.BenchPayload
function M.BenchPayload_decode(buf)
local decode_int32 = wire.decode_int32
local decode_len = wire.decode_len
local decode_string = wire.decode_string
local _d = M.BenchPayload_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.BenchPayload decode, got " .. type(buf), 0)
end
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)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
result.name = _s
pos = _epos
else
local val
val, pos = decode_string(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)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
_n_tags = _n_tags + 1; list[_n_tags] = _s
pos = _epos
else
local val
val, pos = decode_string(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(payload)
else
pb.codec.merge_message(M.BenchPayload_Inner_descriptor, prev, M.BenchPayload_Inner_decode(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_string(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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.BenchPayload_text(t, opts) return pb.text.encode(M.BenchPayload_descriptor, t, opts) end
---@param t proto2_basic.BenchPayload
---@return boolean
function M.BenchPayload_has_name(t) return t.name ~= nil end
---@param t proto2_basic.BenchPayload
function M.BenchPayload_clear_name(t) t.name = nil end
---@param t proto2_basic.BenchPayload
---@return boolean
function M.BenchPayload_has_retries(t) return t.retries ~= nil end
---@param t proto2_basic.BenchPayload
function M.BenchPayload_clear_retries(t) t.retries = nil end
---@param t proto2_basic.BenchPayload
---@return boolean
function M.BenchPayload_has_inner(t) return t.inner ~= nil end
---@param t proto2_basic.BenchPayload
function M.BenchPayload_clear_inner(t) t.inner = nil end
---@param t proto2_basic.BenchPayload
---@return boolean
function M.BenchPayload_has_stats(t) return t.stats ~= nil end
---@param t proto2_basic.BenchPayload
function M.BenchPayload_clear_stats(t) t.stats = nil end
---@param t? proto2_basic.BenchPayload.Stats
---@return proto2_basic.BenchPayload.Stats
function M.BenchPayload_Stats_new(t) return t or {} end
---@param t proto2_basic.BenchPayload.Stats
---@return string
function M.BenchPayload_Stats_encode(t)
local encode_int32 = wire.encode_int32
local _d = M.BenchPayload_Stats_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.BenchPayload.Stats, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 8: latency_ns
v = t.latency_ns
if v ~= nil then
n = n + 1; out[n] = "\x40"
n = n + 1; out[n] = encode_int32(v)
end
-- field 9: attempts
v = t.attempts
if v ~= nil then
n = n + 1; out[n] = "\x48"
n = n + 1; out[n] = encode_int32(v)
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.BenchPayload.Stats
function M.BenchPayload_Stats_decode(buf)
local decode_int32 = wire.decode_int32
local _d = M.BenchPayload_Stats_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.BenchPayload.Stats decode, got " .. type(buf), 0)
end
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
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.BenchPayload_Stats_text(t, opts) return pb.text.encode(M.BenchPayload_Stats_descriptor, t, opts) end
---@param t proto2_basic.BenchPayload.Stats
---@return boolean
function M.BenchPayload_Stats_has_latency_ns(t) return t.latency_ns ~= nil end
---@param t proto2_basic.BenchPayload.Stats
function M.BenchPayload_Stats_clear_latency_ns(t) t.latency_ns = nil end
---@param t proto2_basic.BenchPayload.Stats
---@return boolean
function M.BenchPayload_Stats_has_attempts(t) return t.attempts ~= nil end
---@param t proto2_basic.BenchPayload.Stats
function M.BenchPayload_Stats_clear_attempts(t) t.attempts = nil end
---@param t? proto2_basic.BenchPayload.Inner
---@return proto2_basic.BenchPayload.Inner
function M.BenchPayload_Inner_new(t) return t or {} end
---@param t proto2_basic.BenchPayload.Inner
---@return string
function M.BenchPayload_Inner_encode(t)
local _d = M.BenchPayload_Inner_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.encode(_p, t)
end
if type(t) ~= 'table' then
error("expected table for proto2_basic.BenchPayload.Inner, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: key
v = t.key
if v == nil then
error("required field missing on encode: proto2_basic.BenchPayload.Inner.key", 0)
end
n = n + 1; out[n] = "\x0a"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = CHARS[_len]
else
n = n + 1; out[n] = wire.encode_varint(_len)
end
n = n + 1; out[n] = v
-- field 2: weight
v = t.weight
if v ~= nil then
n = n + 1; out[n] = "\x10"
n = n + 1; out[n] = wire.encode_int32(v)
end
local _uf = t._unknown_fields
if _uf ~= nil and _uf ~= '' then n = n + 1; out[n] = _uf end
return table.concat(out)
end
---@param b string
---@return proto2_basic.BenchPayload.Inner
function M.BenchPayload_Inner_decode(buf)
local _d = M.BenchPayload_Inner_descriptor
if pb.c_runtime ~= nil then
local _p = _d.c_plan or pb.c_runtime.compile_plan(_d)
return pb.c_runtime.decode(_p, buf)
end
if type(buf) ~= 'string' then
error("expected string for proto2_basic.BenchPayload.Inner decode, got " .. type(buf), 0)
end
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)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
result.key = _s
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 pb.MessageView
function M.BenchPayload_Inner_decode_lazy(b) return pb.decode_lazy(M.BenchPayload_Inner_descriptor, b) end
---@param t proto2_basic.BenchPayload.Inner
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.BenchPayload_Inner_text(t, opts) return pb.text.encode(M.BenchPayload_Inner_descriptor, t, opts) end
---@param t proto2_basic.BenchPayload.Inner
---@return boolean
function M.BenchPayload_Inner_has_weight(t) return t.weight ~= nil end
---@param t proto2_basic.BenchPayload.Inner
function M.BenchPayload_Inner_clear_weight(t) t.weight = nil end
-- Extension: proto2_basic.ext_count extends proto2_basic.BenchPayload (tag 100)
pb.register_extension(M.BenchPayload_descriptor, {name="ext_count", full_name="proto2_basic.ext_count", id=100, kind='scalar', proto_type="int32", optional=true})
-- Extension: proto2_basic.ext_label extends proto2_basic.BenchPayload (tag 101)
pb.register_extension(M.BenchPayload_descriptor, {name="ext_label", full_name="proto2_basic.ext_label", id=101, kind='scalar', proto_type="string", optional=true})
return M