在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jinq0123/LuaPbIntf开源软件地址(OpenSource Url):https://github.com/jinq0123/LuaPbIntf开源编程语言(OpenSource Language):C++ 64.5%开源软件介绍(OpenSource Introduction):LuaPbIntfLua Protobuf interface. Binding Protobuf to Lua with lua-intf, supporting lua53 and proto3. LuaPbIntf is inspired by luapb, but has been rewritten to take advantage of lua-intf, which makes the binding easier to use and easier to understand. LuaPbIntf will dynamic load Protocol Buffer message definition files .proto without code generation. LuaPbIntf use lua table to present Message,
Differ from luapb
BuildBuild with conan
Without conan (depricated)Init third_party dir first, see third_party/README.md. Then use premake5 to generate VS2015 sln or Makefile to build. See premake/premake5.bat On Windows, it is recommended by google that you use static protobuf only. On Linux, you may need to recompile libprotobuf.a with -fPIC, or link libprotobuf.so. Link error
Please see issue #2. By default, it expects the Lua library to build under C++. If you really want to use Lua library compiled under C, you can define LUAINTF_LINK_LUA_COMPILED_IN_CXX to 0. Run testSee test/README.md ExampleEncode and Decodelocal pb = require("luapbintf")
pb.import_proto_file("test.proto")
local msg = { uid = 12345 }
local sz = pb.encode("test.TestMsg", msg)
local msg2 = pb.decode("test.TestMsg", sz)
assert(msg2.uid == 12345) Rpc assert(pb.get_rpc_input_name("test.Test", "Foo") == "test.TestMsg")
assert(pb.get_rpc_output_name("test.Test", "Foo") == "test.CommonMsg") Map fieldlocal msgs = {}
msgs["k1"] = {}
msgs["k2"] = {}
pb.encode("test.TestMsg", { msgs = msgs }) Oneof field local msg = { msg2 = {} }
local s = pb.encode("test.TestMsg", msg)
local result = pb.decode("test.TestMsg", s)
assert(result.name == "")
assert(result.name2 == nil)
assert(result.msg2) Type ConvertionNumber will be converted to string if necessary. local msg = { name = 12345 }
local s = pb.encode("test.TestMsg", msg)
assert(pb.decode("test.TestMsg", s).name == "12345") Integer will be converted from one type to another. Such as from int64 4294967296 to int32 0: local msg = { n32 = 4294967296 + 123 }
assert(msg.n32 == 4294967296 + 123)
local s = pb.encode("test.TestMsg", msg)
local msg2 = pb.decode("test.TestMsg", s)
assert(msg2.n32 == 123) String can be converted to integer or float: local msg = { d = "12345e-67" }
local s = pb.encode("test.TestMsg", msg)
assert(pb.decode("test.TestMsg", s).d == 12345e-67) Can not convert float to integer.
Enum is integer, but input string enum will be converted to integer. local msg = { cmd = "CMD_TYPE_CHECK" }
local s = pb.encode("test.TestMsg", msg)
assert(pb.decode("test.TestMsg", s).cmd == 2) Repeated field is a lua array table and it is read from index 1 to len, ignoring others. local msg = { names = {"n1", "n2", "n3", [0] = "n1", [100] = "n100"} }
local s = pb.encode("test.TestMsg", msg)
local msg2 = pb.decode("test.TestMsg", s)
assert(#msg2.names == 3) Proto2 ExtensionProto2 extension is not supported, which is replaced by Any type in proto3. ReferenceSee doc/reference.md. Known Bugs
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论