protoc-gen-lua Extensions 中只有repeated 导致 Crash

来源:互联网 发布:小米wifi mac 编辑:程序博客网 时间:2024/06/11 23:44

自从用了 protoc-gen-lua 之后,就有了各种各样的问题。之前总结了一些 注意事项

protoc-gen-lua extensions正确的使用方式

Unity中使用SLua的一些注意事项


比如 : 对于proto-lua-gen 如果一个message 中有一个 extensions ,但是这个 extensions是一个空的 message 像下面

    --Student.protp         message Student    {      required int32 id = 1;           extensions 10 to max;    }         message Phone    {    extend Student    {      repeated Phone phones = 10;    }    }

那么要注意,序列化 Student 的时候,千万不要手贱去获取 extensions ,然后序列化 ,会卡死的!!

    local student= Student_pb.Person()      local phone = student.Extensions[Student_pb.Phone.phones]      local data = student:SerializeToString()   --卡死  

如果 extensions 的message 是空的,就不要去管他,这样写

    local student= Student_pb.Person()      local data = student:SerializeToString()   --正常  

然后在 游戏中 空的 message 的话,虽然可以不去获取 extensions来避免崩溃卡死,但是这样的数据会出问题,

所以对于之前的空的message,我们就设置一个 optional的值 。

然后在 代码中使用这个message的时候一定要记得设置这个optional的值。

然后今天发现:

如果 message  只有 repeated 标签,而没有 optional 、required ,也会导致崩溃!!!


所以也只好加上一个 optional  来暂时解决这个问题。。


message Person {  required int32 id = 1;  extensions 10 to max;}message Phone {    extend Person     {       required Phone vphone = 10;    }    repeated string phonenum=1;    optional int32 phoneid=2;    //如果没有这个optional,就会crash}



测试工程下载:

http://pan.baidu.com/s/1WBme6


0 0
原创粉丝点击