From adb3922a87cd31a65d93b72f751c7b230cbfdcee Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 5 Mar 2023 23:48:42 +0300 Subject: [PATCH] add proto codec.Frame support Signed-off-by: Vasiliy Tolstov --- yaml.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/yaml.go b/yaml.go index fbf8684..1f7a375 100644 --- a/yaml.go +++ b/yaml.go @@ -4,9 +4,10 @@ package yaml // import "go.unistack.org/micro-codec-yaml/v3" import ( "io" - "sigs.k8s.io/yaml" + pb "go.unistack.org/micro-proto/v3/codec" "go.unistack.org/micro/v3/codec" rutil "go.unistack.org/micro/v3/util/reflect" + "sigs.k8s.io/yaml" ) type yamlCodec struct { @@ -32,7 +33,10 @@ func (c *yamlCodec) 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 } @@ -53,7 +57,11 @@ func (c *yamlCodec) 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 }