add codec.RawMessage support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-12-23 21:01:38 +03:00
parent e0d6f2552c
commit 8f6b64794b
3 changed files with 29 additions and 1547 deletions

13
go.mod
View File

@ -1,10 +1,19 @@
module go.unistack.org/micro-codec-yaml/v3 module go.unistack.org/micro-codec-yaml/v3
go 1.16 go 1.22
toolchain go1.23.4
require ( require (
go.unistack.org/micro-proto/v3 v3.4.1 go.unistack.org/micro-proto/v3 v3.4.1
go.unistack.org/micro/v3 v3.10.94 go.unistack.org/micro/v3 v3.10.94
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

1553
go.sum

File diff suppressed because it is too large Load Diff

10
yaml.go
View File

@ -35,6 +35,10 @@ func (c *yamlCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
return m.Data, nil return m.Data, nil
case *pb.Frame: case *pb.Frame:
return m.Data, nil return m.Data, nil
case codec.RawMessage:
return []byte(m), nil
case *codec.RawMessage:
return []byte(*m), nil
} }
return yaml.Marshal(v) return yaml.Marshal(v)
@ -63,6 +67,12 @@ func (c *yamlCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
case *pb.Frame: case *pb.Frame:
m.Data = b m.Data = b
return nil return nil
case *codec.RawMessage:
*m = append((*m)[0:0], b...)
return nil
case codec.RawMessage:
copy(m, b)
return nil
} }
return yaml.Unmarshal(b, v) return yaml.Unmarshal(b, v)