-
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
Resolve default values when using message getters #412
Conversation
I was looking at the logic for |
You are correct. I'll fix it. |
I don't remember off the top of my head how pb in other langs works, but I feel like I can assign |
If the field is unset or assigned to a default value, then on the wire the field is just omitted. Setting a field to null directly should be considered incorrect and a method like clear should be used instead. Which, clear does not yet exist in Protobuf.js, though I have implemented it on my end. I plan to create a PR for that too in the near future. For checking if the value is set, I only check if the value is null or the default value. The C++ implementation actually returns true even if the user sets the field to it's default value. It would be possible to do the same here by setting an additional flag on the message when the field is set using a setter, but I chose not to do this to continue support for using the dot accessor of the property. Though, as I previously commented, would prefer if direct access to the properties were limited to allow for more correct functionality of things like the |
Ah! Gotcha, thanks that was the missing part for me. Thanks for the info! |
@englercj Here's a proof of concept for how we could make the I plan on cleaning this up a bit and actually obscuring the nullable properties on the message and then using |
Basically, the only case I see where this PR is remotely useful is when using proto2 without explicit defaults to fall back to the default value (which you can already do by using e.g.
Please don't do that. Accessors are not idiomatic in JavaScript. |
What is accomplished in this PR: