add proto codec.Frame support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
7b50d918cd
commit
185449b5b0
9
go.mod
9
go.mod
@ -1,10 +1,13 @@
|
||||
module go.unistack.org/micro-codec-jsonpb/v3
|
||||
|
||||
go 1.16
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
go.unistack.org/micro/v3 v3.10.14
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.7 // indirect
|
||||
go.unistack.org/micro/v3 v3.10.14
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
12
jsonpb.go
12
jsonpb.go
@ -4,6 +4,7 @@ package jsonpb // import "go.unistack.org/micro-codec-jsonpb/v3"
|
||||
import (
|
||||
"io"
|
||||
|
||||
pb "go.unistack.org/micro-proto/v3/codec"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||
@ -46,7 +47,10 @@ func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, erro
|
||||
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
|
||||
}
|
||||
|
||||
@ -78,7 +82,11 @@ func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) e
|
||||
v = nv
|
||||
}
|
||||
|
||||
if m, ok := v.(*codec.Frame); ok {
|
||||
switch m := v.(type) {
|
||||
case *codec.Frame:
|
||||
m.Data = d
|
||||
return nil
|
||||
case *pb.Frame:
|
||||
m.Data = d
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user