Merge pull request 'add proto codec.Frame support' (#45) from proto-frame into v3

Reviewed-on: #45
This commit is contained in:
Василий Толстов 2023-03-05 22:09:54 +03:00
commit 0aee8591b6
2 changed files with 20 additions and 3 deletions

11
go.mod
View File

@ -1,8 +1,17 @@
module go.unistack.org/micro-codec-msgpack/v3
go 1.16
go 1.19
require (
github.com/vmihailenco/msgpack/v5 v5.3.5
go.unistack.org/micro-proto/v3 v3.3.1
go.unistack.org/micro/v3 v3.10.5
)
require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)

View File

@ -5,6 +5,7 @@ import (
"io"
"github.com/vmihailenco/msgpack/v5"
pb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v3/codec"
rutil "go.unistack.org/micro/v3/util/reflect"
)
@ -31,7 +32,10 @@ func (c *msgpackCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, err
v = nv
}
if m, ok := v.(*codec.Frame); ok {
switch m := v.(type) {
case *codec.Frame:
return m.Data, nil
case *pb.Frame:
return m.Data, nil
}
@ -52,7 +56,11 @@ func (c *msgpackCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option)
v = nv
}
if m, ok := v.(*codec.Frame); ok {
switch m := v.(type) {
case *codec.Frame:
m.Data = b
return nil
case *pb.Frame:
m.Data = b
return nil
}