// Copyright 2022 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package protoreflectimport ()// Equal reports whether v1 and v2 are recursively equal.//// - Values of different types are always unequal.//// - Bytes values are equal if they contain identical bytes.// Empty bytes (regardless of nil-ness) are considered equal.//// - Floating point values are equal if they contain the same value.// Unlike the == operator, a NaN is equal to another NaN.//// - Enums are equal if they contain the same number.// Since [Value] does not contain an enum descriptor,// enum values do not consider the type of the enum.//// - Other scalar values are equal if they contain the same value.//// - [Message] values are equal if they belong to the same message descriptor,// have the same set of populated known and extension field values,// and the same set of unknown fields values.//// - [List] values are equal if they are the same length and// each corresponding element is equal.//// - [Map] values are equal if they have the same set of keys and// the corresponding value for each key is equal.func ( Value) ( Value) bool {returnequalValue(, )}func (, Value) bool { := .typ == .typswitch .typ {casenilType:returncaseboolType:return && .Bool() == .Bool()caseint32Type, int64Type:return && .Int() == .Int()caseuint32Type, uint64Type:return && .Uint() == .Uint()casefloat32Type, float64Type:return && equalFloat(.Float(), .Float())casestringType:return && .String() == .String()casebytesType:return && bytes.Equal(.Bytes(), .Bytes())caseenumType:return && .Enum() == .Enum()default:switch x := .Interface().(type) {caseMessage: , := .Interface().(Message)return && equalMessage(, )caseList: , := .Interface().(List)return && equalList(, )caseMap: , := .Interface().(Map)return && equalMap(, )default:panic(fmt.Sprintf("unknown type: %T", )) } }}// equalFloat compares two floats, where NaNs are treated as equal.func (, float64) bool {ifmath.IsNaN() || math.IsNaN() {returnmath.IsNaN() && math.IsNaN() }return == }// equalMessage compares two messages.func (, Message) bool {if .Descriptor() != .Descriptor() {returnfalse } := 0 := true .Range(func( FieldDescriptor, Value) bool { ++ := .Get() = .Has() && equalValue(, )return })if ! {returnfalse } := 0 .Range(func( FieldDescriptor, Value) bool { ++returntrue })if != {returnfalse }returnequalUnknown(.GetUnknown(), .GetUnknown())}// equalList compares two lists.func (, List) bool {if .Len() != .Len() {returnfalse }for := .Len() - 1; >= 0; -- {if !equalValue(.Get(), .Get()) {returnfalse } }returntrue}// equalMap compares two maps.func (, Map) bool {if .Len() != .Len() {returnfalse } := true .Range(func( MapKey, Value) bool { := .Get() = .Has() && equalValue(, )return })return}// equalUnknown compares unknown fields by direct comparison on the raw bytes// of each individual field number.func (, RawFields) bool {iflen() != len() {returnfalse }ifbytes.Equal([]byte(), []byte()) {returntrue } := make(map[FieldNumber]RawFields) := make(map[FieldNumber]RawFields)forlen() > 0 { , , := protowire.ConsumeField() [] = append([], [:]...) = [:] }forlen() > 0 { , , := protowire.ConsumeField() [] = append([], [:]...) = [:] }returnreflect.DeepEqual(, )}
The pages are generated with Goldsv0.7.6. (GOOS=linux GOARCH=amd64)