starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.73k stars 387 forks source link

通过cjson序列化pb.decode中空数组的问题 #197

Open doudouliyougangbeng opened 2 years ago

doudouliyougangbeng commented 2 years ago

由于lua中没有数组概念,pb.decode会把空数组当成空table,当cjson进行decode时就会序列化为{}。 现在cjson支持cjson.decode_array_with_array_mt(true)即当setmetatable({}, array_mt)时就会序列化[]。 我现在的做法为,递归所有属性,找到"repeated"的空table,进行设置 image 这种感觉非常不友好而且严重影响性能,有没有从pb方面就能很好的解决问题的方法呢?

starwing commented 2 years ago

可以讨论下看看有什么比较好的方案

bugwang commented 1 year ago

[] {} 都设置成 nil

starwing commented 1 year ago

可以考虑pb.defaults("*array", array_mt)