yugabyte-ycql-driver 3.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/README.md +242 -0
- data/ext/cassandra_murmur3/cassandra_murmur3.c +178 -0
- data/ext/cassandra_murmur3/extconf.rb +2 -0
- data/lib/cassandra/address_resolution.rb +36 -0
- data/lib/cassandra/address_resolution/policies.rb +2 -0
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
- data/lib/cassandra/address_resolution/policies/none.rb +35 -0
- data/lib/cassandra/aggregate.rb +123 -0
- data/lib/cassandra/argument.rb +51 -0
- data/lib/cassandra/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +100 -0
- data/lib/cassandra/auth/providers.rb +17 -0
- data/lib/cassandra/auth/providers/password.rb +65 -0
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +331 -0
- data/lib/cassandra/cluster/client.rb +1612 -0
- data/lib/cassandra/cluster/connection_pool.rb +78 -0
- data/lib/cassandra/cluster/connector.rb +372 -0
- data/lib/cassandra/cluster/control_connection.rb +962 -0
- data/lib/cassandra/cluster/failed_connection.rb +35 -0
- data/lib/cassandra/cluster/metadata.rb +142 -0
- data/lib/cassandra/cluster/options.rb +145 -0
- data/lib/cassandra/cluster/registry.rb +284 -0
- data/lib/cassandra/cluster/schema.rb +405 -0
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +112 -0
- data/lib/cassandra/cluster/schema/fetchers.rb +1627 -0
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +175 -0
- data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +45 -0
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
- data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +102 -0
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
- data/lib/cassandra/column.rb +66 -0
- data/lib/cassandra/column_container.rb +326 -0
- data/lib/cassandra/compression.rb +69 -0
- data/lib/cassandra/compression/compressors/lz4.rb +73 -0
- data/lib/cassandra/compression/compressors/snappy.rb +69 -0
- data/lib/cassandra/custom_data.rb +53 -0
- data/lib/cassandra/driver.rb +260 -0
- data/lib/cassandra/errors.rb +784 -0
- data/lib/cassandra/execution/info.rb +69 -0
- data/lib/cassandra/execution/options.rb +267 -0
- data/lib/cassandra/execution/profile.rb +153 -0
- data/lib/cassandra/execution/profile_manager.rb +71 -0
- data/lib/cassandra/execution/trace.rb +192 -0
- data/lib/cassandra/executors.rb +113 -0
- data/lib/cassandra/function.rb +156 -0
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +794 -0
- data/lib/cassandra/host.rb +102 -0
- data/lib/cassandra/index.rb +118 -0
- data/lib/cassandra/keyspace.rb +473 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing.rb +121 -0
- data/lib/cassandra/load_balancing/policies.rb +20 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +172 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +141 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +149 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +100 -0
- data/lib/cassandra/materialized_view.rb +92 -0
- data/lib/cassandra/null_logger.rb +56 -0
- data/lib/cassandra/protocol.rb +102 -0
- data/lib/cassandra/protocol/coder.rb +1085 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +418 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +448 -0
- data/lib/cassandra/protocol/request.rb +41 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +51 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +117 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +51 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +122 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +59 -0
- data/lib/cassandra/protocol/requests/query_request.rb +112 -0
- data/lib/cassandra/protocol/requests/register_request.rb +38 -0
- data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
- data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
- data/lib/cassandra/protocol/response.rb +28 -0
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +36 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +36 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +36 -0
- data/lib/cassandra/protocol/responses/error_response.rb +142 -0
- data/lib/cassandra/protocol/responses/event_response.rb +30 -0
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +52 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +62 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +59 -0
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +71 -0
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +61 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +43 -0
- data/lib/cassandra/protocol/responses/result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +39 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +73 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +70 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +37 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +36 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +33 -0
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +58 -0
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +48 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +34 -0
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +73 -0
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +63 -0
- data/lib/cassandra/protocol/v1.rb +326 -0
- data/lib/cassandra/protocol/v3.rb +358 -0
- data/lib/cassandra/protocol/v4.rb +478 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection/policies/constant.rb +46 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/result.rb +276 -0
- data/lib/cassandra/retry.rb +154 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry/policies/default.rb +53 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +73 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/session.rb +270 -0
- data/lib/cassandra/statement.rb +32 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/statements/batch.rb +146 -0
- data/lib/cassandra/statements/bound.rb +65 -0
- data/lib/cassandra/statements/prepared.rb +235 -0
- data/lib/cassandra/statements/simple.rb +118 -0
- data/lib/cassandra/statements/void.rb +38 -0
- data/lib/cassandra/table.rb +240 -0
- data/lib/cassandra/time.rb +103 -0
- data/lib/cassandra/time_uuid.rb +78 -0
- data/lib/cassandra/timestamp_generator.rb +37 -0
- data/lib/cassandra/timestamp_generator/simple.rb +38 -0
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
- data/lib/cassandra/trigger.rb +67 -0
- data/lib/cassandra/tuple.rb +131 -0
- data/lib/cassandra/types.rb +1704 -0
- data/lib/cassandra/udt.rb +443 -0
- data/lib/cassandra/util.rb +464 -0
- data/lib/cassandra/uuid.rb +110 -0
- data/lib/cassandra/uuid/generator.rb +212 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/datastax/cassandra.rb +47 -0
- data/lib/ycql.rb +842 -0
- metadata +243 -0
@@ -0,0 +1,478 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
# @private
|
22
|
+
module V4
|
23
|
+
class Encoder
|
24
|
+
HEADER_FORMAT = 'c2ncN'.freeze
|
25
|
+
|
26
|
+
def initialize(compressor, protocol_version)
|
27
|
+
@compressor = compressor
|
28
|
+
@protocol_version = protocol_version
|
29
|
+
end
|
30
|
+
|
31
|
+
def encode(buffer, request, stream_id)
|
32
|
+
flags = 0
|
33
|
+
flags |= 0x02 if request.trace?
|
34
|
+
flags |= 0x10 if @protocol_version == Cassandra::Protocol::Versions::BETA_VERSION
|
35
|
+
|
36
|
+
body = CqlByteBuffer.new
|
37
|
+
|
38
|
+
if request.payload?
|
39
|
+
flags |= 0x04
|
40
|
+
body.append_bytes_map(request.payload)
|
41
|
+
end
|
42
|
+
|
43
|
+
request.write(body, @protocol_version, self)
|
44
|
+
|
45
|
+
if @compressor && request.compressable? && @compressor.compress?(body)
|
46
|
+
flags |= 1
|
47
|
+
body = @compressor.compress(body)
|
48
|
+
end
|
49
|
+
|
50
|
+
header = [@protocol_version, flags, stream_id, request.opcode, body.bytesize]
|
51
|
+
buffer << header.pack(HEADER_FORMAT)
|
52
|
+
buffer << body
|
53
|
+
|
54
|
+
buffer
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_parameters(buffer, params, types, names = EMPTY_LIST)
|
58
|
+
Coder.write_values_v4(buffer, params, types, names)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Decoder
|
63
|
+
def initialize(handler, compressor = nil, custom_type_handlers = {})
|
64
|
+
@handler = handler
|
65
|
+
@compressor = compressor
|
66
|
+
@state = :initial
|
67
|
+
@header = nil
|
68
|
+
@version = nil
|
69
|
+
@code = nil
|
70
|
+
@length = nil
|
71
|
+
@buffer = CqlByteBuffer.new
|
72
|
+
@custom_type_handlers = custom_type_handlers
|
73
|
+
end
|
74
|
+
|
75
|
+
def <<(data)
|
76
|
+
@buffer << data
|
77
|
+
|
78
|
+
__send__(:"decode_#{@state}", @buffer)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
READY = ReadyResponse.new
|
84
|
+
|
85
|
+
def decode_initial(buffer)
|
86
|
+
return if buffer.length < 9
|
87
|
+
|
88
|
+
frame_header = buffer.read_int
|
89
|
+
protocol_version = (frame_header >> 24) & 0x7f
|
90
|
+
|
91
|
+
if protocol_version < 3
|
92
|
+
stream_id = (frame_header >> 8) & 0xff
|
93
|
+
stream_id = (stream_id & 0x7f) - (stream_id & 0x80)
|
94
|
+
|
95
|
+
error_response = ErrorResponse.new(nil, nil, 0x000A,
|
96
|
+
'Invalid or unsupported protocol version')
|
97
|
+
@handler.complete_request(stream_id, error_response)
|
98
|
+
|
99
|
+
return
|
100
|
+
end
|
101
|
+
|
102
|
+
@header = frame_header
|
103
|
+
@code = buffer.read_byte
|
104
|
+
@length = buffer.read_int
|
105
|
+
@state = :body
|
106
|
+
|
107
|
+
decode_body(buffer)
|
108
|
+
end
|
109
|
+
|
110
|
+
def decode_header(buffer)
|
111
|
+
buffer_length = buffer.length
|
112
|
+
|
113
|
+
while buffer_length >= 9
|
114
|
+
frame_header = buffer.read_int
|
115
|
+
frame_code = buffer.read_byte
|
116
|
+
frame_length = buffer.read_int
|
117
|
+
|
118
|
+
if (buffer_length - 9) < frame_length
|
119
|
+
@header = frame_header
|
120
|
+
@code = frame_code
|
121
|
+
@length = frame_length
|
122
|
+
@state = :body
|
123
|
+
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
actual_decode(buffer, frame_header, frame_length, frame_code)
|
128
|
+
buffer_length = buffer.length
|
129
|
+
end
|
130
|
+
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
|
134
|
+
def decode_body(buffer)
|
135
|
+
frame_header = @header
|
136
|
+
frame_code = @code
|
137
|
+
frame_length = @length
|
138
|
+
buffer_length = buffer.length
|
139
|
+
|
140
|
+
until buffer_length < frame_length
|
141
|
+
actual_decode(buffer, frame_header, frame_length, frame_code)
|
142
|
+
buffer_length = buffer.length
|
143
|
+
|
144
|
+
if buffer_length < 9
|
145
|
+
@header = nil
|
146
|
+
@code = nil
|
147
|
+
@length = nil
|
148
|
+
@state = :header
|
149
|
+
|
150
|
+
return
|
151
|
+
end
|
152
|
+
|
153
|
+
frame_header = buffer.read_int
|
154
|
+
frame_code = buffer.read_byte
|
155
|
+
frame_length = buffer.read_int
|
156
|
+
buffer_length -= 9
|
157
|
+
end
|
158
|
+
|
159
|
+
@header = frame_header
|
160
|
+
@code = frame_code
|
161
|
+
@length = frame_length
|
162
|
+
|
163
|
+
nil
|
164
|
+
end
|
165
|
+
|
166
|
+
def actual_decode(buffer, fields, frame_length, code)
|
167
|
+
protocol_version = (fields >> 24) & 0x7f
|
168
|
+
compression = ((fields >> 16) & 0x01) == 0x01
|
169
|
+
tracing = ((fields >> 16) & 0x02) == 0x02
|
170
|
+
payload = ((fields >> 16) & 0x04) == 0x04
|
171
|
+
warning = ((fields >> 16) & 0x08) == 0x08
|
172
|
+
stream_id = fields & 0xffff
|
173
|
+
stream_id = (stream_id & 0x7fff) - (stream_id & 0x8000)
|
174
|
+
opcode = code & 0xff
|
175
|
+
|
176
|
+
# If we're dealing with a compressed body, read the whole body, decompress,
|
177
|
+
# and treat the uncompressed body as if that's what we got in the first place.
|
178
|
+
# This means, reset frame_length to that uncompressed size.
|
179
|
+
if compression
|
180
|
+
if @compressor
|
181
|
+
buffer = CqlByteBuffer.new(
|
182
|
+
@compressor.decompress(buffer.read(frame_length))
|
183
|
+
)
|
184
|
+
frame_length = buffer.size
|
185
|
+
else
|
186
|
+
raise Errors::DecodingError,
|
187
|
+
'Compressed frame received, but no compressor configured'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# We want to read one full frame; but after we read/parse chunks of the body
|
192
|
+
# there may be more cruft left in the frame that we don't care about. So,
|
193
|
+
# we save off the current size of the buffer, do all our reads for the
|
194
|
+
# frame, get the final remaining size, and based on that discard possible
|
195
|
+
# remaining bytes in the frame. In particular, we account for the possibility
|
196
|
+
# that the buffer contains some/all of a subsequent frame as well, and we
|
197
|
+
# don't want to mess with that.
|
198
|
+
|
199
|
+
buffer_starting_length = buffer.length
|
200
|
+
|
201
|
+
trace_id = (buffer.read_uuid if tracing)
|
202
|
+
|
203
|
+
warnings = (buffer.read_string_list if warning)
|
204
|
+
|
205
|
+
custom_payload = (buffer.read_bytes_map.freeze if payload)
|
206
|
+
|
207
|
+
remaining_frame_length = frame_length -
|
208
|
+
(buffer_starting_length - buffer.length)
|
209
|
+
response = decode_response(opcode, protocol_version, buffer,
|
210
|
+
remaining_frame_length, trace_id, custom_payload,
|
211
|
+
warnings)
|
212
|
+
|
213
|
+
# Calculate and discard remaining cruft in the frame.
|
214
|
+
extra_length = frame_length - (buffer_starting_length - buffer.length)
|
215
|
+
buffer.discard(extra_length) if extra_length > 0
|
216
|
+
|
217
|
+
if stream_id == -1
|
218
|
+
@handler.notify_event_listeners(response)
|
219
|
+
else
|
220
|
+
@handler.complete_request(stream_id, response)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def decode_response(opcode,
|
225
|
+
protocol_version,
|
226
|
+
buffer,
|
227
|
+
size,
|
228
|
+
trace_id,
|
229
|
+
custom_payload,
|
230
|
+
warnings)
|
231
|
+
case opcode
|
232
|
+
when 0x00 # ERROR
|
233
|
+
code = buffer.read_int
|
234
|
+
message = buffer.read_string
|
235
|
+
|
236
|
+
case code
|
237
|
+
when 0x1000
|
238
|
+
UnavailableErrorResponse.new(custom_payload,
|
239
|
+
warnings,
|
240
|
+
code,
|
241
|
+
message,
|
242
|
+
buffer.read_consistency,
|
243
|
+
buffer.read_int,
|
244
|
+
buffer.read_int)
|
245
|
+
when 0x1100
|
246
|
+
WriteTimeoutErrorResponse.new(custom_payload,
|
247
|
+
warnings,
|
248
|
+
code,
|
249
|
+
message,
|
250
|
+
buffer.read_consistency,
|
251
|
+
buffer.read_int,
|
252
|
+
buffer.read_int,
|
253
|
+
buffer.read_string)
|
254
|
+
when 0x1200
|
255
|
+
ReadTimeoutErrorResponse.new(custom_payload,
|
256
|
+
warnings,
|
257
|
+
code,
|
258
|
+
message,
|
259
|
+
buffer.read_consistency,
|
260
|
+
buffer.read_int,
|
261
|
+
buffer.read_int,
|
262
|
+
(buffer.read_byte != 0))
|
263
|
+
when 0x1300
|
264
|
+
cl = buffer.read_consistency
|
265
|
+
received = buffer.read_int
|
266
|
+
block_for = buffer.read_int
|
267
|
+
if protocol_version < 5
|
268
|
+
ReadFailureErrorResponse.new(custom_payload,
|
269
|
+
warnings,
|
270
|
+
code,
|
271
|
+
message,
|
272
|
+
cl,
|
273
|
+
received,
|
274
|
+
block_for,
|
275
|
+
buffer.read_int,
|
276
|
+
(buffer.read_byte != 0),
|
277
|
+
nil)
|
278
|
+
else
|
279
|
+
failures_by_node = buffer.read_reason_map
|
280
|
+
ReadFailureErrorResponse.new(custom_payload,
|
281
|
+
warnings,
|
282
|
+
code,
|
283
|
+
message,
|
284
|
+
cl,
|
285
|
+
received,
|
286
|
+
block_for,
|
287
|
+
nil,
|
288
|
+
(buffer.read_byte != 0),
|
289
|
+
failures_by_node)
|
290
|
+
end
|
291
|
+
when 0x1400
|
292
|
+
FunctionFailureErrorResponse.new(custom_payload,
|
293
|
+
warnings,
|
294
|
+
code,
|
295
|
+
message,
|
296
|
+
buffer.read_string,
|
297
|
+
buffer.read_string,
|
298
|
+
buffer.read_string_list)
|
299
|
+
when 0x1500
|
300
|
+
cl = buffer.read_consistency
|
301
|
+
received = buffer.read_int
|
302
|
+
block_for = buffer.read_int
|
303
|
+
if protocol_version < 5
|
304
|
+
WriteFailureErrorResponse.new(custom_payload,
|
305
|
+
warnings,
|
306
|
+
code,
|
307
|
+
message,
|
308
|
+
cl,
|
309
|
+
received,
|
310
|
+
block_for,
|
311
|
+
buffer.read_int,
|
312
|
+
buffer.read_string,
|
313
|
+
nil)
|
314
|
+
else
|
315
|
+
failures_by_node = buffer.read_reason_map
|
316
|
+
WriteFailureErrorResponse.new(custom_payload,
|
317
|
+
warnings,
|
318
|
+
code,
|
319
|
+
message,
|
320
|
+
cl,
|
321
|
+
received,
|
322
|
+
block_for,
|
323
|
+
nil,
|
324
|
+
buffer.read_string,
|
325
|
+
failures_by_node)
|
326
|
+
end
|
327
|
+
when 0x2400
|
328
|
+
AlreadyExistsErrorResponse.new(custom_payload,
|
329
|
+
warnings,
|
330
|
+
code,
|
331
|
+
message,
|
332
|
+
buffer.read_string,
|
333
|
+
buffer.read_string)
|
334
|
+
when 0x2500
|
335
|
+
UnpreparedErrorResponse.new(custom_payload,
|
336
|
+
warnings,
|
337
|
+
code,
|
338
|
+
message,
|
339
|
+
buffer.read_short_bytes)
|
340
|
+
else
|
341
|
+
ErrorResponse.new(custom_payload, warnings, code, message)
|
342
|
+
end
|
343
|
+
when 0x02 # READY
|
344
|
+
READY
|
345
|
+
when 0x03 # AUTHENTICATE
|
346
|
+
AuthenticateResponse.new(buffer.read_string)
|
347
|
+
when 0x06 # SUPPORTED
|
348
|
+
SupportedResponse.new(buffer.read_string_multimap)
|
349
|
+
when 0x08 # RESULT
|
350
|
+
result_type = buffer.read_int
|
351
|
+
case result_type
|
352
|
+
when 0x0001 # Void
|
353
|
+
VoidResultResponse.new(custom_payload, warnings, trace_id)
|
354
|
+
when 0x0002 # Rows
|
355
|
+
original_buffer_length = buffer.length
|
356
|
+
column_specs, paging_state = Coder.read_metadata_v4(buffer)
|
357
|
+
|
358
|
+
if column_specs.nil?
|
359
|
+
consumed_bytes = original_buffer_length - buffer.length
|
360
|
+
remaining_bytes =
|
361
|
+
CqlByteBuffer.new(buffer.read(size - consumed_bytes - 4))
|
362
|
+
RawRowsResultResponse.new(custom_payload,
|
363
|
+
warnings,
|
364
|
+
protocol_version,
|
365
|
+
remaining_bytes,
|
366
|
+
paging_state,
|
367
|
+
trace_id,
|
368
|
+
@custom_type_handlers)
|
369
|
+
else
|
370
|
+
RowsResultResponse.new(custom_payload,
|
371
|
+
warnings,
|
372
|
+
Coder.read_values_v4(buffer, column_specs, @custom_type_handlers),
|
373
|
+
column_specs,
|
374
|
+
paging_state,
|
375
|
+
trace_id)
|
376
|
+
end
|
377
|
+
when 0x0003 # SetKeyspace
|
378
|
+
SetKeyspaceResultResponse.new(custom_payload,
|
379
|
+
warnings,
|
380
|
+
buffer.read_string,
|
381
|
+
trace_id)
|
382
|
+
when 0x0004 # Prepared
|
383
|
+
id = buffer.read_short_bytes
|
384
|
+
pk_idx, params_metadata = Coder.read_prepared_metadata_v4(buffer)
|
385
|
+
result_metadata = Coder.read_metadata_v4(buffer).first
|
386
|
+
|
387
|
+
PreparedResultResponse.new(custom_payload,
|
388
|
+
warnings,
|
389
|
+
id,
|
390
|
+
params_metadata,
|
391
|
+
result_metadata,
|
392
|
+
pk_idx,
|
393
|
+
trace_id)
|
394
|
+
when 0x0005 # SchemaChange
|
395
|
+
change = buffer.read_string
|
396
|
+
target = buffer.read_string
|
397
|
+
name = nil
|
398
|
+
arguments = EMPTY_LIST
|
399
|
+
|
400
|
+
case target
|
401
|
+
when Protocol::Constants::SCHEMA_CHANGE_TARGET_KEYSPACE
|
402
|
+
keyspace = buffer.read_string
|
403
|
+
when Protocol::Constants::SCHEMA_CHANGE_TARGET_TABLE,
|
404
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT
|
405
|
+
keyspace = buffer.read_string
|
406
|
+
name = buffer.read_string
|
407
|
+
when Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
|
408
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
409
|
+
keyspace = buffer.read_string
|
410
|
+
name = buffer.read_string
|
411
|
+
arguments = buffer.read_string_list
|
412
|
+
else
|
413
|
+
raise Errors::DecodingError,
|
414
|
+
"Unsupported event target: #{target.inspect}"
|
415
|
+
end
|
416
|
+
|
417
|
+
SchemaChangeResultResponse.new(custom_payload,
|
418
|
+
warnings,
|
419
|
+
change,
|
420
|
+
keyspace,
|
421
|
+
name,
|
422
|
+
target,
|
423
|
+
arguments,
|
424
|
+
trace_id)
|
425
|
+
else
|
426
|
+
raise Errors::DecodingError,
|
427
|
+
"Unsupported result type: #{result_type.inspect}"
|
428
|
+
end
|
429
|
+
when 0x0C # EVENT
|
430
|
+
event_type = buffer.read_string
|
431
|
+
case event_type
|
432
|
+
when 'SCHEMA_CHANGE'
|
433
|
+
change = buffer.read_string
|
434
|
+
target = buffer.read_string
|
435
|
+
arguments = EMPTY_LIST
|
436
|
+
|
437
|
+
case target
|
438
|
+
when Protocol::Constants::SCHEMA_CHANGE_TARGET_KEYSPACE
|
439
|
+
keyspace = buffer.read_string
|
440
|
+
name = nil
|
441
|
+
when Protocol::Constants::SCHEMA_CHANGE_TARGET_TABLE,
|
442
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT,
|
443
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
|
444
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
445
|
+
keyspace = buffer.read_string
|
446
|
+
name = buffer.read_string
|
447
|
+
else
|
448
|
+
raise Errors::DecodingError,
|
449
|
+
"Unsupported event target: #{target.inspect}"
|
450
|
+
end
|
451
|
+
|
452
|
+
if target == Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION \
|
453
|
+
|| target == Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
454
|
+
arguments = buffer.read_string_list
|
455
|
+
end
|
456
|
+
|
457
|
+
SchemaChangeEventResponse.new(change, keyspace, name, target, arguments)
|
458
|
+
when 'STATUS_CHANGE'
|
459
|
+
StatusChangeEventResponse.new(buffer.read_string, *buffer.read_inet)
|
460
|
+
when 'TOPOLOGY_CHANGE'
|
461
|
+
TopologyChangeEventResponse.new(buffer.read_string, *buffer.read_inet)
|
462
|
+
else
|
463
|
+
raise Errors::DecodingError,
|
464
|
+
"Unsupported event type: #{event_type.inspect}"
|
465
|
+
end
|
466
|
+
when 0x0E # AUTH_CHALLENGE
|
467
|
+
AuthChallengeResponse.new(buffer.read_bytes)
|
468
|
+
when 0x10 # AUTH_SUCCESS
|
469
|
+
AuthSuccessResponse.new(buffer.read_bytes)
|
470
|
+
else
|
471
|
+
raise Errors::DecodingError,
|
472
|
+
"Unsupported response opcode: #{opcode.inspect}"
|
473
|
+
end
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|