encoding: switch ordering of Unmarshal arguments

While it is general convention that the receiver being mutated
is the first argument, the standard library specifically goes against
this convention when it comes to the Unmarshal function.

Switch the ordering of the Unmarshal function to match the Go stdlib.

Change-Id: I893346680233ef9fec7104415a54a0a7ae353378
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/177258
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/encoding/bench_test.go b/encoding/bench_test.go
index 5a54130..ab0fbbd 100644
--- a/encoding/bench_test.go
+++ b/encoding/bench_test.go
@@ -166,7 +166,7 @@
 		if *benchV1 {
 			err = protoV1.UnmarshalText(string(in), m)
 		} else {
-			err = prototext.Unmarshal(m, in)
+			err = prototext.Unmarshal(in, m)
 		}
 		if err != nil {
 			b.Fatal(err)
@@ -203,7 +203,7 @@
 		if *benchV1 {
 			err = jsonpbV1.UnmarshalString(string(out), m)
 		} else {
-			err = protojson.Unmarshal(m, out)
+			err = protojson.Unmarshal(out, m)
 		}
 		if err != nil {
 			b.Fatal(err)
diff --git a/encoding/jsonpb/jsonpb.go b/encoding/jsonpb/jsonpb.go
index 43c28b5..4cf24d6 100644
--- a/encoding/jsonpb/jsonpb.go
+++ b/encoding/jsonpb/jsonpb.go
@@ -1,13 +1,17 @@
 // Package jsonpb is deprecated.
 package jsonpb
 
-import "google.golang.org/protobuf/encoding/protojson"
-
-var (
-	Marshal   = protojson.Marshal
-	Unmarshal = protojson.Unmarshal
+import (
+	"google.golang.org/protobuf/encoding/protojson"
+	"google.golang.org/protobuf/proto"
 )
 
+var Marshal = protojson.Marshal
+
+func Unmarshal(m proto.Message, b []byte) error {
+	return protojson.Unmarshal(b, m)
+}
+
 type (
 	MarshalOptions   = protojson.MarshalOptions
 	UnmarshalOptions = protojson.UnmarshalOptions
diff --git a/encoding/protojson/bench_test.go b/encoding/protojson/bench_test.go
index 595c908..70603af 100644
--- a/encoding/protojson/bench_test.go
+++ b/encoding/protojson/bench_test.go
@@ -15,7 +15,7 @@
 	input := []byte(`"-123456789.123456789s"`)
 
 	for i := 0; i < b.N; i++ {
-		err := protojson.Unmarshal(&knownpb.Duration{}, input)
+		err := protojson.Unmarshal(input, &knownpb.Duration{})
 		if err != nil {
 			b.Fatal(err)
 		}
diff --git a/encoding/protojson/decode.go b/encoding/protojson/decode.go
index b6c056e..99e1a8b 100644
--- a/encoding/protojson/decode.go
+++ b/encoding/protojson/decode.go
@@ -21,8 +21,8 @@
 )
 
 // Unmarshal reads the given []byte into the given proto.Message.
-func Unmarshal(m proto.Message, b []byte) error {
-	return UnmarshalOptions{}.Unmarshal(m, b)
+func Unmarshal(b []byte, m proto.Message) error {
+	return UnmarshalOptions{}.Unmarshal(b, m)
 }
 
 // UnmarshalOptions is a configurable JSON format parser.
@@ -48,7 +48,7 @@
 // options in UnmarshalOptions object. It will clear the message first before
 // setting the fields. If it returns an error, the given message may be
 // partially set.
-func (o UnmarshalOptions) Unmarshal(m proto.Message, b []byte) error {
+func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error {
 	mr := m.ProtoReflect()
 	// TODO: Determine if we would like to have an option for merging or only
 	// have merging behavior.  We should at least be consistent with textproto
diff --git a/encoding/protojson/decode_test.go b/encoding/protojson/decode_test.go
index 75b28d3..ba8f10b 100644
--- a/encoding/protojson/decode_test.go
+++ b/encoding/protojson/decode_test.go
@@ -2596,7 +2596,7 @@
 	for _, tt := range tests {
 		tt := tt
 		t.Run(tt.desc, func(t *testing.T) {
-			err := tt.umo.Unmarshal(tt.inputMessage, []byte(tt.inputText))
+			err := tt.umo.Unmarshal([]byte(tt.inputText), tt.inputMessage)
 			if err != nil && !tt.wantErr {
 				t.Errorf("Unmarshal() returned error: %v\n\n", err)
 			}
diff --git a/encoding/prototext/decode.go b/encoding/prototext/decode.go
index f9263bd..efc4c7a 100644
--- a/encoding/prototext/decode.go
+++ b/encoding/prototext/decode.go
@@ -20,8 +20,8 @@
 )
 
 // Unmarshal reads the given []byte into the given proto.Message.
-func Unmarshal(m proto.Message, b []byte) error {
-	return UnmarshalOptions{}.Unmarshal(m, b)
+func Unmarshal(b []byte, m proto.Message) error {
+	return UnmarshalOptions{}.Unmarshal(b, m)
 }
 
 // UnmarshalOptions is a configurable textproto format unmarshaler.
@@ -41,7 +41,7 @@
 
 // Unmarshal reads the given []byte and populates the given proto.Message using options in
 // UnmarshalOptions object.
-func (o UnmarshalOptions) Unmarshal(m proto.Message, b []byte) error {
+func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error {
 	var nerr errors.NonFatal
 
 	mr := m.ProtoReflect()
diff --git a/encoding/prototext/decode_test.go b/encoding/prototext/decode_test.go
index 4837117..20fcc94 100644
--- a/encoding/prototext/decode_test.go
+++ b/encoding/prototext/decode_test.go
@@ -1523,7 +1523,7 @@
 	for _, tt := range tests {
 		tt := tt
 		t.Run(tt.desc, func(t *testing.T) {
-			err := tt.umo.Unmarshal(tt.inputMessage, []byte(tt.inputText))
+			err := tt.umo.Unmarshal([]byte(tt.inputText), tt.inputMessage)
 			if err != nil && !tt.wantErr {
 				t.Errorf("Unmarshal() returned error: %v\n\n", err)
 			}
diff --git a/encoding/prototext/other_test.go b/encoding/prototext/other_test.go
index 4819f7d..8262099 100644
--- a/encoding/prototext/other_test.go
+++ b/encoding/prototext/other_test.go
@@ -226,7 +226,7 @@
 			}
 
 			gotMessage := new(pb2.KnownTypes)
-			err = prototext.UnmarshalOptions{Resolver: tt.resolver}.Unmarshal(gotMessage, b)
+			err = prototext.UnmarshalOptions{Resolver: tt.resolver}.Unmarshal(b, gotMessage)
 			if err != nil {
 				t.Errorf("Unmarshal() returned error: %v\n\n", err)
 			}
diff --git a/encoding/textpb/textpb.go b/encoding/textpb/textpb.go
index ba2c9ea..2c54d65 100644
--- a/encoding/textpb/textpb.go
+++ b/encoding/textpb/textpb.go
@@ -1,13 +1,17 @@
 // Package textpb is deprecated.
 package textpb
 
-import "google.golang.org/protobuf/encoding/prototext"
-
-var (
-	Marshal   = prototext.Marshal
-	Unmarshal = prototext.Unmarshal
+import (
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 )
 
+var Marshal = prototext.Marshal
+
+func Unmarshal(m proto.Message, b []byte) error {
+	return prototext.Unmarshal(b, m)
+}
+
 type (
 	MarshalOptions   = prototext.MarshalOptions
 	UnmarshalOptions = prototext.UnmarshalOptions
diff --git a/internal/cmd/conformance/main.go b/internal/cmd/conformance/main.go
index 5262376..ea54a82 100644
--- a/internal/cmd/conformance/main.go
+++ b/internal/cmd/conformance/main.go
@@ -71,7 +71,7 @@
 	case *pb.ConformanceRequest_JsonPayload:
 		err = protojson.UnmarshalOptions{
 			DiscardUnknown: req.TestCategory == pb.TestCategory_JSON_IGNORE_UNKNOWN_PARSING_TEST,
-		}.Unmarshal(msg, []byte(p.JsonPayload))
+		}.Unmarshal([]byte(p.JsonPayload), msg)
 	default:
 		return &pb.ConformanceResponse{
 			Result: &pb.ConformanceResponse_RuntimeError{