-
Notifications
You must be signed in to change notification settings - Fork 39
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
proto gen: support optionals for proto syntax 3 #105
Conversation
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.
Looks good to me, @aadedamola.
A couple of minor comments from me.
WDYT, @utrack ?
integration/binding_with_optional_field/strings/strings.to_upper.go
Outdated
Show resolved
Hide resolved
@@ -203,17 +203,30 @@ func addValueTyped(f *descriptor.Field) string { | |||
if valueFormatter != "" { | |||
return fmt.Sprintf(valueFormatter, getter) | |||
} | |||
|
|||
if f.GetProto3Optional() { |
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.
is it possible to have both value formatter and optional for the same field?
I guess not, but could you please check it?
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.
We can have both -- currently, the valueformatter is used for encoding bytes. Bytes evaluate to the byte[] scalar type on go which is nullable. So the current implementation works.
The question is do we want to create pointers for bytes[] on code generation instead? And if yes, why?
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.
Agree. I don't think we need a pointer to a slice
return fmt.Sprintf(`fmt.Sprintf("%s", %s)`, valueVerb, getter) | ||
} | ||
|
||
if !isRepeated { | ||
if isRepeated { |
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.
It is not possible to have both optional and repeated for the same field, right?
It does not make much sense to me, but is it possible from the protobuf perspective?
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.
To the best of my knowledge, repeated fields are inherently optional. If we try to put both optional and repeated on the same field, the parser will raise an error (did a quick experiment btw)
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.
Also, an answer on Stack Overflow -- https://stackoverflow.com/a/25637833
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.
Thanks for checking it
LGTM, thanks! :) |
Based on the issue raised, this PR adds support for optional fields in proto 3. It also contains a test case for an optional field.