-
Notifications
You must be signed in to change notification settings - Fork 810
Support nullable=false on a map to mean embedded map value #121
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
Support nullable=false on a map to mean embedded map value #121
Conversation
Allow Go maps that use type aliases for their key or value.
Add a casttype test to casttype.proto
map[string]Message does not allow reflect.Value#Addr() on the reflect.Value retrieved by accessing the map at an index, because the map value is not accessable as a pointer. Create a copy of the value if CanAddr() is false before invoking proto.Text and jsonpb.Marshal. Required to support nullable=false map values
Instead of map<string,Message> becoming map[string]*Message, use nullable=false to indicate the resulting map should be map[string]Message, which can be used to avoid indirection in the maps.
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 could probably have two Wilson tests, one with nullable=false and one without?
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.
Yes
Almost there :) |
Unmarshaller should explicitly include that.
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 should probably mention that this is not supported on message types?
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.
Hrm - I can add a test, I thought it would be supported. Let me try that.
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.
I forgot, this is hard to test with the structure of test cast type. It will work when the alias type is in the same package and points to the generated struct (we have an example of it in Kube). Will think on how to deliver a better test here - is a follow up fine?
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.
Yes I think just say we don't support messages for castvalue.
If you can figure out how to support and test it, then we just update the doc at that point.
I am only nit picking now, because everything looks correct and pretty much ready to be merged. I also think I need to ask again, since this is a new pull request. |
Are you ready for me to merge it? |
I'll go through and address those comments - just thinking of the next person to come in here :) Yes, I am fine with transferring copyright for this pull request. |
jsonpb doesn't have access to the original type of the cast map value from Proto, which means the generic struct reflection marshalling fails if the cast type is not proto.Message. Add a struct tag annotation that indicates the original message type so we can look it up in the proto registry.
Fixed more edge cases and applied review feedback. See the jsonpb commit - I'm not sure this is the best solution, but without access to the proto.Properties map key and value data, it's a harder problem. |
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 just reuse the values again instead of assigning new ones.
Maybe we can get to a point where we can merge before supporting castvalue of message types. |
Well, I believe support is complete for that - it's just whether the jsonpb On Mon, Nov 30, 2015 at 3:34 AM, Walter Schulze [email protected]
|
Unfortunately they do worry me if they are there and not properly tested. The other thing is that the tests are breaking for protoc 2.5 and 2.6.1, see the travis build. |
By not properly tested - I believe the castvalue test case exercises all the code paths (but I could be wrong). The problem of castvalue I believe is a general problem, not specific to nullable message vs non-nullable message. The use case we had was for map[string]MessageAlias - so I need to solve castvalue of a message one way or another. |
The proto error was fixed - castvalue copied and pasted something that did not support maps. |
I think castvalue and casttype for message types are very hard. |
I may be missing the areas that you're most concerned with. Is there generated code that combo doesn't touch that I may be missing? Two more commits added that cover castvalue more thoroughly (with fixes) |
Sorry about the delay. |
I can't remember, but I think you mentioned a problem with imported casttype messages? |
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.
This could just be a normal if and else?
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.
Don't worry I fixed this.
Support nullable=false on a map to mean embedded map value
Thank you very much smartest clayton. |
Fixes #116, #117, #118
Builds upon #119 and #120