Introduce Try*()
Accessor Method Generation for One-Of Groups
#5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What change does this introduce?
This PR introduces accessor method generation for each type in "one-off" groups for protobuf messages. While
protoc-gen-go
plugin already generates accessor methods for each type in "one-of groups", those generated methods lack the ability to differentiate between the absence of a value and the presence of a zero value.The new generated methods have the following use pattern, where the returned
ok
boolean value signifies if the target value is set in "one-of" group. Ifok
is false, the caller can disregard the value offoo
variable as it would not be originally set in theone-of
group.Why make this change?
This change hopefully make developers' life simpler by introducing accessor methods on "one-of" groups that can be used deterministically to retrieve the desired value.
Is there anything you are unsure about?
No
What issues does this relate to?
N/A