-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Proto3 Nested Message Getter is not useful #54
Comments
The point is so that deeply nested proto types (e.g. message field in a message that's a field of another message, etc.) can be traversed simply, and without regard for nil message pointers along the way. You can write m.GetFoo().GetBar().GetBaz() and only check for nil right at the end. If you don't find it useful, don't use it. |
Oh, didn't know you could do That's pretty cool. However, it doesn't strike me as immediately obvious. Is there a place where such things are documented? Like golang/protobuf Tips&Tricks? ;) |
It's mentioned in the README and in the package doc, perhaps not so explicitly. |
Is there a reason why the getters don't follow a similar pattern to the C++ API, which allows you to call mutable_field() and creates an object if it doesn't already exist. Otherwise I end up writing a block like this every time I access a sub message field:
|
Take this generated code:
What is the purpose of this Getter? It will not be called on a
nil
m *FlagId
.I actually hoped it would create an new instance of the type behind the
Deployment
field, but it seems to not do anything other than a normalm.Deployment
would.I really hoped it would create a new instance if it was nil, this way I could solve the problem in without reflection:
grpc-ecosystem/grpc-gateway#32
The text was updated successfully, but these errors were encountered: