Skip to content

Lua built-in module implementation, realizes cmake modularization, realizes automatic reflection in lua layer by directly calling protobuf reflection function in module. Supports pb2, pb3, realizes pb, luatable and other data structure xml, json, yaml conversion.

License

Notifications You must be signed in to change notification settings

brinkqiang/luapb

Repository files navigation

luapb

Copyright (c) 2013-2018 brinkqiang ([email protected])

luapb License blog Open Source Love GitHub stars GitHub forks

Build status

Linux Mac Windows
lin-badge mac-badge win-badge

Intro

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)

Contacts

Thanks

About

Lua built-in module implementation, realizes cmake modularization, realizes automatic reflection in lua layer by directly calling protobuf reflection function in module. Supports pb2, pb3, realizes pb, luatable and other data structure xml, json, yaml conversion.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages