protobuf
protobuf copied to clipboard
Known Issue: unknown behaviour for proto.Equal
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
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?
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?
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:
- Using the gogoprotobuf equal extension https://godoc.org/github.com/gogo/protobuf/plugin/equal
- Using my new project https://github.com/awalterschulze/goderive
Thanks! The equal extension looks good! But I've run into another issue with it, reported in #283.
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 https://github.com/gogo/protobuf/blob/5628607bb4c51c3157aacc3a50f0ab707582b805/proto/equal.go#L151 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.