forked from tarantool/go-tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgpack.go
54 lines (41 loc) · 1.19 KB
/
msgpack.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
//go:build !go_tarantool_msgpack_v5
// +build !go_tarantool_msgpack_v5
package tarantool
import (
"io"
"gopkg.in/vmihailenco/msgpack.v2"
msgpcode "gopkg.in/vmihailenco/msgpack.v2/codes"
)
type encoder = msgpack.Encoder
type decoder = msgpack.Decoder
func newEncoder(w io.Writer) *encoder {
return msgpack.NewEncoder(w)
}
func newDecoder(r io.Reader) *decoder {
return msgpack.NewDecoder(r)
}
func encodeUint(e *encoder, v uint64) error {
return e.EncodeUint(uint(v))
}
func encodeInt(e *encoder, v int64) error {
return e.EncodeInt(int(v))
}
func msgpackIsUint(code byte) bool {
return code == msgpcode.Uint8 || code == msgpcode.Uint16 ||
code == msgpcode.Uint32 || code == msgpcode.Uint64 ||
msgpcode.IsFixedNum(code)
}
func msgpackIsMap(code byte) bool {
return code == msgpcode.Map16 || code == msgpcode.Map32 || msgpcode.IsFixedMap(code)
}
func msgpackIsArray(code byte) bool {
return code == msgpcode.Array16 || code == msgpcode.Array32 ||
msgpcode.IsFixedArray(code)
}
func msgpackIsString(code byte) bool {
return msgpcode.IsFixedString(code) || code == msgpcode.Str8 ||
code == msgpcode.Str16 || code == msgpcode.Str32
}
func init() {
msgpack.RegisterExt(errorExtID, &BoxError{})
}