From f482480b6ee6971b4e436f9ce901b991fb269644 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 5 Aug 2026 22:58:38 +0200 Subject: kstore: add atomic document store --- kstore/codec.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 kstore/codec.go (limited to 'kstore/codec.go') diff --git a/kstore/codec.go b/kstore/codec.go new file mode 100644 index 0000000..6a1568f --- /dev/null +++ b/kstore/codec.go @@ -0,0 +1,36 @@ +package kstore + +import ( + "encoding/json" + + "gopkg.in/yaml.v3" +) + +// JSONCodec encodes documents as indented JSON. +type JSONCodec struct{} + +func (JSONCodec) Marshal(value any) ([]byte, error) { + return json.MarshalIndent(value, "", " ") +} + +func (JSONCodec) Unmarshal(data []byte, value any) error { + return json.Unmarshal(data, value) +} + +// YAMLCodec encodes documents as YAML. +type YAMLCodec struct{} + +func (YAMLCodec) Marshal(value any) ([]byte, error) { + return yaml.Marshal(value) +} + +func (YAMLCodec) Unmarshal(data []byte, value any) error { + return yaml.Unmarshal(data, value) +} + +var ( + // JSON is the default JSON codec. + JSON JSONCodec + // YAML is the default YAML codec. + YAML YAMLCodec +) -- cgit v1.3