diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 22:58:38 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 22:58:38 +0200 |
| commit | f482480b6ee6971b4e436f9ce901b991fb269644 (patch) | |
| tree | 84d96a4e083ebb723a86e28a747fbfea64d36dd6 /kstore/codec.go | |
| parent | 016b10e33161ec3274cf4b4d34eb939a290a9243 (diff) | |
kstore: add atomic document storev0.10.0
Diffstat (limited to 'kstore/codec.go')
| -rw-r--r-- | kstore/codec.go | 36 |
1 files changed, 36 insertions, 0 deletions
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 +) |
