proto: import change from Google.
Add tests for merging a map field. When src contains a duplicate key,
its value message replaces (not merges with) the value message in dst.
diff --git a/proto/clone_test.go b/proto/clone_test.go
index 76720f1..f607ff4 100644
--- a/proto/clone_test.go
+++ b/proto/clone_test.go
@@ -195,6 +195,9 @@
NameMapping: map[int32]string{6: "Nigel"},
MsgMapping: map[int64]*pb.FloatingPoint{
0x4001: &pb.FloatingPoint{F: proto.Float64(2.0)},
+ 0x4002: &pb.FloatingPoint{
+ F: proto.Float64(2.0),
+ },
},
ByteMapping: map[bool][]byte{true: []byte("wowsa")},
},
@@ -203,6 +206,12 @@
6: "Bruce", // should be overwritten
7: "Andrew",
},
+ MsgMapping: map[int64]*pb.FloatingPoint{
+ 0x4002: &pb.FloatingPoint{
+ F: proto.Float64(3.0),
+ Exact: proto.Bool(true),
+ }, // the entire message should be overwritten
+ },
},
want: &pb.MessageWithMap{
NameMapping: map[int32]string{
@@ -211,6 +220,9 @@
},
MsgMapping: map[int64]*pb.FloatingPoint{
0x4001: &pb.FloatingPoint{F: proto.Float64(2.0)},
+ 0x4002: &pb.FloatingPoint{
+ F: proto.Float64(2.0),
+ },
},
ByteMapping: map[bool][]byte{true: []byte("wowsa")},
},
@@ -254,6 +266,27 @@
Union: &pb.Communique_Name{"Bobby Tables"},
},
},
+ {
+ src: &proto3pb.Message{
+ Terrain: map[string]*proto3pb.Nested{
+ "kay_a": &proto3pb.Nested{Cute: true}, // replace
+ "kay_b": &proto3pb.Nested{Bunny: "rabbit"}, // insert
+ },
+ },
+ dst: &proto3pb.Message{
+ Terrain: map[string]*proto3pb.Nested{
+ "kay_a": &proto3pb.Nested{Bunny: "lost"}, // replaced
+ "kay_c": &proto3pb.Nested{Bunny: "bunny"}, // keep
+ },
+ },
+ want: &proto3pb.Message{
+ Terrain: map[string]*proto3pb.Nested{
+ "kay_a": &proto3pb.Nested{Cute: true},
+ "kay_b": &proto3pb.Nested{Bunny: "rabbit"},
+ "kay_c": &proto3pb.Nested{Bunny: "bunny"},
+ },
+ },
+ },
}
func TestMerge(t *testing.T) {
diff --git a/proto/proto3_proto/proto3.proto b/proto/proto3_proto/proto3.proto
index 31509e4..3e9a1ab 100644
--- a/proto/proto3_proto/proto3.proto
+++ b/proto/proto3_proto/proto3.proto
@@ -66,6 +66,7 @@
message Nested {
string bunny = 1;
+ bool cute = 2;
}
message MessageWithMap {
diff --git a/proto/testdata/test.proto b/proto/testdata/test.proto
index f607113..2ce2960 100644
--- a/proto/testdata/test.proto
+++ b/proto/testdata/test.proto
@@ -488,6 +488,7 @@
message FloatingPoint {
required double f = 1;
+ optional bool exact = 2;
}
message MessageWithMap {