-
Notifications
You must be signed in to change notification settings - Fork 806
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
Bug: Conflict with Size fieldname and Size method name #56
Comments
I have made this fix on the sizeunderscore branch. |
merged |
Is there something special about the Size method? I mean, is it the part of some stdlib interface, or it's a gogoprotobuf addition? |
It might be, but not yet. You can use gogoproto.customname to change the field name again. |
I'm wondering, is it possible to change Size method to SizePb or something like that? type sizer interface{
SizePb() int
}
func (this *codec) Marshal(v interface{}) ([]byte, error) {
var n int
if psz, ok := v.(sizer); ok {
n = psz.SizePb()
} else if sz, ok := v.(interface{ Size() int }); ok { // compatibility
n = sz.Size()
}
// ...
} For lib users we can have one more option to generate Size methods instead of SizePb. It will still work for both variants since we check each interface on Marshal. |
That is a lot of effort for very little pay off. |
This is the TODO I was talking about |
It's important because Size is a pretty common name for both methods and fields. String method has its interface already defined in Go, so it's ok to rename all user's fields and methods to avoid collisions. But Size is different. There is already interface with a Size method in stdlib with a completely different meaning: The issue can be easily resolved with fork, as Dropbox guys done, but it would be better to have it in official repo, I believe :) |
You make a compelling argument, but this is still a breaking change. |
I agree, another extension is a much better way than just renaming everything at once. |
Ok that will be great. extensions name: protosizer Maybe the marshal plugin could check which of protosizer or sizer is used and then call that method. |
I should look at the code more closely, but it sounds right to check for used extension. I'll post a PR in a few days then. I hope I will get enough time to test it properly :) |
…go#56. Regenerate files.
…go#56. Regenerate files.
This issue was originally reported here: #39.
I see that when you have a field named String golang/protobuf generates that fieldname as String_, since this field conflict with the generated String method.
I think this would be a great solution to the Size method and fieldname conflict problem.
The text was updated successfully, but these errors were encountered: