-- Code generated by protoc-gen-tarantool. DO NOT EDIT.
-- source: quickstart.proto
-- syntax: proto3
-- package: quickstart
local pb = require("pb")
local wire = pb.wire
local M = {}
M.options = {go_package = "tarantoolpb_synthetic/quickstart"}
-- Enum: quickstart.Role
M.Role_descriptor = pb.enum("quickstart.Role", {
ROLE_UNSPECIFIED = 0,
USER = 1,
ADMIN = 2,
})
M.Role = M.Role_descriptor.by_name
-- Pre-declare message descriptors so cross-references resolve.
M.User_descriptor = {name = "quickstart.User"}
-- Message: quickstart.User
M.User_descriptor.fields = {
{name="id", id=1, kind='scalar', proto_type="int32"},
{name="name", id=2, kind='scalar', proto_type="string"},
{name="role", id=3, kind='enum', enum=M.Role_descriptor},
{name="emails", id=4, kind='scalar', proto_type="string", repeated=true},
}
pb.finalize_message(M.User_descriptor)
M.User_fields = pb.field_names({
id = "id",
name = "name",
role = "role",
emails = "emails",
})
-- EmmyLua / lua-language-server type annotations.
-- These are comments — no runtime effect. They give editors
-- autocomplete and type-checking for the generated wrappers.
---@alias quickstart.Role integer
---@class quickstart.User
---@field id integer
---@field name string
---@field role quickstart.Role
---@field emails string[]
---@param t? quickstart.User
---@return quickstart.User
function M.User_new(t) return t or {} end
---@param t quickstart.User
---@return string
function M.User_encode(t)
if type(t) ~= 'table' then
error("expected table for quickstart.User, got " .. type(t), 0)
end
local out, n = {}, 0
local v
-- field 1: id
v = t.id
if v ~= nil and v ~= 0 then
n = n + 1; out[n] = "\x08"
n = n + 1; out[n] = wire.encode_int32(v)
end
-- field 2: name
v = t.name
if v ~= nil and v ~= '' then
n = n + 1; out[n] = "\x12"
n = n + 1; out[n] = wire.encode_varint(#v)
n = n + 1; out[n] = v
end
-- field 3: role
v = t.role
if v ~= nil then
local nv = v
if type(v) == 'string' then
nv = M.Role[v]
if nv == nil then error("unknown enum value '" .. v .. "' for quickstart.Role", 0) end
end
if nv ~= 0 then
n = n + 1; out[n] = "\x18"
n = n + 1; out[n] = wire.encode_int32(nv)
end
end
-- field 4: emails
v = t.emails
if v ~= nil and #v > 0 then
local _tag = "\x22"
for _i = 1, #v do
local _b = v[_i]
n = n + 1; out[n] = _tag
n = n + 1; out[n] = wire.encode_varint(#_b)
n = n + 1; out[n] = _b
end
end
local _exts = t._extensions
if _exts ~= nil then
local _elist = M.User_descriptor.extensions_list
if _elist ~= nil then
for _i = 1, #_elist do
local _ext = _elist[_i]
local _ev = _exts[_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 quickstart.User
function M.User_decode(buf)
if type(buf) ~= 'string' then
error("expected string for quickstart.User decode, got " .. type(buf), 0)
end
local result = {}
local pos, len = 1, #buf
local _uf
while pos <= len do
local _tag_start = pos
local id, wt
id, wt, pos = wire.decode_tag(buf, pos)
if id == 1 then
local val
val, pos = wire.decode_int32(buf, pos)
result.id = val
elseif id == 2 then
local val
val, pos = wire.decode_string(buf, pos)
result.name = val
elseif id == 3 then
local u
u, pos = wire.decode_varint(buf, pos)
result.role = wire.varint_to_int32(u)
elseif id == 4 then
local list = result.emails
if list == nil then list = {}; result.emails = list end
local val
val, pos = wire.decode_string(buf, pos)
list[#list + 1] = val
else
local _ebid = M.User_descriptor.extensions_by_id
local _ext = _ebid and _ebid[id] or nil
if _ext ~= nil then
pos = pb.codec.decode_extension(_ext, buf, pos, wt, result)
else
pos = wire.skip_field(buf, pos, wt, id)
if _uf == nil then _uf = {} end
_uf[#_uf + 1] = buf:sub(_tag_start, pos - 1)
end
end
end
if _uf ~= nil then result._unknown_fields = table.concat(_uf) end
return result
end
---@param b string
---@return pb.MessageView
function M.User_decode_lazy(b) return pb.decode_lazy(M.User_descriptor, b) end
---@param t quickstart.User
---@param opts? {single_line: boolean?, indent: string?}
---@return string
function M.User_text(t, opts) return pb.text.encode(M.User_descriptor, t, opts) end
return M