proto, runtime/protoiface: add support for fast-path marshaling

Allow message implementations to provide optimized versions of standard
operations. Generated messages now include a ProtoReflectMethods method,
returning a protoiface.Methods struct containing pointers to assorted
optional functions.

The Methods struct also includes a Flags field indicating support for
optional features such as deterministic marshaling.

Implementation of the fast paths (and tests) will come in later CLs.

Change-Id: Idd1beed0ecf43ec5e5e7b8da2ee1e08d3ce32213
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/170340
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index c9f3fb6..4025320 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -325,6 +325,10 @@
 	return xxx_File_test_test_proto_messageTypes[0].MessageOf(x)
 }
 
+func (m *TestAllTypes) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[0].Methods()
+}
+
 // Deprecated: Use TestAllTypes.ProtoReflect.Type instead.
 func (*TestAllTypes) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{0}
@@ -1064,6 +1068,10 @@
 	return xxx_File_test_test_proto_messageTypes[1].MessageOf(x)
 }
 
+func (m *TestDeprecatedMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[1].Methods()
+}
+
 // Deprecated: Use TestDeprecatedMessage.ProtoReflect.Type instead.
 func (*TestDeprecatedMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{1}
@@ -1131,6 +1139,10 @@
 	return xxx_File_test_test_proto_messageTypes[2].MessageOf(x)
 }
 
+func (m *ForeignMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[2].Methods()
+}
+
 // Deprecated: Use ForeignMessage.ProtoReflect.Type instead.
 func (*ForeignMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{2}
@@ -1170,6 +1182,10 @@
 	return xxx_File_test_test_proto_messageTypes[3].MessageOf(x)
 }
 
+func (m *TestReservedFields) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[3].Methods()
+}
+
 // Deprecated: Use TestReservedFields.ProtoReflect.Type instead.
 func (*TestReservedFields) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{3}
@@ -1196,6 +1212,10 @@
 	return xxx_File_test_test_proto_messageTypes[4].MessageOf(x)
 }
 
+func (m *TestAllExtensions) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[4].Methods()
+}
+
 // Deprecated: Use TestAllExtensions.ProtoReflect.Type instead.
 func (*TestAllExtensions) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{4}
@@ -1231,6 +1251,10 @@
 	return xxx_File_test_test_proto_messageTypes[5].MessageOf(x)
 }
 
+func (m *OptionalGroupExtension) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[5].Methods()
+}
+
 // Deprecated: Use OptionalGroupExtension.ProtoReflect.Type instead.
 func (*OptionalGroupExtension) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{5}
@@ -1264,6 +1288,10 @@
 	return xxx_File_test_test_proto_messageTypes[6].MessageOf(x)
 }
 
+func (m *RepeatedGroupExtension) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[6].Methods()
+}
+
 // Deprecated: Use RepeatedGroupExtension.ProtoReflect.Type instead.
 func (*RepeatedGroupExtension) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{6}
@@ -1296,6 +1324,10 @@
 	return xxx_File_test_test_proto_messageTypes[7].MessageOf(x)
 }
 
+func (m *TestNestedExtension) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[7].Methods()
+}
+
 // Deprecated: Use TestNestedExtension.ProtoReflect.Type instead.
 func (*TestNestedExtension) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{7}
@@ -1322,6 +1354,10 @@
 	return xxx_File_test_test_proto_messageTypes[8].MessageOf(x)
 }
 
+func (m *FooRequest) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[8].Methods()
+}
+
 // Deprecated: Use FooRequest.ProtoReflect.Type instead.
 func (*FooRequest) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{8}
@@ -1347,6 +1383,10 @@
 	return xxx_File_test_test_proto_messageTypes[9].MessageOf(x)
 }
 
+func (m *FooResponse) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[9].Methods()
+}
+
 // Deprecated: Use FooResponse.ProtoReflect.Type instead.
 func (*FooResponse) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{9}
@@ -1374,6 +1414,10 @@
 	return xxx_File_test_test_proto_messageTypes[10].MessageOf(x)
 }
 
+func (m *TestAllTypes_NestedMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[10].Methods()
+}
+
 // Deprecated: Use TestAllTypes_NestedMessage.ProtoReflect.Type instead.
 func (*TestAllTypes_NestedMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{0, 0}
@@ -1414,6 +1458,10 @@
 	return xxx_File_test_test_proto_messageTypes[11].MessageOf(x)
 }
 
+func (m *TestAllTypes_OptionalGroup) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[11].Methods()
+}
+
 // Deprecated: Use TestAllTypes_OptionalGroup.ProtoReflect.Type instead.
 func (*TestAllTypes_OptionalGroup) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{0, 1}
@@ -1447,6 +1495,10 @@
 	return xxx_File_test_test_proto_messageTypes[12].MessageOf(x)
 }
 
+func (m *TestAllTypes_RepeatedGroup) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_proto_messageTypes[12].Methods()
+}
+
 // Deprecated: Use TestAllTypes_RepeatedGroup.ProtoReflect.Type instead.
 func (*TestAllTypes_RepeatedGroup) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_proto_rawDescGZIP(), []int{0, 2}
diff --git a/internal/testprotos/test/test_import.pb.go b/internal/testprotos/test/test_import.pb.go
index 8949257..6a5fc07 100644
--- a/internal/testprotos/test/test_import.pb.go
+++ b/internal/testprotos/test/test_import.pb.go
@@ -6,6 +6,7 @@
 import (
 	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
 	protoregistry "github.com/golang/protobuf/v2/reflect/protoregistry"
+	protoiface "github.com/golang/protobuf/v2/runtime/protoiface"
 	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
 	sync "sync"
 )
@@ -79,6 +80,10 @@
 	return xxx_File_test_test_import_proto_messageTypes[0].MessageOf(x)
 }
 
+func (m *ImportMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_import_proto_messageTypes[0].Methods()
+}
+
 // Deprecated: Use ImportMessage.ProtoReflect.Type instead.
 func (*ImportMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_import_proto_rawDescGZIP(), []int{0}
diff --git a/internal/testprotos/test/test_public.pb.go b/internal/testprotos/test/test_public.pb.go
index fde1bd6..1c76763 100644
--- a/internal/testprotos/test/test_public.pb.go
+++ b/internal/testprotos/test/test_public.pb.go
@@ -6,6 +6,7 @@
 import (
 	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
 	protoregistry "github.com/golang/protobuf/v2/reflect/protoregistry"
+	protoiface "github.com/golang/protobuf/v2/runtime/protoiface"
 	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
 	sync "sync"
 )
@@ -32,6 +33,10 @@
 	return xxx_File_test_test_public_proto_messageTypes[0].MessageOf(x)
 }
 
+func (m *PublicImportMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_public_proto_messageTypes[0].Methods()
+}
+
 // Deprecated: Use PublicImportMessage.ProtoReflect.Type instead.
 func (*PublicImportMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_public_proto_rawDescGZIP(), []int{0}
diff --git a/internal/testprotos/test/test_weak.pb.go b/internal/testprotos/test/test_weak.pb.go
index 5f52a22..541908c 100644
--- a/internal/testprotos/test/test_weak.pb.go
+++ b/internal/testprotos/test/test_weak.pb.go
@@ -6,6 +6,7 @@
 import (
 	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
 	protoregistry "github.com/golang/protobuf/v2/reflect/protoregistry"
+	protoiface "github.com/golang/protobuf/v2/runtime/protoiface"
 	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
 	sync "sync"
 )
@@ -32,6 +33,10 @@
 	return xxx_File_test_test_weak_proto_messageTypes[0].MessageOf(x)
 }
 
+func (m *WeakImportMessage) XXX_Methods() *protoiface.Methods {
+	return xxx_File_test_test_weak_proto_messageTypes[0].Methods()
+}
+
 // Deprecated: Use WeakImportMessage.ProtoReflect.Type instead.
 func (*WeakImportMessage) Descriptor() ([]byte, []int) {
 	return xxx_File_test_test_weak_proto_rawDescGZIP(), []int{0}