aerospike 2.11.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/README.md +1 -1
  4. data/lib/aerospike.rb +17 -4
  5. data/lib/aerospike/aerospike_exception.rb +7 -1
  6. data/lib/aerospike/atomic/atomic.rb +1 -1
  7. data/lib/aerospike/bin.rb +1 -1
  8. data/lib/aerospike/cdt/bit_operation.rb +376 -0
  9. data/lib/aerospike/cdt/bit_overflow_action.rb +46 -0
  10. data/lib/aerospike/cdt/bit_policy.rb +36 -0
  11. data/lib/aerospike/cdt/bit_resize_flags.rb +44 -0
  12. data/lib/aerospike/cdt/bit_write_flags.rb +51 -0
  13. data/lib/aerospike/cdt/context.rb +101 -0
  14. data/lib/aerospike/cdt/hll_operation.rb +200 -0
  15. data/lib/aerospike/cdt/hll_policy.rb +34 -0
  16. data/lib/aerospike/cdt/hll_write_flags.rb +53 -0
  17. data/lib/aerospike/cdt/list_operation.rb +127 -97
  18. data/lib/aerospike/cdt/list_sort_flags.rb +10 -2
  19. data/lib/aerospike/cdt/map_operation.rb +154 -93
  20. data/lib/aerospike/cdt/map_order.rb +1 -1
  21. data/lib/aerospike/cdt/map_policy.rb +1 -1
  22. data/lib/aerospike/cdt/map_return_type.rb +1 -1
  23. data/lib/aerospike/cdt/map_write_mode.rb +1 -1
  24. data/lib/aerospike/client.rb +33 -17
  25. data/lib/aerospike/cluster.rb +139 -17
  26. data/lib/aerospike/cluster/partition.rb +1 -1
  27. data/lib/aerospike/cluster/partition_parser.rb +169 -0
  28. data/lib/aerospike/cluster/rack_parser.rb +117 -0
  29. data/lib/aerospike/command/admin_command.rb +1 -1
  30. data/lib/aerospike/command/batch_direct_command.rb +2 -1
  31. data/lib/aerospike/command/batch_direct_exists_command.rb +1 -1
  32. data/lib/aerospike/command/batch_direct_node.rb +3 -3
  33. data/lib/aerospike/command/batch_index_command.rb +11 -2
  34. data/lib/aerospike/command/batch_index_node.rb +2 -2
  35. data/lib/aerospike/command/batch_item.rb +1 -1
  36. data/lib/aerospike/command/command.rb +168 -12
  37. data/lib/aerospike/command/delete_command.rb +21 -5
  38. data/lib/aerospike/command/execute_command.rb +1 -1
  39. data/lib/aerospike/command/exists_command.rb +21 -5
  40. data/lib/aerospike/command/field_type.rb +2 -1
  41. data/lib/aerospike/command/multi_command.rb +55 -5
  42. data/lib/aerospike/command/operate_command.rb +6 -1
  43. data/lib/aerospike/command/read_command.rb +63 -20
  44. data/lib/aerospike/command/read_header_command.rb +18 -6
  45. data/lib/aerospike/command/roles.rb +1 -1
  46. data/lib/aerospike/command/single_command.rb +9 -3
  47. data/lib/aerospike/command/touch_command.rb +48 -4
  48. data/lib/aerospike/command/unsupported_particle_type_validator.rb +1 -1
  49. data/lib/aerospike/command/write_command.rb +13 -4
  50. data/lib/aerospike/connection/create.rb +1 -1
  51. data/lib/aerospike/features.rb +6 -1
  52. data/lib/aerospike/geo_json.rb +1 -1
  53. data/lib/aerospike/host.rb +1 -1
  54. data/lib/aerospike/info.rb +1 -1
  55. data/lib/aerospike/key.rb +1 -1
  56. data/lib/aerospike/language.rb +1 -1
  57. data/lib/aerospike/node.rb +21 -7
  58. data/lib/aerospike/node/rebalance.rb +50 -0
  59. data/lib/aerospike/node/refresh/info.rb +4 -1
  60. data/lib/aerospike/node/refresh/partitions.rb +6 -15
  61. data/lib/aerospike/node/refresh/racks.rb +47 -0
  62. data/lib/aerospike/node/refresh/reset.rb +1 -0
  63. data/lib/aerospike/node/verify/rebalance_generation.rb +43 -0
  64. data/lib/aerospike/node_validator.rb +4 -19
  65. data/lib/aerospike/operation.rb +13 -3
  66. data/lib/aerospike/policy/admin_policy.rb +1 -1
  67. data/lib/aerospike/policy/batch_policy.rb +1 -1
  68. data/lib/aerospike/policy/client_policy.rb +16 -1
  69. data/lib/aerospike/policy/commit_level.rb +1 -1
  70. data/lib/aerospike/policy/consistency_level.rb +1 -1
  71. data/lib/aerospike/policy/generation_policy.rb +1 -1
  72. data/lib/aerospike/policy/operate_policy.rb +1 -1
  73. data/lib/aerospike/policy/policy.rb +64 -2
  74. data/lib/aerospike/policy/priority.rb +1 -1
  75. data/lib/aerospike/policy/query_policy.rb +8 -1
  76. data/lib/aerospike/policy/record_bin_multiplicity.rb +1 -1
  77. data/lib/aerospike/policy/record_exists_action.rb +1 -1
  78. data/lib/aerospike/policy/replica.rb +45 -0
  79. data/lib/aerospike/policy/scan_policy.rb +8 -1
  80. data/lib/aerospike/policy/write_policy.rb +1 -1
  81. data/lib/aerospike/query/filter.rb +1 -1
  82. data/lib/aerospike/query/query_command.rb +16 -5
  83. data/lib/aerospike/query/recordset.rb +1 -1
  84. data/lib/aerospike/query/scan_command.rb +1 -1
  85. data/lib/aerospike/query/statement.rb +9 -2
  86. data/lib/aerospike/query/stream_command.rb +1 -1
  87. data/lib/aerospike/record.rb +1 -1
  88. data/lib/aerospike/result_code.rb +26 -7
  89. data/lib/aerospike/socket/base.rb +4 -3
  90. data/lib/aerospike/task/execute_task.rb +1 -1
  91. data/lib/aerospike/task/index_task.rb +1 -1
  92. data/lib/aerospike/task/task.rb +1 -1
  93. data/lib/aerospike/task/udf_register_task.rb +1 -1
  94. data/lib/aerospike/task/udf_remove_task.rb +1 -1
  95. data/lib/aerospike/ttl.rb +1 -1
  96. data/lib/aerospike/udf.rb +1 -1
  97. data/lib/aerospike/user_role.rb +1 -1
  98. data/lib/aerospike/utils/buffer.rb +14 -4
  99. data/lib/aerospike/utils/packer.rb +1 -1
  100. data/lib/aerospike/utils/pool.rb +1 -1
  101. data/lib/aerospike/utils/unpacker.rb +1 -1
  102. data/lib/aerospike/value/particle_type.rb +2 -2
  103. data/lib/aerospike/value/value.rb +165 -33
  104. data/lib/aerospike/version.rb +1 -1
  105. metadata +20 -8
  106. data/lib/aerospike/cluster/partition_tokenizer_new.rb +0 -130
  107. data/lib/aerospike/cluster/partition_tokenizer_old.rb +0 -135
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02e8ccb3f64b4605bc10b58af760e35373209b7323b2c06cc04f133dd12c4b7d
4
- data.tar.gz: 2b396aec824a2057daef8a6bd054c00bb103e2afd32f2d4c30de6e97853997f3
3
+ metadata.gz: 71a4730468bf7f38257303515a01945e1221d25f98b35f28d7aa9c0d74e06e3b
4
+ data.tar.gz: 1bf1fd2c18697d5e7adda3cc5df5b5fdea7ecd2c7f6c81950c7a4f9dbba06ead
5
5
  SHA512:
6
- metadata.gz: 6eb54355ef98807e3523c93bce1b5c2b440a1340387d351da5fb310f11c513d69622f60e309129ac4ea8897d26f5f3bf38362b3c6995a8241d023e383e17a887
7
- data.tar.gz: 217f6f2a2a0b782d0309e7a487416bf47be2e9225dce5899d1d9e54b2b7578a26e9e0535d9ce5dc1a53bf3b1be87c865218482a59ba4e216a68803328c7608ba
6
+ metadata.gz: 4aeaddd24ad85bc4178973cfe865410536b8aaa2030486715d1495c380438a7e9b5980a36f953623f9da85b4f6ef497273797baad99e0e1af259faf1a6d64c6a
7
+ data.tar.gz: 899f9ff5ddf4be0085dd6783f382278948f9e466778590e939a8f097b91432745001c65b6bf7ed3494056296a1c80ce1bbba5a9a6473b982101a99c839ea1168
@@ -2,7 +2,56 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [Unreleased]
5
+ ## [2.16.0] - 2020-10-12
6
+
7
+ * **New Features**
8
+ * [CLIENT-1173], [CLIENT-1246] Support Nested CDT operations with Context.
9
+ * [CLIENT-1179], Support Bitwise operations.
10
+
11
+ * **Changes**
12
+ * `ListSortFlags` now has an `ASCENDING` option, with `DEFAULT` mapping to it.
13
+
14
+ ## [2.15.0] - 2020-10-05
15
+
16
+ * **New Features**
17
+ * [CLIENT-1254] Adds support for HyperLogLog.
18
+
19
+ * **Changes**
20
+ * `Client#operate` now uses `OperatePolicy` by default.
21
+
22
+ ## [2.14.0] - 2020-08-06
23
+
24
+ * **New Features**
25
+ * Adds support for rack-aware reads.
26
+ * Adds support for client-server compression.
27
+
28
+ * **Improvements**
29
+ * Adds support for `truncate-namespace` command.
30
+
31
+ ## [2.13.0] - 2020-07-17
32
+
33
+ * **New Features**
34
+ * Adds support for replica policies.
35
+
36
+ * **Improvements**
37
+ * Remove support for "old" partition tokenizer.
38
+ * Refactor how partition parser is initialized and called.
39
+ * Adds support for 'replicas' and remove the old partition table queries from the server.
40
+
41
+ ## [2.12.0] - 2019-04-21
42
+
43
+ * **New Features**
44
+ * Support for predicate expressions in all transaction.
45
+ * Support for `operation.delete` in `client#operate`.
46
+
47
+ * **Improvements**
48
+ * Optimize serialization for nested structures. Thanks to [@Kacper Madej](https://github.com/madejejej)! [[#94](https://github.com/aerospike/aerospike-client-ruby/pull/94)]
49
+ * Remove `Thread#abort_on_exception` from `batch_index_command`. Thanks to [@Kacper Madej](https://github.com/madejejej)! [[#94](https://github.com/aerospike/aerospike-client-ruby/pull/92)]
50
+ * Does not allow values other than Integer, Float, String, Symbol and nil to be used as keys in Maps.
51
+
52
+ * **Bug Fixes**
53
+ * Fixes tests that weren't using ENV variables for connections. This will allow the tests to be run on any server.
54
+
6
55
 
7
56
  ## [2.11.0] - 2019-05-17
8
57
 
data/README.md CHANGED
@@ -97,7 +97,7 @@ This library is packaged with a number of tests.
97
97
 
98
98
  To run all the test cases:
99
99
 
100
- $ bundle exec rspec
100
+ $ AEROSPIKE_HOSTS="<host:port>[,<hoist:port>]" AEROSPIKE_USER="<user>" AEROSPIKE_PASSWORD="<pass>" bundle exec rspec
101
101
 
102
102
  <a name="Examples"></a>
103
103
  ## Examples
@@ -1,4 +1,4 @@
1
- # Copyright 2014-2018 Aerospike, Inc.
1
+ # Copyright 2014-2020 Aerospike, Inc.
2
2
  #
3
3
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
4
4
  # license agreements.
@@ -22,6 +22,7 @@ require "timeout"
22
22
  require 'resolv'
23
23
  require 'msgpack'
24
24
  require 'bcrypt'
25
+ require 'zlib'
25
26
 
26
27
  require 'aerospike/atomic/atomic'
27
28
 
@@ -64,6 +65,7 @@ require 'aerospike/command/admin_command'
64
65
  require 'aerospike/command/unsupported_particle_type_validator'
65
66
  require 'aerospike/key'
66
67
  require 'aerospike/operation'
68
+ require 'aerospike/cdt/context'
67
69
  require 'aerospike/cdt/list_operation'
68
70
  require 'aerospike/cdt/list_order'
69
71
  require 'aerospike/cdt/list_return_type'
@@ -76,6 +78,14 @@ require 'aerospike/cdt/map_return_type'
76
78
  require 'aerospike/cdt/map_write_flags'
77
79
  require 'aerospike/cdt/map_write_mode'
78
80
  require 'aerospike/cdt/map_policy'
81
+ require 'aerospike/cdt/hll_operation'
82
+ require 'aerospike/cdt/hll_write_flags'
83
+ require 'aerospike/cdt/hll_policy'
84
+ require 'aerospike/cdt/bit_operation'
85
+ require 'aerospike/cdt/bit_overflow_action'
86
+ require 'aerospike/cdt/bit_resize_flags'
87
+ require 'aerospike/cdt/bit_write_flags'
88
+ require 'aerospike/cdt/bit_policy'
79
89
  require 'aerospike/geo_json'
80
90
  require 'aerospike/ttl'
81
91
 
@@ -101,22 +111,25 @@ require 'aerospike/connection/create'
101
111
 
102
112
  require 'aerospike/cluster'
103
113
  require 'aerospike/cluster/create_connection'
104
- require 'aerospike/cluster/partition'
105
114
  require 'aerospike/cluster/find_nodes_to_remove'
106
115
  require 'aerospike/cluster/find_node'
107
- require 'aerospike/cluster/partition_tokenizer_new'
108
- require 'aerospike/cluster/partition_tokenizer_old'
116
+ require 'aerospike/cluster/partition'
117
+ require 'aerospike/cluster/partition_parser'
118
+ require 'aerospike/cluster/rack_parser'
109
119
  require 'aerospike/node'
110
120
  require 'aerospike/node/generation'
121
+ require 'aerospike/node/rebalance'
111
122
  require 'aerospike/node/refresh/failed'
112
123
  require 'aerospike/node/refresh/friends'
113
124
  require 'aerospike/node/refresh/info'
114
125
  require 'aerospike/node/refresh/partitions'
126
+ require 'aerospike/node/refresh/racks'
115
127
  require 'aerospike/node/refresh/peers'
116
128
  require 'aerospike/node/refresh/reset'
117
129
  require 'aerospike/node/verify/cluster_name'
118
130
  require 'aerospike/node/verify/name'
119
131
  require 'aerospike/node/verify/partition_generation'
132
+ require 'aerospike/node/verify/rebalance_generation'
120
133
  require 'aerospike/node/verify/peers_generation'
121
134
  require 'aerospike/node_validator'
122
135
  require 'aerospike/peer'
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2018 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -90,5 +90,11 @@ module Aerospike
90
90
  super(ResultCode::COMMAND_REJECTED, msg)
91
91
  end
92
92
  end
93
+
94
+ class InvalidNamespace < Aerospike
95
+ def initialize(msg=nil)
96
+ super(ResultCode::INVALID_NAMESPACE, msg)
97
+ end
98
+ end
93
99
  end
94
100
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -0,0 +1,376 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2016-2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http:#www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ ##
24
+ # Bit operations. Create bit operations used by client operate command.
25
+ # Offset orientation is left-to-right. Negative offsets are supported.
26
+ # If the offset is negative, the offset starts backwards from end of the bitmap.
27
+ # If an offset is out of bounds, a parameter error will be returned.
28
+ #
29
+ # Nested CDT operations are supported by optional context arguments. Example:
30
+ # bin = [[0b00000001, 0b01000010],[0b01011010]]
31
+ # Resize first bitmap (in a list of bitmaps) to 3 bytes.
32
+ # BitOperation.resize("bin", 3, BitResizeFlags::DEFAULT, ctx: [Context.list_index(0)])
33
+ # bin result = [[0b00000001, 0b01000010, 0b00000000],[0b01011010]]
34
+ class BitOperation < Operation
35
+
36
+ RESIZE = 0
37
+ INSERT = 1
38
+ REMOVE = 2
39
+ SET = 3
40
+ OR = 4
41
+ XOR = 5
42
+ AND = 6
43
+ NOT = 7
44
+ LSHIFT = 8
45
+ RSHIFT = 9
46
+ ADD = 10
47
+ SUBTRACT = 11
48
+ SET_INT = 12
49
+ GET = 50
50
+ COUNT = 51
51
+ LSCAN = 52
52
+ RSCAN = 53
53
+ GET_INT = 54
54
+
55
+ INT_FLAGS_SIGNED = 1
56
+
57
+ attr_reader :bit_op, :arguments, :policy, :ctx
58
+
59
+ def initialize(op_type, bit_op, bin_name, *arguments, ctx: nil, policy: nil)
60
+ @op_type = op_type
61
+ @bin_name = bin_name
62
+ @bin_value = nil
63
+ @bit_op = bit_op
64
+ @ctx = ctx
65
+ @arguments = arguments
66
+ end
67
+
68
+
69
+ # BitResizeOp creates byte "resize" operation.
70
+ # Server resizes byte[] to byte_size according to resize_flags (See {@link BitResizeFlags}).
71
+ # Server does not return a value.
72
+ # Example:
73
+ # bin = [0b00000001, 0b01000010]
74
+ # byte_size = 4
75
+ # resize_flags = 0
76
+ # bin result = [0b00000001, 0b01000010, 0b00000000, 0b00000000]
77
+ def self.resize(bin_name, byte_size, resize_flags, ctx: nil, policy: BitPolicy::DEFAULT)
78
+ BitOperation.new(Operation::BIT_MODIFY, RESIZE, bin_name, byte_size, policy.flags, resize_flags, ctx: ctx, policy: policy)
79
+ end
80
+
81
+ # BitInsertOp creates byte "insert" operation.
82
+ # Server inserts value bytes into byte[] bin at byte_offset.
83
+ # Server does not return a value.
84
+ # Example:
85
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
86
+ # byte_offset = 1
87
+ # value = [0b11111111, 0b11000111]
88
+ # bin result = [0b00000001, 0b11111111, 0b11000111, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
89
+ def self.insert(bin_name, byte_offset, value, ctx: nil, policy: BitPolicy::DEFAULT)
90
+ BitOperation.new(Operation::BIT_MODIFY, INSERT, bin_name, byte_offset, value_to_bytes(value), policy.flags, ctx: ctx, policy: policy)
91
+ end
92
+
93
+ # BitRemoveOp creates byte "remove" operation.
94
+ # Server removes bytes from byte[] bin at byte_offset for byte_size.
95
+ # Server does not return a value.
96
+ # Example:
97
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
98
+ # byte_offset = 2
99
+ # byte_size = 3
100
+ # bin result = [0b00000001, 0b01000010]
101
+ def self.remove(bin_name, byte_offset, byte_size, ctx: nil, policy: BitPolicy::DEFAULT)
102
+ BitOperation.new(Operation::BIT_MODIFY, REMOVE, bin_name, byte_offset, byte_size, policy.flags, ctx: ctx, policy: policy)
103
+ end
104
+
105
+ # BitSetOp creates bit "set" operation.
106
+ # Server sets value on byte[] bin at bit_offset for bit_size.
107
+ # Server does not return a value.
108
+ # Example:
109
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
110
+ # bit_offset = 13
111
+ # bit_size = 3
112
+ # value = [0b11100000]
113
+ # bin result = [0b00000001, 0b01000111, 0b00000011, 0b00000100, 0b00000101]
114
+ def self.set(bin_name, bit_offset, bit_size, value, ctx: nil, policy: BitPolicy::DEFAULT)
115
+ BitOperation.new(Operation::BIT_MODIFY, SET, bin_name, bit_offset, bit_size, value_to_bytes(value), policy.flags, ctx: ctx, policy: policy)
116
+ end
117
+
118
+ # BitOrOp creates bit "or" operation.
119
+ # Server performs bitwise "or" on value and byte[] bin at bit_offset for bit_size.
120
+ # Server does not return a value.
121
+ # Example:
122
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
123
+ # bit_offset = 17
124
+ # bit_size = 6
125
+ # value = [0b10101000]
126
+ # bin result = [0b00000001, 0b01000010, 0b01010111, 0b00000100, 0b00000101]
127
+ def self.or(bin_name, bit_offset, bit_size, value, ctx: nil, policy: BitPolicy::DEFAULT)
128
+ BitOperation.new(Operation::BIT_MODIFY, OR, bin_name, bit_offset, bit_size, value_to_bytes(value), policy.flags, ctx: ctx, policy: policy)
129
+ end
130
+
131
+ # BitXorOp creates bit "exclusive or" operation.
132
+ # Server performs bitwise "xor" on value and byte[] bin at bit_offset for bit_size.
133
+ # Server does not return a value.
134
+ # Example:
135
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
136
+ # bit_offset = 17
137
+ # bit_size = 6
138
+ # value = [0b10101100]
139
+ # bin result = [0b00000001, 0b01000010, 0b01010101, 0b00000100, 0b00000101]
140
+ def self.xor(bin_name, bit_offset, bit_size, value, ctx: nil, policy: BitPolicy::DEFAULT)
141
+ BitOperation.new(Operation::BIT_MODIFY, XOR, bin_name, bit_offset, bit_size, value_to_bytes(value), policy.flags, ctx: ctx, policy: policy)
142
+ end
143
+
144
+ # BitAndOp creates bit "and" operation.
145
+ # Server performs bitwise "and" on value and byte[] bin at bit_offset for bit_size.
146
+ # Server does not return a value.
147
+ # Example:
148
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
149
+ # bit_offset = 23
150
+ # bit_size = 9
151
+ # value = [0b00111100, 0b10000000]
152
+ # bin result = [0b00000001, 0b01000010, 0b00000010, 0b00000000, 0b00000101]
153
+ def self.and(bin_name, bit_offset, bit_size, value, ctx: nil, policy: BitPolicy::DEFAULT)
154
+ BitOperation.new(Operation::BIT_MODIFY, AND, bin_name, bit_offset, bit_size, value_to_bytes(value), policy.flags, ctx: ctx, policy: policy)
155
+ end
156
+
157
+ # BitNotOp creates bit "not" operation.
158
+ # Server negates byte[] bin starting at bit_offset for bit_size.
159
+ # Server does not return a value.
160
+ # Example:
161
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
162
+ # bit_offset = 25
163
+ # bit_size = 6
164
+ # bin result = [0b00000001, 0b01000010, 0b00000011, 0b01111010, 0b00000101]
165
+ def self.not(bin_name, bit_offset, bit_size, ctx: nil, policy: BitPolicy::DEFAULT)
166
+ BitOperation.new(Operation::BIT_MODIFY, NOT, bin_name, bit_offset, bit_size, policy.flags, ctx: ctx, policy: policy)
167
+ end
168
+
169
+ # BitLShiftOp creates bit "left shift" operation.
170
+ # Server shifts left byte[] bin starting at bit_offset for bit_size.
171
+ # Server does not return a value.
172
+ # Example:
173
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
174
+ # bit_offset = 32
175
+ # bit_size = 8
176
+ # shift = 3
177
+ # bin result = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00101000]
178
+ def self.lshift(bin_name, bit_offset, bit_size, shift, ctx: nil, policy: BitPolicy::DEFAULT)
179
+ BitOperation.new(Operation::BIT_MODIFY, LSHIFT, bin_name, bit_offset, bit_size, shift, policy.flags, ctx: ctx, policy: policy)
180
+ end
181
+
182
+ # BitRShiftOp creates bit "right shift" operation.
183
+ # Server shifts right byte[] bin starting at bit_offset for bit_size.
184
+ # Server does not return a value.
185
+ # Example:
186
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
187
+ # bit_offset = 0
188
+ # bit_size = 9
189
+ # shift = 1
190
+ # bin result = [0b00000000, 0b11000010, 0b00000011, 0b00000100, 0b00000101]
191
+ def self.rshift(bin_name, bit_offset, bit_size, shift, ctx: nil, policy: BitPolicy::DEFAULT)
192
+ BitOperation.new(Operation::BIT_MODIFY, RSHIFT, bin_name, bit_offset, bit_size, shift, policy.flags, ctx: ctx, policy: policy)
193
+ end
194
+
195
+ # BitAddOp creates bit "add" operation.
196
+ # Server adds value to byte[] bin starting at bit_offset for bit_size. Bit_size must be <= 64.
197
+ # Signed indicates if bits should be treated as a signed number.
198
+ # If add overflows/underflows, {@link BitOverflowAction} is used.
199
+ # Server does not return a value.
200
+ # Example:
201
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
202
+ # bit_offset = 24
203
+ # bit_size = 16
204
+ # value = 128
205
+ # signed = false
206
+ # bin result = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b10000101]
207
+ def self.add(
208
+ bin_name,
209
+ bit_offset,
210
+ bit_size,
211
+ value,
212
+ signed,
213
+ action,
214
+ ctx: nil,
215
+ policy: BitPolicy::DEFAULT
216
+ )
217
+ actionFlags = action
218
+ actionFlags |= INT_FLAGS_SIGNED if signed
219
+
220
+ BitOperation.new(Operation::BIT_MODIFY, ADD, bin_name, bit_offset, bit_size, value, policy.flags, actionFlags, ctx: ctx, policy: policy)
221
+ end
222
+
223
+ # BitSubtractOp creates bit "subtract" operation.
224
+ # Server subtracts value from byte[] bin starting at bit_offset for bit_size. Bit_size must be <= 64.
225
+ # Signed indicates if bits should be treated as a signed number.
226
+ # If add overflows/underflows, {@link BitOverflowAction} is used.
227
+ # Server does not return a value.
228
+ # Example:
229
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
230
+ # bit_offset = 24
231
+ # bit_size = 16
232
+ # value = 128
233
+ # signed = false
234
+ # bin result = [0b00000001, 0b01000010, 0b00000011, 0b0000011, 0b10000101]
235
+ def self.subtract(
236
+ bin_name,
237
+ bit_offset,
238
+ bit_size,
239
+ value,
240
+ signed,
241
+ action,
242
+ ctx: nil,
243
+ policy: BitPolicy::DEFAULT
244
+ )
245
+ actionFlags = action
246
+ actionFlags |= INT_FLAGS_SIGNED if signed
247
+
248
+ BitOperation.new(Operation::BIT_MODIFY, SUBTRACT, bin_name, bit_offset, bit_size, value, policy.flags, actionFlags, ctx: ctx, policy: policy)
249
+ end
250
+
251
+ # BitSetIntOp creates bit "setInt" operation.
252
+ # Server sets value to byte[] bin starting at bit_offset for bit_size. Size must be <= 64.
253
+ # Server does not return a value.
254
+ # Example:
255
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
256
+ # bit_offset = 1
257
+ # bit_size = 8
258
+ # value = 127
259
+ # bin result = [0b00111111, 0b11000010, 0b00000011, 0b0000100, 0b00000101]
260
+ def self.set_int(bin_name, bit_offset, bit_size, value, ctx: nil, policy: BitPolicy::DEFAULT)
261
+ BitOperation.new(Operation::BIT_MODIFY, SET_INT, bin_name, bit_offset, bit_size, value, policy.flags, ctx: ctx, policy: policy)
262
+ end
263
+
264
+ # BitGetOp creates bit "get" operation.
265
+ # Server returns bits from byte[] bin starting at bit_offset for bit_size.
266
+ # Example:
267
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
268
+ # bit_offset = 9
269
+ # bit_size = 5
270
+ # returns [0b1000000]
271
+ def self.get(bin_name, bit_offset, bit_size, ctx: nil)
272
+ BitOperation.new(Operation::BIT_READ, GET, bin_name, bit_offset, bit_size, ctx: ctx)
273
+ end
274
+
275
+ # BitCountOp creates bit "count" operation.
276
+ # Server returns integer count of set bits from byte[] bin starting at bit_offset for bit_size.
277
+ # Example:
278
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
279
+ # bit_offset = 20
280
+ # bit_size = 4
281
+ # returns 2
282
+ def self.count(bin_name, bit_offset, bit_size, ctx: nil)
283
+ BitOperation.new(Operation::BIT_READ, COUNT, bin_name, bit_offset, bit_size, ctx: ctx)
284
+ end
285
+
286
+ # BitLScanOp creates bit "left scan" operation.
287
+ # Server returns integer bit offset of the first specified value bit in byte[] bin
288
+ # starting at bit_offset for bit_size.
289
+ # Example:
290
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
291
+ # bit_offset = 24
292
+ # bit_size = 8
293
+ # value = true
294
+ # returns 5
295
+ def self.lscan(bin_name, bit_offset, bit_size, value, ctx: nil)
296
+ BitOperation.new(Operation::BIT_READ, LSCAN, bin_name, bit_offset, bit_size, value && true, ctx: ctx)
297
+ end
298
+
299
+ # BitRScanOp creates bit "right scan" operation.
300
+ # Server returns integer bit offset of the last specified value bit in byte[] bin
301
+ # starting at bit_offset for bit_size.
302
+ # Example:
303
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
304
+ # bit_offset = 32
305
+ # bit_size = 8
306
+ # value = true
307
+ # returns 7
308
+ def self.rscan(bin_name, bit_offset, bit_size, value, ctx: nil)
309
+ BitOperation.new(Operation::BIT_READ, RSCAN, bin_name, bit_offset, bit_size, value && true, ctx: ctx)
310
+ end
311
+
312
+ # BitGetIntOp creates bit "get integer" operation.
313
+ # Server returns integer from byte[] bin starting at bit_offset for bit_size.
314
+ # Signed indicates if bits should be treated as a signed number.
315
+ # Example:
316
+ # bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]
317
+ # bit_offset = 8
318
+ # bit_size = 16
319
+ # signed = false
320
+ # returns 16899
321
+ def self.get_int(bin_name, bit_offset, bit_size, signed, ctx: nil)
322
+ if signed
323
+ BitOperation.new(Operation::BIT_READ, GET_INT, bin_name, bit_offset, bit_size, INT_FLAGS_SIGNED, ctx: ctx)
324
+ else
325
+ BitOperation.new(Operation::BIT_READ, GET_INT, bin_name, bit_offset, bit_size, ctx: ctx)
326
+ end
327
+ end
328
+
329
+ def bin_value
330
+ @bin_value ||= pack_bin_value
331
+ end
332
+
333
+ private
334
+
335
+ def self.value_to_bytes(value)
336
+ case value
337
+ when Integer
338
+ [value].pack('C*')
339
+ when Array
340
+ value.pack('C*')
341
+ when String
342
+ BytesValue.new(value)
343
+ when StringValue
344
+ BytesValue.new(value.get)
345
+ else
346
+ value
347
+ end
348
+ end
349
+
350
+ def pack_bin_value
351
+ bytes = nil
352
+ args = arguments.dup
353
+ Packer.use do |packer|
354
+ if @ctx != nil && @ctx.length > 0
355
+ packer.write_array_header(3)
356
+ Value.of(0xff).pack(packer)
357
+
358
+ packer.write_array_header(@ctx.length*2)
359
+ @ctx.each do |ctx|
360
+ Value.of(ctx.id).pack(packer)
361
+ Value.of(ctx.value, true).pack(packer)
362
+ end
363
+ end
364
+
365
+ packer.write_array_header(args.length+1)
366
+ Value.of(@bit_op, true).pack(packer)
367
+ args.each do |value|
368
+ Value.of(value, true).pack(packer)
369
+ end
370
+ bytes = packer.bytes
371
+ end
372
+ BytesValue.new(bytes)
373
+ end
374
+ end
375
+ end
376
+ end