All Projects → jinq0123 → Luapbintf

jinq0123 / Luapbintf

Licence: mit
Binding Protobuf 3 to Lua 5.3

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Luapbintf

sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-83.61%)
Mutual labels:  buffer, protocol
Ocaml Protoc
A Protobuf Compiler for OCaml
Stars: ✭ 129 (+5.74%)
Mutual labels:  protobuf, protocol
Play Store Api
Google Play Store protobuf API wrapper in java
Stars: ✭ 249 (+104.1%)
Mutual labels:  google, protobuf
node-lei-proto
简单的Buffer编码/解析模块
Stars: ✭ 14 (-88.52%)
Mutual labels:  protobuf, buffer
Searchwithmybrowser
Open Cortana searches with your default browser.
Stars: ✭ 285 (+133.61%)
Mutual labels:  google, protocol
Protobuf Convert
Macros for convenient serialization of Rust data structures into/from Protocol Buffers 3
Stars: ✭ 22 (-81.97%)
Mutual labels:  protobuf, protocol
Parrot
The next generation messenger.
Stars: ✭ 305 (+150%)
Mutual labels:  google, protobuf
Enif protobuf
A Google Protobuf implementation with enif (Erlang nif).
Stars: ✭ 33 (-72.95%)
Mutual labels:  google, protobuf
Quinn
Async-friendly QUIC implementation in Rust
Stars: ✭ 1,859 (+1423.77%)
Mutual labels:  protocol
Macassistant
Google Assistant for macOS!
Stars: ✭ 1,564 (+1181.97%)
Mutual labels:  google
Javaosc
OSC content format/"protocol" library for JVM languages
Stars: ✭ 116 (-4.92%)
Mutual labels:  protocol
Pex Context
Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
Stars: ✭ 117 (-4.1%)
Mutual labels:  buffer
Flutter Products Tutorial
A Flutter e-commerce starter kit built using ScopedModel
Stars: ✭ 120 (-1.64%)
Mutual labels:  google
Reactiveplaybilling
An RxJava wrapper for the Google Play Billing Library
Stars: ✭ 117 (-4.1%)
Mutual labels:  buffer
Vim Ctrlspace
Vim Space Controller
Stars: ✭ 1,621 (+1228.69%)
Mutual labels:  buffer
Corrode
A batteries-included library for reading binary data.
Stars: ✭ 116 (-4.92%)
Mutual labels:  buffer
Googleimageshell
Google image search extension for Windows Explorer.
Stars: ✭ 116 (-4.92%)
Mutual labels:  google
Type class
(Semi-)principled type classes for Elixir
Stars: ✭ 121 (-0.82%)
Mutual labels:  protocol
Blade Build
Blade is a powerful build system from Tencent, supports many mainstream programming languages, such as C/C++, java, scala, python, protobuf...
Stars: ✭ 1,722 (+1311.48%)
Mutual labels:  protobuf
Esp V2
A service proxy that provides API management capabilities using Google Service Infrastructure.
Stars: ✭ 120 (-1.64%)
Mutual labels:  google

LuaPbIntf

Lua 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, encode() to encode lua message table to string, and decode() to decode string to lua message table.

Differ from luapb

  • Support proto3
  • Support service
  • Able to set the proto path
  • luapb skips some types such as: TYPE_SFIXED32. See issue.

Build

Build with conan

  1. Install conan.
  2. Add conan repositories
    • conan remote add remote_bintray_bincrafters https://api.bintray.com/conan/bincrafters/public-conan
    • conan remote add remote_bintray_jinq0123 https://api.bintray.com/conan/jinq0123/test
  3. conan create . user/channel --build missing
    • The result luapbintf.dll/luapbintf.so is in ~/.conan/data/luapbintf/0.1/user/channel/package/...
    • Add build settings like: conan create user/channel --build missing -s arch=x86

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

error LNK2019: unresolved external symbol "void __cdecl lua_settop(struct lua_State *,int)" ([email protected]@[email protected]@[email protected])

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 test

See test/README.md

Example

Encode and Decode

local 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 field

local 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 Convertion

Number 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.

> msg = { n32 = 1.1 }
> pb.encode("test.TestMsg", msg)
stdin:1: bad argument #-1 to 'encode' (number has no integer representation)

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 Extension

Proto2 extension is not supported, which is replaced by Any type in proto3.

Reference

See doc/reference.md.

Known Bugs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].