Giter Site home page Giter Site logo

protoc-gen-lua's People

Contributors

krestenkrab avatar sean-lin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protoc-gen-lua's Issues

Generating code with > 200 local variables

Lua has a built in limit of 200 local variables in any one instance on the VM.

Currently, protoc-gen-lua will exceed this limit for very large protocol buffer specifications. This causes an error when one tries to use the generated code.

I propose to use global variables when creating *_pb.lua files. Although they are slower, they are only used the first time this file is parsed. This would make the effect negligible in situations where the file is require'd once and the resultant API objects are used repeatedly within the same VM context, for example in NGINX across multiple requests.

incomplete functions

in module decoder.lua, there is no implementions of function _SkipGroup and _EndGroup

io.format nil exception

protobuf.lua
line 759
name = io:format("(%s)", field.full_name)
line 765
prefix = io:format("%s[%d].", name, i)

please use string.format instead

ClearField function and nil reference

Is this usage correct?

pb_instance.ClearField("field_name")

Seems to fail with a nil reference to fields_by_name

        if message_descriptor.fields_by_name[field_name] == nil then
            error('Protocol message has no "' .. field_name .. '" field.')
        end

It looks like the member fields_by_name is never set anywhere, further in the ClearField method there also looks like another potential nil reference as field isn't set either.

int64 encoder _VarintSize error!

有64位字段的message,里面数值很大时 在计算 bytesize时出错, 应该是之前代码没兼容64位

function _VarintSize(value)
if value <= 0x7f then return 1 end
if value <= 0x3fff then return 2 end
if value <= 0x1fffff then return 3 end
if value <= 0xfffffff then return 4 end
return 5
end

may need to change:

function _VarintSize(value)
if value <= 0x7f then return 1 end
if value <= 0x3fff then return 2 end
if value <= 0x1fffff then return 3 end
if value <= 0xfffffff then return 4 end
if value <= 0x7ffffffff then return 5 end
if value <= 0x3ffffffffff then return 6 end
if value <= 0x1ffffffffffff then return 7 end
if value <= 0xffffffffffffff then return 8 end
if value <= 0x7fffffffffffffff then return 9 end
return 10
end

不知道这样改可行不可行?

嵌套多个proto的不能用

双嵌套的不能用呀

下面是报错信息 和 3个proto文件内容 求解决呀 ^~^

LUA ERROR: [string "protobuf.lua"]:288: attempt to index upvalue 'message_type' (a nil value)

文件p_result.proto:
import "p_user.proto";
import "p_major.proto";

message Result {
required int32 resultCode = 1;
optional string failCode = 2;
optional User user = 3;
optional Major major = 4;
}

文件p_user.proto:
message User{
optional string userId = 1;
required string username = 2;
optional string password = 3;
optional string channel = 4;
optional string regdate = 5;
optional string lastlogindate = 6;
optional string tokenId = 7;
optional bool isFast = 8;
optional bool isBinded = 9;
}

文件p_major.proto:
message Major{

optional string userId = 1;
optional string majorId = 2;
optional string majorCode = 3;

}

Does it suppot UINT64?

I saw in the "descriptor.lua" that there were TYPE_UINT64 and CPPTYPE_UINT64 in the file.

Now i define a uint64 field named id in a .proto file and gen a _pb.lua file.
How can i use the filed?
I write a testcase:
print(type(xxx.id))
the result is still "number".
Lua's number is a double value. It can't hold a uint64 variable.

Windows?

How to install a plugin for protoc in windows?

double may cause crash on some phone

When parse message with a double field, it may cause crash, because incorrect data alignment will send signal sigbus in these machines.So modify lua_pb.c to use follow functions to parse float and double:
static float unpack_float(const uint8_t* buffer)
{

ifdef IS_LITTLE_ENDIAN

float fvalue;
memcpy(&fvalue, buffer, sizeof(float));
return fvalue;

else

uint32_t uvalue;
memcpy(&uvalue, buffer, sizeof(uint32_t));
uvalue = le32toh(uvalue);
return *(*float)&uvalue;

endif

}

static double unpack_double(const uint8_t* buffer)
{

ifdef IS_LITTLE_ENDIAN

double dvalue;
memcpy(&dvalue, buffer, sizeof(double));
return dvalue;

else

uint64_t uvalue;
memcpy(&uvalue, buffer, sizeof(uint64_t));
uvalue = le64toh(uvalue);
return *(*double)&uvalue;

endif

}

int32 pasererror

        local msg1= person_pb.Person() 
            msg1.personid = 100
            msg1.name = "zhag"
            msg1.email = "[email protected]"
            local pb_data = msg1:SerializeToString()  -- Parse Example 
            print(msg1.personid) 
            print(msg1.name) 
            print(msg1.email)

                           print result is 100  [email protected]

            local msg2 = person_pb.Person() 
            msg2:ParseFromString(pb_data) 
            print(msg2.personid)
            print(msg2.name)
            print(msg2.email)
                           print result is 0 [email protected]

why msg2.personid is 0 ??

Index nil value

def get_ref_name(self, type_name):
return (node.filename + '_pb.').upper() + node.get_local_name()

or you just get code like this:
local MESSAGE_PB = require("Message_pb")
Message_pb.MessageSingle.RegisterExtension(REQUESTLOGIN_UP_FIELD)

Failed to parse message in lua when proto file imports another proto file

Failed to parse message in lua, when the message contains embedded field which is defined in another proto file.

the error message and stack:

[LUA-print] LUA ERROR: [string "pb/containers.lua"]:27: attempt to index field '_message_descriptor' (a nil value)

[LUA-print] stack traceback:
[string ".\script/main.lua"]:53: in function <[string ".\script/main.lua"]:50>
[string "pb/containers.lua"]:27: in function 'add'
[string "pb/decoder.lua"]:249: in function 'field_decoder'
[string "pb/protobuf.lua"]:684: in function '_InternalParse'
[string "pb/decoder.lua"]:271: in function 'field_decoder'
[string "pb/protobuf.lua"]:684: in function '_internal_parse'
[string "pb/protobuf.lua"]:693: in function 'merge_from_string'
[string "pb/protobuf.lua"]:702: in function 'ParseFromString'

report one bug for enum in protoc-gen-lua script

I report one bug for enum auto generate in protoc-gen-lua script.

proto file:
message RegisterReq {
enum CmdId
{
CMD_ID = 1;
}
optional ......
}

example:
module.REGISTERREQ_CMDID_CMD_ID_ENUM = protobuf.EnumValueDescriptor()
module.REGISTERREQ_CMDID_CMD_ID_ENUM.name = 'CMD_ID'
module.REGISTERREQ_CMDID_CMD_ID_ENUM.index = 0
module.REGISTERREQ_CMDID_CMD_ID_ENUM.number = 1
module.REGISTERREQ_CMDID.values = {REGISTERREQ_CMDID_CMD_ID_ENUM} // error
//should be
module.REGISTERREQ_CMDID.values = {module.REGISTERREQ_CMDID_CMD_ID_ENUM}

I am not very sure how to fix this gracefully

in protoc-gen-lua script 249 code_gen_enum_item function
I just change return value from
return obj_name
to
return 'module.' + obj_name

and It works

error running example test.lua

I tried running test.lua after compiling you code but getting error.

$ lua -v
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
$ protoc --version
libprotoc 3.4.0
$ protoc --lua_out=./ person.proto
$ lua test.lua
lua: ../protobuf/encoder.lua:224: attempt to call upvalue '_EncodeSignedVarint' (a nil value)
stack traceback:
	../protobuf/encoder.lua:224: in function <../protobuf/encoder.lua:219>
	(tail call): ?
	../protobuf/encoder.lua:257: in function '?'
	../protobuf/protobuf.lua:302: in function '_AttachFieldHelpers'
	../protobuf/protobuf.lua:904: in function 'Message'
	./person_pb.lua:104: in main chunk
	[C]: in function 'require'
	test.lua:4: in main chunk
	[C]: ? 

Can you please guide me?

序列化结果是乱序的

protobuf.lua中_internal_serialize函数实现,ListFields方法遍历是无序的,会导致结果不稳定,在某些情景下无法反序列化。

local _internal_serialize = function(self, write_bytes)
    for field_descriptor, field_value in message_meta._member.ListFields(self) do
        field_descriptor._encoder(write_bytes, field_value)
    end
end

改动:根据field的key的index排序,再进行遍历。

local _internal_serialize = function(self, write_bytes)
    local field_list = {}
    for k, v in pairs(self._fields) do
        field_list[k.index + 1] = k
    end
    local n = table.maxn(field_list)
    for i = 1, n do
        local descriptor = field_list[i]
        if descriptor then
            value = self._fields[descriptor]
            if _IsPresent(descriptor, value) then
                descriptor._encoder(write_bytes, value)
            end
        end
    end
end

奇怪的序列化卡死问题

message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;

extensions 10 to max;
}

message Phone {
extend Person { required Phone phones = 10;} // phones字段若是repeated就不会有问题
enum PHONE_TYPE{
MOBILE = 1;
HOME = 2;
}
repeated string num = 1; // 或是再加一个字段,序列化也没问题了
}

用法感觉也没错误啊:

local person= person_pb.Person()
person.id = 1000
person.name = "Alice"
person.email = "[email protected]"

local home = person.Extensions[person_pb.Phone.phones]
table.insert(home.num, "2147483647")

local data = person:SerializeToString()

local msg = person_pb.Person()

msg:ParseFromString(data)
print(msg)

Windows support?

Could you, please, help me with compiling it for windows platform?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.