-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
54 lines (42 loc) · 854 Bytes
/
codec.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
package yaml
import (
"bytes"
"io"
"github.com/mirango/framework"
"gopkg.in/yaml.v2"
)
type YAML struct{}
func New() *YAML {
return &YAML{}
}
func (YAML) Encode(v interface{}) ([]byte, error) {
return yaml.Marshal(v)
}
func (YAML) EncodeTo(w io.Writer, v interface{}) error {
b, err := yaml.Marshal(v)
if err != nil {
return err
}
_, err = w.Write(b)
return err
}
func (YAML) EncodingType() string {
return framework.MIME_YAML
}
func (YAML) Decode(data []byte, v interface{}) error {
return yaml.Unmarshal(data, v)
}
func (YAML) DecodeFrom(r io.Reader, v interface{}) error {
var buf bytes.Buffer
_, err := buf.ReadFrom(r)
if err != nil {
return err
}
return yaml.Unmarshal(buf.Bytes(), v)
}
func (YAML) DecodingType() string {
return framework.MIME_YAML
}
func (YAML) MIMEType() string {
return framework.MIME_YAML
}