build(deps): bump github.com/containerd/typeurl/v2 from 2.2.2 to 2.2.3

Bumps [github.com/containerd/typeurl/v2](https://github.com/containerd/typeurl) from 2.2.2 to 2.2.3.
- [Release notes](https://github.com/containerd/typeurl/releases)
- [Commits](https://github.com/containerd/typeurl/compare/v2.2.2...v2.2.3)

Signed-off-by: Derek McGowan <derek@mcg.dev>

---
updated-dependencies:
- dependency-name: github.com/containerd/typeurl/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit 01c489141c37e27b71370ab26ab28347b17f4284)
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
dependabot[bot]
2024-11-11 23:34:14 +00:00
committed by Derek McGowan
parent e21cb92182
commit 389e781ea1
5 changed files with 24 additions and 22 deletions

View File

@@ -39,7 +39,7 @@ type handler interface {
Marshaller(interface{}) func() ([]byte, error)
Unmarshaller(interface{}) func([]byte) error
TypeURL(interface{}) string
GetType(url string) reflect.Type
GetType(url string) (reflect.Type, bool)
}
// Definitions of common error types used throughout typeurl.
@@ -240,7 +240,7 @@ func MarshalAnyToProto(from interface{}) (*anypb.Any, error) {
}
func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) {
t, err := getTypeByUrl(typeURL)
t, isProto, err := getTypeByUrl(typeURL)
if err != nil {
return nil, err
}
@@ -258,14 +258,16 @@ func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error)
}
}
pm, ok := v.(proto.Message)
if ok {
return v, proto.Unmarshal(value, pm)
}
if isProto {
pm, ok := v.(proto.Message)
if ok {
return v, proto.Unmarshal(value, pm)
}
for _, h := range handlers {
if unmarshal := h.Unmarshaller(v); unmarshal != nil {
return v, unmarshal(value)
for _, h := range handlers {
if unmarshal := h.Unmarshaller(v); unmarshal != nil {
return v, unmarshal(value)
}
}
}
@@ -273,12 +275,12 @@ func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error)
return v, json.Unmarshal(value, v)
}
func getTypeByUrl(url string) (reflect.Type, error) {
func getTypeByUrl(url string) (_ reflect.Type, isProto bool, _ error) {
mu.RLock()
for t, u := range registry {
if u == url {
mu.RUnlock()
return t, nil
return t, false, nil
}
}
mu.RUnlock()
@@ -286,15 +288,15 @@ func getTypeByUrl(url string) (reflect.Type, error) {
if err != nil {
if errors.Is(err, protoregistry.NotFound) {
for _, h := range handlers {
if t := h.GetType(url); t != nil {
return t, nil
if t, isProto := h.GetType(url); t != nil {
return t, isProto, nil
}
}
}
return nil, fmt.Errorf("type with url %s: %w", url, ErrNotFound)
return nil, false, fmt.Errorf("type with url %s: %w", url, ErrNotFound)
}
empty := mt.New().Interface()
return reflect.TypeOf(empty).Elem(), nil
return reflect.TypeOf(empty).Elem(), true, nil
}
func tryDereference(v interface{}) reflect.Type {

View File

@@ -59,10 +59,10 @@ func (gogoHandler) TypeURL(v interface{}) string {
return gogoproto.MessageName(pm)
}
func (gogoHandler) GetType(url string) reflect.Type {
func (gogoHandler) GetType(url string) (reflect.Type, bool) {
t := gogoproto.MessageType(url)
if t == nil {
return nil
return nil, false
}
return t.Elem()
return t.Elem(), true
}