internal/impl: add message validator

This adds a experimental function to the internal/impl package which
validates a wire-format message against a message type. The validator
reports whether the message can be successfully unmarshaled, and whether
the result is initialized (all required fields are set). In some cases,
the validator returns ambiguous results when full validation would be
expensive.

The validator is unused outside of tests. In the future, it may be used
to permit lazy unmarshaling of some data. It is being added now for
testing; in particular, the wire fuzzer now checks the validator output
for consistency with the unmarshaler.

The validator adds a small amount of unused per-MessageType state. If
this becomes a concern, we could conditionalize it with a build tag.

Change-Id: I4216ef81d6a9ed975302eed189b02d08608858b4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/212302
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/testprotos/test/test.proto b/internal/testprotos/test/test.proto
index e501b7a..644110d 100644
--- a/internal/testprotos/test/test.proto
+++ b/internal/testprotos/test/test.proto
@@ -43,6 +43,7 @@
   optional bytes         optional_bytes    = 15;
   optional group OptionalGroup = 16 {
     optional int32 a = 17;
+    optional NestedMessage optional_nested_message = 1000;
   }
   optional NestedMessage  optional_nested_message  = 18;
   optional ForeignMessage optional_foreign_message = 19;
@@ -68,6 +69,7 @@
   repeated bytes         repeated_bytes    = 45;
   repeated group RepeatedGroup = 46 {
     optional int32 a = 47;
+    optional NestedMessage optional_nested_message = 1001;
   }
   repeated NestedMessage  repeated_nested_message  = 48;
   repeated ForeignMessage repeated_foreign_message = 49;
@@ -188,6 +190,7 @@
 
   optional group OptionalGroup_extension = 16 {
     optional int32 a = 17;
+    optional TestAllTypes.NestedMessage optional_nested_message = 1000;
   }
 
   optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
@@ -211,6 +214,7 @@
 
   repeated group RepeatedGroup_extension = 46 {
     optional int32 a = 47;
+    optional TestAllTypes.NestedMessage optional_nested_message = 1001;
   }
 
   repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;