All Projects → jinjiazhang → protolua

jinjiazhang / protolua

Licence: other
C++ implement encode, decode Protocol Buffers for Lua without code generation

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
CMake
9771 projects
lua
6591 projects

Projects that are alternatives of or similar to protolua

protostuff-compiler
Protobuf parser, java code and documentation generator
Stars: ✭ 42 (-64.1%)
Mutual labels:  protobuf
play-grpc
Play + Akka gRPC
Stars: ✭ 31 (-73.5%)
Mutual labels:  protobuf
Protobuf-Dreamer
A tiled DeepDream project for creating any size of image, on both CPU and GPU
Stars: ✭ 39 (-66.67%)
Mutual labels:  protobuf
boilr-grpc
A boilr template for a gRPC service, with a REST Gateway
Stars: ✭ 15 (-87.18%)
Mutual labels:  protobuf
homebrew-extensions
🍻 Homebrew tap for PHP extensions
Stars: ✭ 264 (+125.64%)
Mutual labels:  protobuf
go course
個人多年來學習與實作上的心得筆記
Stars: ✭ 25 (-78.63%)
Mutual labels:  protobuf
karate-grpc
gRPC Testing Made Simple by Karate
Stars: ✭ 43 (-63.25%)
Mutual labels:  protobuf
server-client-template-go
No description or website provided.
Stars: ✭ 14 (-88.03%)
Mutual labels:  protobuf
redis-protobuf
Redis module for reading and writing Protobuf messages
Stars: ✭ 153 (+30.77%)
Mutual labels:  protobuf
yadoms
Yadoms is open source, simple, powerfull, flexible and multiplatforms domotic solution.
Stars: ✭ 56 (-52.14%)
Mutual labels:  protobuf
cocolian-rpc
使用Apache Thrift作为容器,Google Protobuf作为协议的一个RPC框架。
Stars: ✭ 19 (-83.76%)
Mutual labels:  protobuf
pbts-grpc-transcoder
A TypeScript library that provides gRPC to HTTP/1 & JSON transcoding for the protobuf.js library
Stars: ✭ 12 (-89.74%)
Mutual labels:  protobuf
RESTvsGRPC
Evaluating Performance of REST vs. gRPC
Stars: ✭ 36 (-69.23%)
Mutual labels:  protobuf
hsproto
Hearthstone Protobuf files
Stars: ✭ 31 (-73.5%)
Mutual labels:  protobuf
monorepo-base
A Bazel monorepo with an example service using gRPC + Go + Protobuf, deployable to GCP via Kubernetes.
Stars: ✭ 49 (-58.12%)
Mutual labels:  protobuf
grpcweb-boilerplate
A minimal repo containing all the boilerplate for getting started with GopherJS using gRPC-Web
Stars: ✭ 45 (-61.54%)
Mutual labels:  protobuf
iot-dev
Example IoT projects
Stars: ✭ 54 (-53.85%)
Mutual labels:  protobuf
protodoc
protodoc generates Protocol Buffer documentation.
Stars: ✭ 43 (-63.25%)
Mutual labels:  protobuf
savetheworldwithgo
Build systems with Go examples
Stars: ✭ 81 (-30.77%)
Mutual labels:  protobuf
makego
Makefile setup for our Golang projects.
Stars: ✭ 65 (-44.44%)
Mutual labels:  protobuf

Protocol Buffers for lua

https://github.com/jinjiazhang/protolua/

Overview

ProtoLua is a google protocol buffers C library for Lua which implement less than 1000 lines code. Parse proto2 or proto3 file dynamically without code generation, You can also redevelop it to support RPC like 'Advance Example'.

Quick Example

person.proto

syntax = "proto3";

message Person {
    string name = 1;
    int32 id = 2;
    string email = 3;
    
    enum PhoneType {
        MOBILE = 0;
        HOME = 1;
        WORK = 2;
    }
    
    message PhoneNumber {
        string number = 1;
        PhoneType type = 2;
    }
    
    repeated PhoneNumber phones = 4;
    map<string, int32> scores = 5;
}

test.lua

require "protolua"
proto.parse("person.proto")

local person = {
    name = "jinjiazh",
    id = 10001,
    email = "[email protected]",
    phones = {
        {number = "183****0402", type = PhoneType.HOME},
        {number = "186****9470", type = PhoneType.WORK},
    },
    scores = {
        ["Chinese"] = 82,
        ["Maths"] = 98,
        ["English"] = 88,
    }
}

local data = proto.encode("Person", person)
local clone = proto.decode("Person", data)

local data = proto.pack("Person", person.name, person.id, person.email, person.phones, person.scores)
local name, id, email, phones, scores = proto.unpack("Person", data)

Advance Example

syntax = "proto3";

message OnBuyItemReq {
    int32 goodsId = 1;
    int32 goodsNum = 2;
}

message OnBuyItemRsp {
    int32 retCode = 1;
    int32 goodsId = 2;
    int32 goodsNum = 3;
}
-- server code
function c2s.OnBuyItemReq( fd, goodsId, goodsNum )
    local player = FindPlayerByFd(fd)
    local retCode = shopMgr.BuyItem(player, goodsId, goodsNum)
    proto.CallClient(fd, "OnBuyItemRsp", retCode, goodsId, goodsNum)
end

-- client code
function s2c.OnBuyItemRsp( retCode, goodsId, goodsNum )
    print(retCode, goodsId, goodsNum)
end

proto.CallServer("OnBuyItemReq", 1021, 10)

Path Mapping

If you want to put *.proto files to other directory, you can use path mapping.

Example:

Directory Tree:

C:\my_project\
    proto\
        a.proto
    other_proto\
        b.proto
    run.exe
D:\any_directory\
    c.proto

Map path:

require "protolua"

-- Added by default, so there is no need to map "./" and "./proto/"
-- proto.map_path("", "./")
-- proto.map_path("", "./proto/")
proto.map_path("", "./other_proto/")
proto.map_path("", "D:\any_directory\")

-- Now, we can parse the proto files
proto.parse("a.proto")
proto.parse("b.proto")
proto.parse("c.proto")

Attention Please

lua51ext.h for int64

inline long long lua_toint64(lua_State *L, int idx)
{
    if (lua_type(L, idx) == LUA_TSTRING)
    {
        return atoll(lua_tostring(L, idx));
    }
    return (long long)lua_tonumber(L, idx);
}

inline void lua_pushint64(lua_State *L, long long value)
{
    // because of #define LUA_NUMBER_FMT "%.14g"
    if (abs(value) > 99999999999999)
    {
        char str[32];
        lua_pushstring(L, _i64toa(value, str, 10));
        return;
    }

    lua_pushnumber(L, (lua_Number)value);
}

Dependencies

lua-5.3.5: https://www.lua.org/ftp/lua-5.3.5.tar.gz
protobuf: https://github.com/google/protobuf

Contact Me

QQ:164442955

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