-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new `csproto.Clone()` function and associated tests add `go.work*` to `.gitignore`
- Loading branch information
1 parent
17e64cd
commit 4b67217
Showing
8 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ dist/ | |
|
||
# editor-related files | ||
.vscode/ | ||
|
||
# Go workspace files | ||
go.work* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters