From 3dd5ca68d1a3bfd92a182dd0e89198ad473038a1 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 23 Dec 2024 19:08:21 +0300 Subject: [PATCH] codec: add yaml support Signed-off-by: Vasiliy Tolstov --- codec/codec.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/codec/codec.go b/codec/codec.go index b850cf8f..3929a51e 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -54,3 +54,22 @@ func (m *RawMessage) UnmarshalJSON(data []byte) error { *m = append((*m)[0:0], data...) 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(data []byte) error { + if m == nil { + return errors.New("RawMessage UnmarshalYAML on nil pointer") + } + *m = append((*m)[0:0], data...) + return nil +} -- 2.45.2