-
Notifications
You must be signed in to change notification settings - Fork 179
/
codec.go
46 lines (37 loc) · 1.01 KB
/
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
package encoding
import (
"io"
)
// Encodable is a type that defines a canonical encoding.
type Encodable interface {
Encode() []byte
}
// Marshaler marshals and unmarshals values to and from bytes.
type Marshaler interface {
// Marshaler marshals a value to bytes.
//
// This function returns an error if the value type is not supported by this marshaler.
Marshal(interface{}) ([]byte, error)
// Unmarshal unmarshals bytes to a value.
//
// This functions returns an error if the bytes do not fit the provided value type.
Unmarshal([]byte, interface{}) error
// MustMarshal marshals a value to bytes.
//
// This function panics if marshaling fails.
MustMarshal(interface{}) []byte
// MustUnmarshal unmarshals bytes to a value.
//
// This function panics if decoding fails.
MustUnmarshal([]byte, interface{})
}
type Encoder interface {
Encode(interface{}) error
}
type Decoder interface {
Decode(interface{}) error
}
type Codec interface {
NewEncoder(w io.Writer) Encoder
NewDecoder(r io.Reader) Decoder
}