add proto codec.Frame support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-03-05 22:09:04 +03:00
parent ffd9472309
commit 6212be1b3b
2 changed files with 20 additions and 3 deletions

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
}