protoc-gen-lua Extensions 中只有repeated 导致 Crash
发布时间:2020-12-14 21:57:09 所属栏目:大数据 来源:网络整理
导读:自从用了 protoc-gen-lua?之后,就有了各种各样的问题。之前总结了一些?注意事项 protoc-gen-lua extensions正确的使用方式 Unity中使用SLua的一些注意事项 比如 : 对于proto-lua-gen 如果一个message 中有一个 extensions ,但是这个 extensions是一个空的
自从用了 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |