-- 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 string_byte = string.byte
local utf8_len = require('utf8').len
local band = bit.band
local rshift = bit.rshift
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)
local _d = M.User_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 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"
local _len = #v
if _len < 128 then
n = n + 1; out[n] = string.char(_len)
else
n = n + 1; out[n] = wire.encode_varint(_len)
end
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
local _len = #_b
if _len < 128 then
n = n + 1; out[n] = string.char(_len)
else
n = n + 1; out[n] = wire.encode_varint(_len)
end
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)
local _d = M.User_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 quickstart.User decode, got " .. type(buf), 0)
end
local result = {}
local pos, len = 1, #buf
local _uf
local _n_emails = 0
while pos <= len do
local _tag_start = pos
local id, wt
local _b = string_byte(buf, pos)
if _b ~= nil and _b < 0x80 then
wt = band(_b, 7)
if wt >= 6 then error("illegal wire type " .. wt, 0) end
id = rshift(_b, 3)
if id == 0 then error("illegal field number 0", 0) end
pos = pos + 1
else
id, wt, pos = wire.decode_tag(buf, pos)
end
if id == 1 then
local val
val, pos = wire.decode_int32(buf, pos)
result.id = val
elseif id == 2 then
local _lb = string_byte(buf, pos)
if _lb ~= nil and _lb < 0x80 then
local _np = pos + 1
local _epos = _np + _lb
if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end
local _s = buf:sub(_np, _epos - 1)
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 = wire.decode_string(buf, pos)
result.name = val
end
elseif id == 3 then
local u
u, pos = wire.decode_varint(buf, pos)
result.role = wire.varint_to_int32(u)
elseif id == 4 then
local list = result.emails
if list == nil then list = {}; result.emails = list end
local _lb = string_byte(buf, pos)
if _lb ~= nil and _lb < 0x80 then
local _np = pos + 1
local _epos = _np + _lb
if _epos - 1 > len then error("truncated LEN at offset " .. pos, 0) end
local _s = buf:sub(_np, _epos - 1)
if utf8_len(_s) == nil then error("invalid UTF-8 in string field at offset " .. pos, 0) end
_n_emails = _n_emails + 1; list[_n_emails] = _s
pos = _epos
else
local val
val, pos = wire.decode_string(buf, pos)
_n_emails = _n_emails + 1; list[_n_emails] = val
end
else
local _ebid = M.User_descriptor.extensions_by_id
local _ext = _ebid and _ebid[id] or nil
if _ext ~= nil then
pos = pb.codec.decode_extension(_ext, buf, pos, wt, result)
else
pos = wire.skip_field(buf, pos, wt, id)
if _uf == nil then _uf = {} end
_uf[#_uf + 1] = buf:sub(_tag_start, pos - 1)
end
end
end
if _uf ~= nil then result._unknown_fields = table.concat(_uf) end
return result
end
---@param b string
---@return pb.MessageView
function M.User_decode_lazy(b) return pb.decode_lazy(M.User_descriptor, b) end
---@param t quickstart.User
---@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