-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding.go
More file actions
45 lines (32 loc) · 822 Bytes
/
encoding.go
File metadata and controls
45 lines (32 loc) · 822 Bytes
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
package cache
import (
"encoding/json"
"github.com/vmihailenco/msgpack/v5"
)
type Marshaler interface {
Marshal(r *Response) ([]byte, error)
}
type Unmarshaler interface {
Unmarshal(b []byte, v *Response) error
}
// Interface that marshal/unmarshal `Response`
type Encoder interface {
Marshaler
Unmarshaler
}
type MsgpackEncoder struct{}
func (m *MsgpackEncoder) Marshal(r *Response) ([]byte, error) {
return msgpack.Marshal(r)
}
func (m *MsgpackEncoder) Unmarshal(b []byte, v *Response) error {
return msgpack.Unmarshal(b, v)
}
var _ Encoder = &MsgpackEncoder{}
type JSONEncoder struct{}
func (e *JSONEncoder) Marshal(r *Response) ([]byte, error) {
return json.Marshal(r)
}
func (e *JSONEncoder) Unmarshal(b []byte, v *Response) error {
return json.Unmarshal(b, v)
}
var _ Encoder = &JSONEncoder{}