leizhiyuan commented on PR #680: URL: https://github.com/apache/rocketmq-clients/pull/680#issuecomment-1925295801
add some ref [protocmp](https://protobuf.dev/reference/go/faq/#deepequal) it seems only [proto.Equal](https://pkg.go.dev/google.golang.org/protobuf/proto#Equal) can be used in production code where protocmp can be used in test (for best practice) > Why does reflect.DeepEqual behave unexpectedly with protobuf messages? > Generated protocol buffer message types include internal state which can vary even between equivalent messages. > > In addition, the reflect.DeepEqual function is not aware of the semantics of protocol buffer messages, and can report differences where none exist. For example, a map field containing a nil map and one containing a zero-length, non-nil map are semantically equivalent, but will be reported as unequal by reflect.DeepEqual. > > Use the [proto.Equal](https://pkg.go.dev/google.golang.org/protobuf/proto#Equal) function to compare message values. > > In tests, you can also use the ["github.com/google/go-cmp/cmp"](https://pkg.go.dev/github.com/google/go-cmp/cmp?tab=doc) package with the [protocmp.Transform()](https://pkg.go.dev/google.golang.org/protobuf/testing/protocmp#Transform) option. The cmp package can compare arbitrary data structures, and [cmp.Diff](https://pkg.go.dev/github.com/google/go-cmp/cmp#Diff) produces human-readable reports of the differences between values. > > if diff := cmp.Diff(a, b, protocmp.Transform()); diff != "" { > t.Errorf("unexpected difference:\n%v", diff) > } -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org