From 0056cc94904c582ba8b52ebbc8e9861f43d8ba25 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 5 Mar 2023 22:20:00 +0300 Subject: [PATCH] add proto codec.Frame support Signed-off-by: Vasiliy Tolstov --- go.mod | 9 ++++++--- proto.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0142ae3..2c08176 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,13 @@ 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 ( 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 ) diff --git a/proto.go b/proto.go index 80094d1..5738fb2 100644 --- a/proto.go +++ b/proto.go @@ -4,6 +4,7 @@ package proto // import "go.unistack.org/micro-codec-proto/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" "google.golang.org/protobuf/proto" @@ -33,7 +34,10 @@ func (c *protoCodec) 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 } @@ -58,7 +62,11 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er 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 } -- 2.45.2