forked from tarantool/go-tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgpack_v5.go
58 lines (45 loc) · 1.3 KB
/
msgpack_v5.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
55
56
57
58
//go:build go_tarantool_msgpack_v5
// +build go_tarantool_msgpack_v5
package tarantool
import (
"io"
"github.com/vmihailenco/msgpack/v5"
"github.com/vmihailenco/msgpack/v5/msgpcode"
)
type encoder = msgpack.Encoder
type decoder = msgpack.Decoder
func newEncoder(w io.Writer) *encoder {
return msgpack.NewEncoder(w)
}
func newDecoder(r io.Reader) *decoder {
dec := msgpack.NewDecoder(r)
dec.SetMapDecoder(func(dec *msgpack.Decoder) (interface{}, error) {
return dec.DecodeUntypedMap()
})
return dec
}
func encodeUint(e *encoder, v uint64) error {
return e.EncodeUint(v)
}
func encodeInt(e *encoder, v int64) error {
return e.EncodeInt(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)(nil))
}