Skip to content
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

Known Issue: unknown behaviour for proto.Equal #13

Open
awalterschulze opened this issue Dec 3, 2014 · 5 comments
Open

Known Issue: unknown behaviour for proto.Equal #13

awalterschulze opened this issue Dec 3, 2014 · 5 comments

Comments

@awalterschulze
Copy link
Member

From awalterschulze on May 07, 2014 21:17:58

proto.Equal(a, b Message) bool has not been tested with all gogoprotobuf scenarios.

If you are using this please comment so I can up the priority.

Original issue: http://code.google.com/p/gogoprotobuf/issues/detail?id=13

@awalterschulze awalterschulze self-assigned this Dec 3, 2014
@awalterschulze awalterschulze changed the title unknown behaviour for proto.Equal Known Issue: unknown behaviour for proto.Equal May 22, 2015
@awalterschulze awalterschulze removed the bug label Jun 2, 2015
@awalterschulze awalterschulze removed their assignment Oct 12, 2015
@awalterschulze
Copy link
Member Author

This should be reported in another issue, but you could check out in test/thetest.proto

message NidRepCustom {
    repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
    repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false];
}

The equal method does the following

func (uuid Uuid) Equal(other Uuid) bool {
    return bytes.Equal(uuid[0:], other[0:])
}

Does this help?

@andreimatei
Copy link

I've run into problems with proto.Equal() and a proto where we use gogoproto.customtype for a bytes field. I hope this is the right place to report.

This is the proto:
https://github.com/cockroachdb/cockroach/blob/befea82/pkg/roachpb/metadata.proto#L73

And the error is:

panic: interface conversion: interface {} is roachpb.RKey, not []uint8

It's because of this special handling of bytes fields in proto.Equal:
https://github.com/golang/protobuf/blob/ef00c02/proto/equal.go#L218

Any ideas for a work-around?

@awalterschulze
Copy link
Member Author

You are welcome to contribute a fix with a test, but an easier fix might be to just generate equal methods.
Generating equal methods can be done in two ways:

  1. Using the gogoprotobuf equal extension https://godoc.org/github.com/gogo/protobuf/plugin/equal
  2. Using my new project https://github.com/awalterschulze/goderive

@andreimatei
Copy link

Thanks! The equal extension looks good! But I've run into another issue with it, reported in #283.

@tigrannajaryan
Copy link

When using a customtype that is an array proto.Equal does not work, outputs log message proto: don't know how to compare ....

The switch at

switch v1.Kind() {
does not appear to handle reflect.Array case which explains why this does not work.

Before digging into the code I also tried defining Equal func for my customtype since I was expecting that it may be used, but proto.Equal does not appear to try to use it at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants