From 186266359b7c818f54832495a8c23105fae13d89 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 23 Sep 2020 16:39:41 +0200 Subject: [PATCH] feat(encoding): Add json codec Signed-off-by: Mark Sagi-Kazar --- internal/encoding/json/codec.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 internal/encoding/json/codec.go diff --git a/internal/encoding/json/codec.go b/internal/encoding/json/codec.go new file mode 100644 index 0000000..dff9ec9 --- /dev/null +++ b/internal/encoding/json/codec.go @@ -0,0 +1,17 @@ +package json + +import ( + "encoding/json" +) + +// Codec implements the encoding.Encoder and encoding.Decoder interfaces for JSON encoding. +type Codec struct{} + +func (Codec) Encode(v interface{}) ([]byte, error) { + // TODO: expose prefix and indent in the Codec as setting? + return json.MarshalIndent(v, "", " ") +} + +func (Codec) Decode(b []byte, v interface{}) error { + return json.Unmarshal(b, v) +}