add proto codec.Frame support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-03-05 23:34:31 +03:00
parent c989853e18
commit 7a1037d54d
3 changed files with 156 additions and 3 deletions

12
toml.go
View File

@@ -6,6 +6,7 @@ import (
"io"
"github.com/BurntSushi/toml"
pb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v3/codec"
rutil "go.unistack.org/micro/v3/util/reflect"
)
@@ -34,7 +35,10 @@ func (c *tomlCodec) 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
}
@@ -61,7 +65,11 @@ func (c *tomlCodec) Unmarshal(d []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 = d
return nil
case *pb.Frame:
m.Data = d
return nil
}