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
diff --git a/proto/all_test.go b/proto/all_test.go
index 9f63d7c..c3b2378 100644
--- a/proto/all_test.go
+++ b/proto/all_test.go
@@ -1427,7 +1427,7 @@
}
}
-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 @@
}
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))
}
}
diff --git a/proto/decode.go b/proto/decode.go
index f84d465..9f2eb0f 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -296,20 +296,20 @@
// 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)