forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdt_context.go
130 lines (112 loc) · 3.72 KB
/
cdt_context.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2014-2019 Aerospike, Inc.
//
// Portions may be licensed to Aerospike, Inc. under one or more contributor
// license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
package aerospike
const (
ctxTypeListIndex = 0x10
ctxTypeListRank = 0x11
ctxTypeListValue = 0x13
ctxTypeMapIndex = 0x20
ctxTypeMapRank = 0x21
ctxTypeMapKey = 0x22
ctxTypeMapValue = 0x23
)
// CDTContext defines Nested CDT context. Identifies the location of nested list/map to apply the operation.
// for the current level.
// An array of CTX identifies location of the list/map on multiple
// levels on nesting.
type CDTContext struct {
id int
value Value
}
func (ctx *CDTContext) pack(cmd BufferEx) (int, error) {
size := 0
sz, err := packAInt64(cmd, int64(ctx.id))
size += sz
if err != nil {
return size, err
}
sz, err = ctx.value.pack(cmd)
size += sz
return size, err
}
// cdtContextList is used in FilterExpression API
type cdtContextList []*CDTContext
func (ctxl cdtContextList) pack(cmd BufferEx) (int, error) {
size := 0
for i := range ctxl {
sz, err := ctxl[i].pack(cmd)
size += sz
if err != nil {
return size, err
}
}
return size, nil
}
// CtxListIndex defines Lookup list by index offset.
// If the index is negative, the resolved index starts backwards from end of list.
// If an index is out of bounds, a parameter error will be returned.
// Examples:
// 0: First item.
// 4: Fifth item.
// -1: Last item.
// -3: Third to last item.
func CtxListIndex(index int) *CDTContext {
return &CDTContext{ctxTypeListIndex, IntegerValue(index)}
}
// CtxListIndexCreate list with given type at index offset, given an order and pad.
func CtxListIndexCreate(index int, order ListOrderType, pad bool) *CDTContext {
return &CDTContext{ctxTypeListIndex | cdtListOrderFlag(order, pad), IntegerValue(index)}
}
// CtxListRank defines Lookup list by rank.
// 0 = smallest value
// N = Nth smallest value
// -1 = largest value
func CtxListRank(rank int) *CDTContext {
return &CDTContext{ctxTypeListRank, IntegerValue(rank)}
}
// CtxListValue defines Lookup list by value.
func CtxListValue(key Value) *CDTContext {
return &CDTContext{ctxTypeListValue, key}
}
// CtxMapIndex defines Lookup map by index offset.
// If the index is negative, the resolved index starts backwards from end of list.
// If an index is out of bounds, a parameter error will be returned.
// Examples:
// 0: First item.
// 4: Fifth item.
// -1: Last item.
// -3: Third to last item.
func CtxMapIndex(index int) *CDTContext {
return &CDTContext{ctxTypeMapIndex, IntegerValue(index)}
}
// CtxMapRank defines Lookup map by rank.
// 0 = smallest value
// N = Nth smallest value
// -1 = largest value
func CtxMapRank(rank int) *CDTContext {
return &CDTContext{ctxTypeMapRank, IntegerValue(rank)}
}
// CtxMapKey defines Lookup map by key.
func CtxMapKey(key Value) *CDTContext {
return &CDTContext{ctxTypeMapKey, key}
}
// CtxMapKeyCreate creates map with given type at map key.
func CtxMapKeyCreate(key Value, order mapOrderType) *CDTContext {
return &CDTContext{ctxTypeMapKey | order.flag, key}
}
// CtxMapValue defines Lookup map by value.
func CtxMapValue(key Value) *CDTContext {
return &CDTContext{ctxTypeMapValue, key}
}