Compare commits

...

4 Commits
v3.11.25 ... v3

Author SHA1 Message Date
vtolstov
6ed0b0e090 Apply Code Coverage Badge 2024-12-23 18:18:20 +00:00
533b265d19 add codec.RawMessage support
All checks were successful
test / test (push) Successful in 3m41s
coverage / build (push) Successful in 8m22s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-23 21:17:32 +03:00
1ace2631a4 Merge pull request 'codec: add yaml support' (#388) from codec-yaml into v3
Some checks failed
test / test (push) Failing after 13m17s
coverage / build (push) Failing after 13m26s
Reviewed-on: #388
2024-12-23 19:08:47 +03:00
3dd5ca68d1 codec: add yaml support
Some checks failed
lint / lint (pull_request) Successful in 1m38s
test / test (pull_request) Successful in 4m17s
coverage / build (pull_request) Failing after 8m42s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-23 19:08:21 +03:00
3 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,5 @@
# Micro # Micro
![Coverage](https://img.shields.io/badge/Coverage-44.9%25-yellow) ![Coverage](https://img.shields.io/badge/Coverage-45.1%25-yellow)
Micro is a standard library for microservices. Micro is a standard library for microservices.

View File

@ -3,6 +3,8 @@ package codec
import ( import (
"errors" "errors"
"gopkg.in/yaml.v3"
) )
var ( var (
@ -54,3 +56,22 @@ func (m *RawMessage) UnmarshalJSON(data []byte) error {
*m = append((*m)[0:0], data...) *m = append((*m)[0:0], data...)
return nil return nil
} }
// MarshalYAML returns m as the JSON encoding of m.
func (m *RawMessage) MarshalYAML() ([]byte, error) {
if m == nil {
return []byte("null"), nil
} else if len(*m) == 0 {
return []byte("null"), nil
}
return *m, nil
}
// UnmarshalYAML sets *m to a copy of data.
func (m *RawMessage) UnmarshalYAML(n *yaml.Node) error {
if m == nil {
return errors.New("RawMessage UnmarshalYAML on nil pointer")
}
*m = append((*m)[0:0], []byte(n.Value)...)
return nil
}

View File

@ -1,5 +1,7 @@
package codec package codec
import "gopkg.in/yaml.v3"
// Frame gives us the ability to define raw data to send over the pipes // Frame gives us the ability to define raw data to send over the pipes
type Frame struct { type Frame struct {
Data []byte Data []byte
@ -26,8 +28,9 @@ func (m *Frame) MarshalYAML() ([]byte, error) {
} }
// UnmarshalYAML set frame data // UnmarshalYAML set frame data
func (m *Frame) UnmarshalYAML(data []byte) error { func (m *Frame) UnmarshalYAML(n *yaml.Node) error {
return m.Unmarshal(data) m.Data = []byte(n.Value)
return nil
} }
// ProtoMessage noop func // ProtoMessage noop func