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/internal/impl/legacy_message.go b/internal/impl/legacy_message.go
index 3d0a921..1bded31 100644
--- a/internal/impl/legacy_message.go
+++ b/internal/impl/legacy_message.go
@@ -457,6 +457,12 @@
func (m aberrantMessage) SetUnknown(pref.RawFields) {
// SetUnknown discards its input on messages which don't support unknown field storage.
}
+func (m aberrantMessage) IsValid() bool {
+ // An invalid message is a read-only, empty message. Since we don't know anything
+ // about the alleged contents of this message, we can't say with confidence that
+ // it is invalid in this sense. Therefore, report it as valid.
+ return true
+}
func (m aberrantMessage) ProtoMethods() *piface.Methods {
return legacyProtoMethods
}