-
Notifications
You must be signed in to change notification settings - Fork 13
/
clone.go
25 lines (23 loc) · 891 Bytes
/
clone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package csproto
import (
gogo "github.com/gogo/protobuf/proto"
google "github.com/golang/protobuf/proto" //nolint: staticcheck // we're using this deprecated package intentionally
googlev2 "google.golang.org/protobuf/proto"
)
// Clone returns a deep copy of m, delegating to the appropriate underlying Protobuf API based on
// the concrete type of m. Since the underlying runtimes return different types, this function returns
// interface{} and the caller will need to type-assert back to the concrete type of m.
//
// If m is not one of the supported message types, this function returns nil.
func Clone(m interface{}) interface{} {
switch MsgType(m) {
case MessageTypeGoogle:
return googlev2.Clone(m.(googlev2.Message))
case MessageTypeGoogleV1:
return google.Clone(m.(google.Message))
case MessageTypeGogo:
return gogo.Clone(m.(gogo.Message))
default:
return nil
}
}