微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

自从用了 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐