Copyright (c) 2013-2018 brinkqiang ([email protected])
Linux | Mac | Windows |
---|---|---|
luapb
win
build.bat
cd bin\relwithdebinfo
lua ..\script\msg.lua
linux
bash build.sh
cd bin/relwithdebinfo
./lua ../script/msg.lua
pb_import enter
pb_import leave
pbtest ��13615632545��[email protected] �(�2�first2�second2�three
local pb = require("luapb")
local luajson = require("luajson")
pb.import("net.proto")
local name = pb.id2name(8345))
local id = pb.name2id("net.tb_Person"))
local msg = pb.pb_new("net.tb_Person")
msg.number = "13615632545"
msg.email = "[email protected]"
msg.age = 28
msg.ptype = 2
msg.desc:add("first")
msg.desc:add("second")
msg.desc:add("three")
local msg_debugstring = pb.tostring(msg)
local buffer = pb.serializeToString(msg)
local msg2 = pb.new("net.tb_Person")
pb.parseFromString(msg2, buffer)
local tb_msg = {
number = "13615632545",
email = "[email protected]",
age = 28,
ptype = "WORK",
desc = {"first", "second", "three"},
jobs = {
{
jobtype = 8345,
jobdesc = "coder"
},
{
jobtype = 9527,
jobdesc = "coder2"
}
}
}
local buffer2 = pb.encode("net.tb_Person", tb_msg)
local tb_msg2 = pb.decode("net.tb_Person", buffer2)
local str_json = pb.table2json("net.tb_Person", tb_msg2)
local str_xml = pb.table2xml("net.tb_Person", tb_msg2)
local str_yaml = pb.table2yaml("net.tb_Person", tb_msg2)
local tb_json = pb.json2table("net.tb_Person", str_json)
local tb_xml = pb.xml2table("net.tb_Person", str_xml)
local tb_yaml = pb.yaml2table("net.tb_Person", str_yaml)