File tree 2 files changed +16
-0
lines changed
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ func Clone(m Message) Message {
59
59
return dst .Interface ()
60
60
}
61
61
62
+ // CloneOf returns a deep copy of m. If the top-level message is invalid,
63
+ // it returns an invalid message as well.
64
+ func CloneOf [M Message ](m M ) M {
65
+ return Clone (m ).(M )
66
+ }
67
+
62
68
// mergeOptions provides a namespace for merge functions, and can be
63
69
// exported in the future if we add user-visible merge options.
64
70
type mergeOptions struct {}
Original file line number Diff line number Diff line change @@ -853,6 +853,16 @@ func TestClone(t *testing.T) {
853
853
}
854
854
}
855
855
856
+ func TestCloneOf (t * testing.T ) {
857
+ want := & testpb.TestAllTypes {
858
+ OptionalInt32 : proto .Int32 (1 ),
859
+ }
860
+ got := proto .CloneOf (want )
861
+ if ! proto .Equal (got , want ) {
862
+ t .Errorf ("Clone(src) != src:\n got %v\n want %v" , got , want )
863
+ }
864
+ }
865
+
856
866
// mutateValue changes a Value, returning a new value.
857
867
//
858
868
// For scalar values, it returns a value different from the input.
You can’t perform that action at this time.
0 commit comments