add proto codec.Frame support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-03-05 21:58:01 +03:00
parent 92a5a4ea20
commit 9fed45dd97
3 changed files with 159 additions and 4 deletions

12
json.go
View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"io"
pb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v3/codec"
rutil "go.unistack.org/micro/v3/util/reflect"
)
@@ -52,7 +53,10 @@ func (c *jsonCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
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
}
@@ -89,7 +93,11 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
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
}