reflect/protoreflect: add {Message,List,Map}.IsValid
Various protoreflect methods can return an "empty, read-only" message,
list, or map value. Provide a method to test if a value is one of these.
Fixes golang/protobuf#966
Change-Id: I793d8426d6e2201755983c06f024412a7e09bc4c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/209018
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/testing/prototest/prototest.go b/testing/prototest/prototest.go
index 79c792d..508ccb9 100644
--- a/testing/prototest/prototest.go
+++ b/testing/prototest/prototest.go
@@ -281,6 +281,7 @@
}
}
}
+func (m testMap) IsValid() bool { return true }
// testFieldList exercises set/get/append/truncate of values in a list.
func testFieldList(t testing.TB, m pref.Message, fd pref.FieldDescriptor) {
@@ -346,6 +347,7 @@
func (l *testList) Set(n int, v pref.Value) { l.a[n] = v }
func (l *testList) Truncate(n int) { l.a = l.a[:n] }
func (l *testList) NewElement() pref.Value { panic("unimplemented") }
+func (l *testList) IsValid() bool { return true }
// testFieldFloat exercises some interesting floating-point scalar field values.
func testFieldFloat(t testing.TB, m pref.Message, fd pref.FieldDescriptor) {