all: abstract fast-path marshal and unmarshal inputs and outputs

We may want to make changes to the inputs and outputs of the fast-path
functions in the future. For example, we likely want to add the ability
for the fast-path unmarshal to report back whether the unmarshaled
message is known to be initialized.

Change the signatures of these functions to take in and return struct
types which can be extended with whatever fields we want in the future.

Change-Id: Idead360785df730283a4630ea405265b72482e62
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/215719
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/runtime/protoiface/methods.go b/runtime/protoiface/methods.go
index 4b9bb92..ed8f153 100644
--- a/runtime/protoiface/methods.go
+++ b/runtime/protoiface/methods.go
@@ -25,14 +25,14 @@
 	// MarshalAppend must be provided if a custom Size is provided.
 	Size func(m protoreflect.Message, opts MarshalOptions) int
 
-	// MarshalAppend appends the wire-format encoding of m to b, returning the result.
+	// Marshal writes the wire-format encoding of m to the provided buffer.
 	// Size should be provided if a custom MarshalAppend is provided.
 	// It must not perform required field checks.
-	MarshalAppend func(b []byte, m protoreflect.Message, opts MarshalOptions) ([]byte, error)
+	Marshal func(m protoreflect.Message, in MarshalInput) (MarshalOutput, error)
 
-	// Unmarshal parses the wire-format message in b and merges the result in m.
+	// Unmarshal parses the wire-format encoding of a message and merges the result to m.
 	// It must not reset m or perform required field checks.
-	Unmarshal func(b []byte, m protoreflect.Message, opts UnmarshalOptions) error
+	Unmarshal func(m protoreflect.Message, in UnmarshalInput) (UnmarshalOutput, error)
 
 	// IsInitialized returns an error if any required fields in m are not set.
 	IsInitialized func(m protoreflect.Message) error
@@ -48,6 +48,21 @@
 	SupportUnmarshalDiscardUnknown
 )
 
+// MarshalInput is input to the marshaler.
+type MarshalInput = struct {
+	pragma.NoUnkeyedLiterals
+
+	Buf     []byte // output is appended to this buffer
+	Options MarshalOptions
+}
+
+// MarshalOutput is output from the marshaler.
+type MarshalOutput = struct {
+	pragma.NoUnkeyedLiterals
+
+	Buf []byte // contains marshaled message
+}
+
 // MarshalOptions configure the marshaler.
 //
 // This type is identical to the one in package proto.
@@ -59,6 +74,21 @@
 	UseCachedSize bool
 }
 
+// UnmarshalInput is input to the unmarshaler.
+type UnmarshalInput = struct {
+	pragma.NoUnkeyedLiterals
+
+	Buf     []byte // input buffer
+	Options UnmarshalOptions
+}
+
+// UnmarshalOutput is output from the unmarshaler.
+type UnmarshalOutput = struct {
+	pragma.NoUnkeyedLiterals
+
+	// Contents available for future expansion.
+}
+
 // UnmarshalOptions configures the unmarshaler.
 //
 // This type is identical to the one in package proto.