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

Reviewed-on: #100
This commit is contained in:
Василий Толстов 2023-03-05 22:20:27 +03:00
commit e0ae6cf5ff
2 changed files with 16 additions and 5 deletions

9
go.mod
View File

@ -1,10 +1,13 @@
module go.unistack.org/micro-codec-proto/v3 module go.unistack.org/micro-codec-proto/v3
go 1.16 go 1.19
require (
go.unistack.org/micro/v3 v3.10.14
google.golang.org/protobuf v1.28.1
)
require ( require (
github.com/google/go-cmp v0.5.7 // indirect 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 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.28.1
) )

View File

@ -4,6 +4,7 @@ package proto // import "go.unistack.org/micro-codec-proto/v3"
import ( import (
"io" "io"
pb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v3/codec" "go.unistack.org/micro/v3/codec"
rutil "go.unistack.org/micro/v3/util/reflect" rutil "go.unistack.org/micro/v3/util/reflect"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -33,7 +34,10 @@ func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error
v = nv 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 return m.Data, nil
} }
@ -58,7 +62,11 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er
v = nv 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 m.Data = d
return nil return nil
} }