-
Notifications
You must be signed in to change notification settings - Fork 122
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
Include the 'has_FIELD?' methods in RBIs generated from protobuf #1835
Conversation
7a6191e
to
1d596b5
Compare
The failing CI is because something that seems unrelated:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is an important omission to address. I have a few comments/questions before we can merge this, though.
1d596b5
to
63da440
Compare
63da440
to
6332ca0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the changes. This looks great now! Thanks again for the contribution.
I don't know what's up with the tests, but I'll merge this since they don't seem to be related at all. |
Motivation
Optional fields may not be present in the serialized payload. The regular accessors will still return the default value for that field type (e.g. 0 or ""). Sometimes you want to know the difference between "default value" and "present in payload", and the
has_FIELD?
methods are there for that:https://protobuf.dev/reference/ruby/ruby-generated/#checking-presence
The return type is pretty weird - it's
false
for when the field isn't present, and 0 for when it is.Implementation
Define the
has_FIELD?
method for all fields that are optional.Tests
There are tests.