-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathencoding.go
61 lines (45 loc) · 1.2 KB
/
encoding.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package toml
import (
"io"
"github.com/BurntSushi/toml"
"github.com/pkg/errors"
"github.com/mickep76/encoding"
)
type tomlCodec struct{}
type tomlEncoder struct {
encoder *toml.Encoder
}
type tomlDecoder struct {
decoder io.Reader
}
func (c *tomlCodec) NewCodec() encoding.Codec {
return &tomlCodec{}
}
func (c *tomlCodec) SetIndent(indent string) error {
return errors.Wrap(encoding.ErrUnsupportedOption, "codec toml")
}
func (c *tomlCodec) SetMapString() error {
return errors.Wrap(encoding.ErrUnsupportedOption, "codec toml")
}
func (c *tomlCodec) NewEncoder(w io.Writer) (encoding.Encoder, error) {
return &tomlEncoder{encoder: toml.NewEncoder(w)}, nil
}
func (c *tomlCodec) Encode(v interface{}) ([]byte, error) {
return encoding.Encode(c, v)
}
func (e *tomlEncoder) Encode(v interface{}) error {
return e.encoder.Encode(v)
}
func (c *tomlCodec) NewDecoder(r io.Reader) (encoding.Decoder, error) {
return &tomlDecoder{decoder: r}, nil
}
func (c *tomlCodec) Decode(b []byte, v interface{}) error {
return encoding.Decode(c, b, v)
}
func (d *tomlDecoder) Decode(v interface{}) error {
_, err := toml.DecodeReader(d.decoder, v)
return err
}
func init() {
encoding.Register("toml", &tomlCodec{})
}