Skip to content

Conversation

smarterclayton
Copy link
Contributor

Fixes #116, #117, #118

Builds upon #119 and #120

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.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@awalterschulze
Copy link
Member

Almost there :)
This is really amazing work.
Thank you so much.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@awalterschulze
Copy link
Member

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 ok with giving over your copyright on the code in pull request 121?

@awalterschulze
Copy link
Member

Are you ready for me to merge it?

@smarterclayton
Copy link
Contributor Author

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.
@smarterclayton
Copy link
Contributor Author

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.

Copy link
Member

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.

@awalterschulze
Copy link
Member

Maybe we can get to a point where we can merge before supporting castvalue of message types.
And then think about casttype and castvalue for message types, what do you think?

@smarterclayton
Copy link
Contributor Author

Well, I believe support is complete for that - it's just whether the jsonpb
changes worry you or not.

On Mon, Nov 30, 2015 at 3:34 AM, Walter Schulze [email protected]
wrote:

Maybe we can get to a point where we can merge before supporting castvalue
of message types.
And then think about casttype and castvalue for message types, what do you
think?


Reply to this email directly or view it on GitHub
#121 (comment).

@awalterschulze
Copy link
Member

Unfortunately they do worry me if they are there and not properly tested.
Lets rather drop the feature until it can properly be supported?

The other thing is that the tests are breaking for protoc 2.5 and 2.6.1, see the travis build.
I have made another comment about how to fix that.

@smarterclayton
Copy link
Contributor Author

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.

@smarterclayton
Copy link
Contributor Author

The proto error was fixed - castvalue copied and pasted something that did not support maps.

@awalterschulze
Copy link
Member

I think castvalue and casttype for message types are very hard.
I think we could merge everything without the changes made for castvalue message types and then try to tackle that separately, just because I think it is a hard problem.
If you want to continue in this pull request, you are welcome.
I just think splitting the work here will make this a little easier.

@smarterclayton
Copy link
Contributor Author

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)

@awalterschulze
Copy link
Member

Sorry about the delay.
I was on holiday yesterday.
I'll get to this ASAP

@awalterschulze
Copy link
Member

I can't remember, but I think you mentioned a problem with imported casttype messages?
I think the generated code will cause a circular dependancy. So its a easy case not to support even though messages that are in the same package actually do seem to work.

Copy link
Member

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?

Copy link
Member

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.

awalterschulze added a commit that referenced this pull request Dec 7, 2015
Support nullable=false on a map to mean embedded map value
@awalterschulze awalterschulze merged commit 89243af into gogo:master Dec 7, 2015
@awalterschulze
Copy link
Member

Thank you very much smartest clayton.
This is some excellent work. I really appreciate your efforts.

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