summaryrefslogtreecommitdiff
path: root/vendor/github.com
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2020-05-09 14:32:13 +0200
committerSebastiaan van Stijn <github@gone.nl>2020-05-09 14:32:13 +0200
commit5ed85b0909fa639c546b2b038724fd069da2d3a3 (patch)
tree6e8033c8c115a7c7478e3c210b4017bf0a4173af /vendor/github.com
parent0fc914de5c9cf13cfa972dbc0ca8034dec7c971d (diff)
downloaddocker-5ed85b0909fa639c546b2b038724fd069da2d3a3.tar.gz
vendor: bump containerd/typeurl v1.0.1
full diff: https://github.com/containerd/typeurl/compare/b45ef1f1f737e10bd45b25b669df25f0da8b9ba0...v1.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'vendor/github.com')
-rw-r--r--vendor/github.com/containerd/typeurl/types.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/vendor/github.com/containerd/typeurl/types.go b/vendor/github.com/containerd/typeurl/types.go
index b70314fda0..e912fd630e 100644
--- a/vendor/github.com/containerd/typeurl/types.go
+++ b/vendor/github.com/containerd/typeurl/types.go
@@ -47,14 +47,14 @@ func Register(v interface{}, args ...string) {
defer mu.Unlock()
if et, ok := registry[t]; ok {
if et != p {
- panic(errors.Errorf("type registred with alternate path %q != %q", et, p))
+ panic(errors.Errorf("type registered with alternate path %q != %q", et, p))
}
return
}
registry[t] = p
}
-// TypeURL returns the type url for a registred type.
+// TypeURL returns the type url for a registered type.
func TypeURL(v interface{}) (string, error) {
mu.Lock()
u, ok := registry[tryDereference(v)]
@@ -120,16 +120,43 @@ func UnmarshalAny(any *types.Any) (interface{}, error) {
}
func UnmarshalByTypeURL(typeURL string, value []byte) (interface{}, error) {
+ return unmarshal(typeURL, value, nil)
+}
+
+func UnmarshalTo(any *types.Any, out interface{}) error {
+ return UnmarshalToByTypeURL(any.TypeUrl, any.Value, out)
+}
+
+func UnmarshalToByTypeURL(typeURL string, value []byte, out interface{}) error {
+ _, err := unmarshal(typeURL, value, out)
+ return err
+}
+
+func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) {
t, err := getTypeByUrl(typeURL)
if err != nil {
return nil, err
}
- v := reflect.New(t.t).Interface()
+
+ if v == nil {
+ v = reflect.New(t.t).Interface()
+ } else {
+ // Validate interface type provided by client
+ vURL, err := TypeURL(v)
+ if err != nil {
+ return nil, err
+ }
+ if typeURL != vURL {
+ return nil, errors.Errorf("can't unmarshal type %q to output %q", typeURL, vURL)
+ }
+ }
+
if t.isProto {
err = proto.Unmarshal(value, v.(proto.Message))
} else {
err = json.Unmarshal(value, v)
}
+
return v, err
}