blob: 6a1568f79a889c967a59dd2953a1129aa5fba3ad (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
)
|