16
16
*/
17
17
package aerospike
18
18
19
+ const (
20
+ ctxTypeListIndex = 0x10
21
+ ctxTypeListRank = 0x11
22
+ ctxTypeListValue = 0x13
23
+ ctxTypeMapIndex = 0x20
24
+ ctxTypeMapRank = 0x21
25
+ ctxTypeMapKey = 0x22
26
+ ctxTypeMapValue = 0x23
27
+ )
28
+
19
29
// CDTContext defines Nested CDT context. Identifies the location of nested list/map to apply the operation.
20
30
// for the current level.
21
31
// An array of CTX identifies location of the list/map on multiple
@@ -25,6 +35,36 @@ type CDTContext struct {
25
35
value Value
26
36
}
27
37
38
+ func (ctx * CDTContext ) pack (cmd BufferEx ) (int , error ) {
39
+ size := 0
40
+ sz , err := packAInt64 (cmd , int64 (ctx .id ))
41
+ size += sz
42
+ if err != nil {
43
+ return size , err
44
+ }
45
+
46
+ sz , err = ctx .value .pack (cmd )
47
+ size += sz
48
+
49
+ return size , err
50
+ }
51
+
52
+ // cdtContextList is used in FilterExpression API
53
+ type cdtContextList []* CDTContext
54
+
55
+ func (ctxl cdtContextList ) pack (cmd BufferEx ) (int , error ) {
56
+ size := 0
57
+ for i := range ctxl {
58
+ sz , err := ctxl [i ].pack (cmd )
59
+ size += sz
60
+ if err != nil {
61
+ return size , err
62
+ }
63
+ }
64
+
65
+ return size , nil
66
+ }
67
+
28
68
// CtxListIndex defines Lookup list by index offset.
29
69
// If the index is negative, the resolved index starts backwards from end of list.
30
70
// If an index is out of bounds, a parameter error will be returned.
@@ -34,25 +74,25 @@ type CDTContext struct {
34
74
// -1: Last item.
35
75
// -3: Third to last item.
36
76
func CtxListIndex (index int ) * CDTContext {
37
- return & CDTContext {0x10 , IntegerValue (index )}
77
+ return & CDTContext {ctxTypeListIndex , IntegerValue (index )}
38
78
}
39
79
40
80
// CtxListIndexCreate list with given type at index offset, given an order and pad.
41
81
func CtxListIndexCreate (index int , order ListOrderType , pad bool ) * CDTContext {
42
- return & CDTContext {0x10 | cdtListOrderFlag (order , pad ), IntegerValue (index )}
82
+ return & CDTContext {ctxTypeListIndex | cdtListOrderFlag (order , pad ), IntegerValue (index )}
43
83
}
44
84
45
85
// CtxListRank defines Lookup list by rank.
46
86
// 0 = smallest value
47
87
// N = Nth smallest value
48
88
// -1 = largest value
49
89
func CtxListRank (rank int ) * CDTContext {
50
- return & CDTContext {0x11 , IntegerValue (rank )}
90
+ return & CDTContext {ctxTypeListRank , IntegerValue (rank )}
51
91
}
52
92
53
93
// CtxListValue defines Lookup list by value.
54
94
func CtxListValue (key Value ) * CDTContext {
55
- return & CDTContext {0x13 , key }
95
+ return & CDTContext {ctxTypeListValue , key }
56
96
}
57
97
58
98
// CtxMapIndex defines Lookup map by index offset.
@@ -64,28 +104,28 @@ func CtxListValue(key Value) *CDTContext {
64
104
// -1: Last item.
65
105
// -3: Third to last item.
66
106
func CtxMapIndex (index int ) * CDTContext {
67
- return & CDTContext {0x20 , IntegerValue (index )}
107
+ return & CDTContext {ctxTypeMapIndex , IntegerValue (index )}
68
108
}
69
109
70
110
// CtxMapRank defines Lookup map by rank.
71
111
// 0 = smallest value
72
112
// N = Nth smallest value
73
113
// -1 = largest value
74
114
func CtxMapRank (rank int ) * CDTContext {
75
- return & CDTContext {0x21 , IntegerValue (rank )}
115
+ return & CDTContext {ctxTypeMapRank , IntegerValue (rank )}
76
116
}
77
117
78
118
// CtxMapKey defines Lookup map by key.
79
119
func CtxMapKey (key Value ) * CDTContext {
80
- return & CDTContext {0x22 , key }
120
+ return & CDTContext {ctxTypeMapKey , key }
81
121
}
82
122
83
123
// Create map with given type at map key.
84
124
func CtxMapKeyCreate (key Value , order mapOrderType ) * CDTContext {
85
- return & CDTContext {0x22 | order .flag , key }
125
+ return & CDTContext {ctxTypeMapKey | order .flag , key }
86
126
}
87
127
88
128
// CtxMapValue defines Lookup map by value.
89
129
func CtxMapValue (key Value ) * CDTContext {
90
- return & CDTContext {0x23 , key }
130
+ return & CDTContext {ctxTypeMapValue , key }
91
131
}
0 commit comments