-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proto2 default optional fields construction behaviour #319
Comments
It is compliant with how the wire format looks. The API might differ for a lot of reasons, though, most notably for the fact that this library has been built from scratch while having wire format compatibility in mint, but without the goal to be API-compatible to other implementations, which is inevitable anyway because this is JavaScript. |
I see. Currently we're using this library to serve a REST API. Clients are implemented in C# using another implementation, so basically we need interop pretty much... Are there any downsides you spotted of using typed construction? If my message field is defined as Anyway, if you think it's not a good move I could always fork and manage that by ourselves I guess.. |
It's not compliant in the sense that Despite the fact that this is JavaScript, there is a way to have an API that works the same as the official implementations, which I described here: #200 (comment). |
Explicitly exposing default values made it work for us. It's a sensible workaround ATM. #200 +1 |
Looks like this can be fixed by changing this logic: https://github.com/dcodeIO/protobuf.js/blob/72bc66ccdfcf66c1645c5de311bf26078d411cac/src/ProtoBuf/Reflect/Message/Field.js#L148-L155 |
Closing this for now. Feel free to send a pull request if this is still a requirement. |
Hi,
Reading the official language guide, I came across the following clause:
When using ProtoBuf.js, I construct via builder a message (
new MyMessage ()
). All optional fields arenull
, but I guess they should be set to its type's default value, as stated above i.e. integers as zero, booleans as false and strings as empty strings. Even after decoding, if optional fields were not in the wire data they will remainnull
instead of having their protocol default values.Does this means ProtoBuf.js construction is not compliant with the protocol?
I've edited the description to better state the issue
The text was updated successfully, but these errors were encountered: