Преглед изворни кода

goprotobuf: Rename UnmarshalAppend to UnmarshalMerge.

"Merge" is the term used in C++ (and other languages),
and "append" doesn't correctly capture the semantics for non-repeated fields.

R=rsc
CC=golang-dev
https://codereview.appspot.com/7103060
David Symonds пре 13 година
родитељ
комит
d4b52d086a
2 измењених фајлова са 11 додато и 11 уклоњено
  1. 6 6
      proto/all_test.go
  2. 5 5
      proto/decode.go

+ 6 - 6
proto/all_test.go

@@ -1427,7 +1427,7 @@ func TestUnmarshalFuzz(t *testing.T) {
 	}
 }
 
-func TestAppend(t *testing.T) {
+func TestMerge(t *testing.T) {
 	pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}}
 	data, err := Marshal(pb)
 	if err != nil {
@@ -1446,14 +1446,14 @@ func TestAppend(t *testing.T) {
 	}
 
 	pb2 := new(MessageList)
-	if err := UnmarshalAppend(data, pb2); err != nil {
-		t.Fatalf("first UnmarshalAppend: %v", err)
+	if err := UnmarshalMerge(data, pb2); err != nil {
+		t.Fatalf("first UnmarshalMerge: %v", err)
 	}
-	if err := UnmarshalAppend(data, pb2); err != nil {
-		t.Fatalf("second UnmarshalAppend: %v", err)
+	if err := UnmarshalMerge(data, pb2); err != nil {
+		t.Fatalf("second UnmarshalMerge: %v", err)
 	}
 	if len(pb2.Message) != 2 {
-		t.Errorf("two UnmarshalAppends produced %d Messages, want 2", len(pb2.Message))
+		t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message))
 	}
 }
 

+ 5 - 5
proto/decode.go

@@ -296,20 +296,20 @@ type Unmarshaler interface {
 // the data in buf, the results can be unpredictable.
 //
 // Unmarshal resets pb before starting to unmarshal, so any
-// existing data in pb is always removed. Use UnmarshalAppend
+// existing data in pb is always removed. Use UnmarshalMerge
 // to preserve and append to existing data.
 func Unmarshal(buf []byte, pb Message) error {
 	pb.Reset()
-	return UnmarshalAppend(buf, pb)
+	return UnmarshalMerge(buf, pb)
 }
 
-// UnmarshalAppend parses the protocol buffer representation in buf and
+// UnmarshalMerge parses the protocol buffer representation in buf and
 // writes the decoded result to pb.  If the struct underlying pb does not match
 // the data in buf, the results can be unpredictable.
 //
-// UnmarshalAppend preserves and appends to existing data in pb.
+// UnmarshalMerge merges into existing data in pb.
 // Most code should use Unmarshal instead.
-func UnmarshalAppend(buf []byte, pb Message) error {
+func UnmarshalMerge(buf []byte, pb Message) error {
 	// If the object can unmarshal itself, let it.
 	if u, ok := pb.(Unmarshaler); ok {
 		return u.Unmarshal(buf)