MCPcopy
hub / github.com/golang/protobuf / anyEqual

Function anyEqual

proto/text_test.go:33–41  ·  view source on GitHub ↗

anyEqual reports whether two messages which may be google.protobuf.Any or may contain google.protobuf.Any fields are equal. We can't use proto.Equal for comparison, because semantically equivalent messages may be marshaled to binary in different tag order. Instead, trust that TextMarshaler with Expa

(got, want proto.Message)

Source from the content-addressed store, hash-verified

31// binary in different tag order. Instead, trust that TextMarshaler with
32// ExpandAny option works and compare the text marshaling results.
33func anyEqual(got, want proto.Message) bool {
34 // if messages are proto.Equal, no need to marshal.
35 if proto.Equal(got, want) {
36 return true
37 }
38 g := expandedMarshaler.Text(got)
39 w := expandedMarshaler.Text(want)
40 return g == w
41}
42
43type golden struct {
44 m proto.Message

Callers 1

TestUnmarshalGoldenFunction · 0.85

Calls 2

EqualFunction · 0.92
TextMethod · 0.80

Tested by

no test coverage detected