Class: Cql::Protocol::Request
- Inherits:
-
Object
- Object
- Cql::Protocol::Request
- Includes:
- Encoding
- Defined in:
- lib/cql/protocol/request.rb
Direct Known Subclasses
CredentialsRequest, ExecuteRequest, OptionsRequest, PrepareRequest, QueryRequest, RegisterRequest, StartupRequest
Instance Attribute Summary collapse
-
#opcode ⇒ Object
readonly
Returns the value of attribute opcode.
Class Method Summary collapse
Instance Method Summary collapse
- #encode_frame(stream_id = 0, buffer = ByteBuffer.new) ⇒ Object
-
#initialize(opcode) ⇒ Request
constructor
A new instance of Request.
Methods included from Encoding
#write_bytes, #write_consistency, #write_decimal, #write_double, #write_float, #write_int, #write_long, #write_long_string, #write_short, #write_short_bytes, #write_string, #write_string_list, #write_string_map, #write_uuid, #write_varint
Constructor Details
#initialize(opcode) ⇒ Request
Returns a new instance of Request.
10 11 12 |
# File 'lib/cql/protocol/request.rb', line 10 def initialize(opcode) @opcode = opcode end |
Instance Attribute Details
#opcode ⇒ Object (readonly)
Returns the value of attribute opcode.
8 9 10 |
# File 'lib/cql/protocol/request.rb', line 8 def opcode @opcode end |
Class Method Details
.change_stream_id(new_stream_id, buffer, offset = 0) ⇒ Object
23 24 25 |
# File 'lib/cql/protocol/request.rb', line 23 def self.change_stream_id(new_stream_id, buffer, offset=0) buffer.update(offset + 2, new_stream_id.chr) end |
Instance Method Details
#encode_frame(stream_id = 0, buffer = ByteBuffer.new) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/cql/protocol/request.rb', line 14 def encode_frame(stream_id=0, buffer=ByteBuffer.new) raise InvalidStreamIdError, 'The stream ID must be between 0 and 127' unless 0 <= stream_id && stream_id < 128 offset = buffer.bytesize buffer << [1, 0, stream_id, opcode, 0].pack(Formats::HEADER_FORMAT) write(buffer) buffer.update(offset + 4, [(buffer.bytesize - offset - 8)].pack(Formats::INT_FORMAT)) buffer end |