package proto
import (
)
func (, Message) bool {
if == nil || == nil {
return == nil && == nil
}
if reflect.TypeOf().Kind() == reflect.Ptr && == {
return true
}
:= .ProtoReflect()
:= .ProtoReflect()
if .IsValid() != .IsValid() {
return false
}
return equalMessage(, )
}
func (, protoreflect.Message) bool {
if .Descriptor() != .Descriptor() {
return false
}
:= 0
:= true
.Range(func( protoreflect.FieldDescriptor, protoreflect.Value) bool {
++
:= .Get()
= .Has() && equalField(, , )
return
})
if ! {
return false
}
:= 0
.Range(func( protoreflect.FieldDescriptor, protoreflect.Value) bool {
++
return true
})
if != {
return false
}
return equalUnknown(.GetUnknown(), .GetUnknown())
}
func ( protoreflect.FieldDescriptor, , protoreflect.Value) bool {
switch {
case .IsList():
return equalList(, .List(), .List())
case .IsMap():
return equalMap(, .Map(), .Map())
default:
return equalValue(, , )
}
}
func ( protoreflect.FieldDescriptor, , protoreflect.Map) bool {
if .Len() != .Len() {
return false
}
:= true
.Range(func( protoreflect.MapKey, protoreflect.Value) bool {
:= .Get()
= .Has() && equalValue(.MapValue(), , )
return
})
return
}
func ( protoreflect.FieldDescriptor, , protoreflect.List) bool {
if .Len() != .Len() {
return false
}
for := .Len() - 1; >= 0; -- {
if !equalValue(, .Get(), .Get()) {
return false
}
}
return true
}
func ( protoreflect.FieldDescriptor, , protoreflect.Value) bool {
switch .Kind() {
case protoreflect.BoolKind:
return .Bool() == .Bool()
case protoreflect.EnumKind:
return .Enum() == .Enum()
case protoreflect.Int32Kind, protoreflect.Sint32Kind,
protoreflect.Int64Kind, protoreflect.Sint64Kind,
protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
return .Int() == .Int()
case protoreflect.Uint32Kind, protoreflect.Uint64Kind,
protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
return .Uint() == .Uint()
case protoreflect.FloatKind, protoreflect.DoubleKind:
:= .Float()
:= .Float()
if math.IsNaN() || math.IsNaN() {
return math.IsNaN() && math.IsNaN()
}
return ==
case protoreflect.StringKind:
return .String() == .String()
case protoreflect.BytesKind:
return bytes.Equal(.Bytes(), .Bytes())
case protoreflect.MessageKind, protoreflect.GroupKind:
return equalMessage(.Message(), .Message())
default:
return .Interface() == .Interface()
}
}
func (, protoreflect.RawFields) bool {
if len() != len() {
return false
}
if bytes.Equal([]byte(), []byte()) {
return true
}
:= make(map[protoreflect.FieldNumber]protoreflect.RawFields)
:= make(map[protoreflect.FieldNumber]protoreflect.RawFields)
for len() > 0 {
, , := protowire.ConsumeField()
[] = append([], [:]...)
= [:]
}
for len() > 0 {
, , := protowire.ConsumeField()
[] = append([], [:]...)
= [:]
}
return reflect.DeepEqual(, )
}