proto: expose package-private equalField.

There is a demand for comparing protobuf.Value-s.
One use case is when one wants to compare just one field via reflection.
Another is when one wants to iterate over fields and check for diffs.
Existing diff packages are recommended only for tests as they panic on error.
Exposing equalField will prevent excessive branching of proto/equal.go code.

Change-Id: Iec8843dae96c9ae3c45858e8b97e7aa963473ce2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/448876
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Run-TryBot: Michael Stapelberg <stapelberg@google.com>
TryBot-Bypass: Michael Stapelberg <stapelberg@google.com>
This commit is contained in:
Oleksii Prokopchuk 2022-11-09 02:24:10 +00:00 committed by Michael Stapelberg
parent 7a48e2b662
commit 4d6d2135eb

View File

@ -74,6 +74,11 @@ func equalMessage(mx, my protoreflect.Message) bool {
return equalUnknown(mx.GetUnknown(), my.GetUnknown())
}
// EqualField compares two fields.
func EqualField(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
return equalField(fd, x, y)
}
// equalField compares two fields.
func equalField(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
switch {