Open git-torrent opened 2 years ago
This is intentional for now. Because to create tables for empty sub message may decrease the performance. If this is really needed, I can add a option to enable this behavior. Any pull request are welcome.
That reminds me of old joke about Pentium FDIV bug - incorrect but fast :)
It is needed if the goal is to comply with google implementation. I would be glad to prepare PR, but I am not that skilled. I can fix the lua side by adding if wrapper then return value or default
.
This is a history issue. The module is written in the time of protobuf 2.0, at that time the sub message has not default empty value. But the semantic is changed when the protobuf 3 is out. and protobuf3 is designed by C++ semantic. That means to simulate that behaviour from Lua will largely decrease the performance: a message of C++ is just a struct that can be easily cleaned to match the protobuf 3 semantic, but this is not true for Lua.
I just add a new option "decode_default_message" to support decode the empty but with default values sub messages. You could try the master HEAD for see whether it fit your need.
Thank you for quick help and explanation.
I looked up the affected code but unfortunately not able to comprehend that. I will wait for release. Thank you again
You say this?
if (!e->LS->encode_default_values && ignoredlen != 0 && ignorezero)
e->b->size -= (unsigned)(ignoredlen + hlen);
The protobuf3 do not encode the zero-value (and has not default value, that is a protobuf2 thing). the second line used to cancel the encoded zero-value, if these conditions are meet:
"encode_default_values"
lpbE_field
does not encode anything)Thanks again for explanation. Do I understand it right that it enables encoding of all the default values?
(this is useful option in case of proto->json conversion which I must do manually).
Yes, it will. be.
It might help in some scenarios. On the other side, turning it on for not loosing array members might bloat the protobufs, what goes against their efficacy.
We can leave this issue as a request for enhancement.
Let's have message:
filled with values
test = pb.decode( pb.encode(test) )
would return:native and wrapped types are not encoded in the same way. On the other side, google implementation (checked Go, python, C#) decodes this message to:
The same applies for other repeated wrappers. All of them should be intialized to default values.
Thanks you.