Skip to content
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

Introduce Try*() Accessor Method Generation for One-Of Groups #5

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

danilvpetrov
Copy link
Member

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. If ok is false, the caller can disregard the value of foo variable as it would not be originally set in the one-of group.

    foo, ok := message.OneOf.TryFoo()

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

@jmalloc jmalloc enabled auto-merge April 22, 2024 22:26
@jmalloc jmalloc merged commit fb0d77c into main Apr 22, 2024
3 checks passed
@jmalloc jmalloc deleted the oneof-getters branch April 22, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants