-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_tools.go
86 lines (73 loc) · 1.85 KB
/
client_tools.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package tarantool
import (
"github.com/vmihailenco/msgpack"
)
// IntKey is utility type for passing integer key to Select*, Update* and Delete*
// It serializes to array with single integer element.
type IntKey struct {
I int
}
func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(1)
enc.EncodeInt(int64(k.I))
return nil
}
// UintKey is utility type for passing unsigned integer key to Select*, Update* and Delete*
// It serializes to array with single integer element.
type UintKey struct {
I uint
}
func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(1)
enc.EncodeUint(uint64(k.I))
return nil
}
// UintKey is utility type for passing string key to Select*, Update* and Delete*
// It serializes to array with single string element.
type StringKey struct {
S string
}
func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(1)
enc.EncodeString(k.S)
return nil
}
// IntIntKey is utility type for passing two integer keys to Select*, Update* and Delete*
// It serializes to array with two integer elements
type IntIntKey struct {
I1, I2 int
}
func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(2)
enc.EncodeInt(int64(k.I1))
enc.EncodeInt(int64(k.I2))
return nil
}
// Op - is update operation
type Op struct {
Op string
Field int
Arg interface{}
}
func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(3)
enc.EncodeString(o.Op)
enc.EncodeInt(int64(o.Field))
return enc.Encode(o.Arg)
}
type OpSplice struct {
Op string
Field int
Pos int
Len int
Replace string
}
func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeArrayLen(5)
enc.EncodeString(o.Op)
enc.EncodeInt(int64(o.Field))
enc.EncodeInt(int64(o.Pos))
enc.EncodeInt(int64(o.Len))
enc.EncodeString(o.Replace)
return nil
}