From 533b265d19a4195b301a386e153da6abbf4f4464 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 23 Dec 2024 21:17:32 +0300 Subject: [PATCH] add codec.RawMessage support Signed-off-by: Vasiliy Tolstov --- codec/codec.go | 6 ++++-- codec/frame.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/codec/codec.go b/codec/codec.go index 3929a51e..5f8cb66b 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -3,6 +3,8 @@ package codec import ( "errors" + + "gopkg.in/yaml.v3" ) var ( @@ -66,10 +68,10 @@ func (m *RawMessage) MarshalYAML() ([]byte, error) { } // UnmarshalYAML sets *m to a copy of data. -func (m *RawMessage) UnmarshalYAML(data []byte) error { +func (m *RawMessage) UnmarshalYAML(n *yaml.Node) error { if m == nil { return errors.New("RawMessage UnmarshalYAML on nil pointer") } - *m = append((*m)[0:0], data...) + *m = append((*m)[0:0], []byte(n.Value)...) return nil } diff --git a/codec/frame.go b/codec/frame.go index 9b7e064a..4bf0f138 100644 --- a/codec/frame.go +++ b/codec/frame.go @@ -1,5 +1,7 @@ package codec +import "gopkg.in/yaml.v3" + // Frame gives us the ability to define raw data to send over the pipes type Frame struct { Data []byte @@ -26,8 +28,9 @@ func (m *Frame) MarshalYAML() ([]byte, error) { } // UnmarshalYAML set frame data -func (m *Frame) UnmarshalYAML(data []byte) error { - return m.Unmarshal(data) +func (m *Frame) UnmarshalYAML(n *yaml.Node) error { + m.Data = []byte(n.Value) + return nil } // ProtoMessage noop func