forked from grafana-cold-storage/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgp.go
More file actions
76 lines (63 loc) · 1.24 KB
/
Copy pathmsgp.go
File metadata and controls
76 lines (63 loc) · 1.24 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package response
import (
"github.com/tinylib/msgp/msgp"
)
type Msgp struct {
code int
body msgp.Marshaler
buf []byte
}
func NewMsgp(code int, body msgp.Marshaler) *Msgp {
return &Msgp{
code: code,
body: body,
buf: BufferPool.Get(),
}
}
func (r *Msgp) Code() int {
return r.code
}
func (r *Msgp) Close() {
BufferPool.Put(r.buf)
}
func (r *Msgp) Body() ([]byte, error) {
var err error
r.buf, err = r.body.MarshalMsg(r.buf)
return r.buf, err
}
func (r *Msgp) Headers() (headers map[string]string) {
headers = map[string]string{"content-type": "application/msgpack"}
return headers
}
type MsgpArray struct {
code int
body []msgp.Marshaler
buf []byte
}
func NewMsgpArray(code int, body []msgp.Marshaler) *MsgpArray {
return &MsgpArray{
code: code,
body: body,
buf: BufferPool.Get(),
}
}
func (r *MsgpArray) Code() int {
return r.code
}
func (r *MsgpArray) Close() {
BufferPool.Put(r.buf)
}
func (r *MsgpArray) Body() ([]byte, error) {
var err error
for _, b := range r.body {
r.buf, err = b.MarshalMsg(r.buf)
if err != nil {
return r.buf, err
}
}
return r.buf, err
}
func (r *MsgpArray) Headers() (headers map[string]string) {
headers = map[string]string{"content-type": "application/msgpack"}
return headers
}