Class: Cassandra::Protocol::V3::Encoder
- Inherits:
-
Object
- Object
- Cassandra::Protocol::V3::Encoder
- Defined in:
- lib/cassandra/protocol/v3.rb
Constant Summary collapse
- HEADER_FORMAT =
'c2ncN'.freeze
Instance Method Summary collapse
- #encode(buffer, request, stream_id) ⇒ Object
-
#initialize(compressor = nil, protocol_version = 3) ⇒ Encoder
constructor
A new instance of Encoder.
- #write_parameters(buffer, params, types, names = EMPTY_LIST) ⇒ Object
Constructor Details
#initialize(compressor = nil, protocol_version = 3) ⇒ Encoder
Returns a new instance of Encoder.
25 26 27 28 |
# File 'lib/cassandra/protocol/v3.rb', line 25 def initialize(compressor = nil, protocol_version = 3) @compressor = compressor @protocol_version = protocol_version end |
Instance Method Details
#encode(buffer, request, stream_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cassandra/protocol/v3.rb', line 30 def encode(buffer, request, stream_id) flags = request.trace? ? 2 : 0 body = request.write(CqlByteBuffer.new, @protocol_version, self) if @compressor && request.compressable? && @compressor.compress?(body) flags |= 1 body = @compressor.compress(body) end header = [@protocol_version, flags, stream_id, request.opcode, body.bytesize] buffer << header.pack(HEADER_FORMAT) buffer << body buffer end |
#write_parameters(buffer, params, types, names = EMPTY_LIST) ⇒ Object
46 47 48 |
# File 'lib/cassandra/protocol/v3.rb', line 46 def write_parameters(buffer, params, types, names = EMPTY_LIST) Coder.write_values_v3(buffer, params, types, names) end |