Class: Mongo::Protocol::Compressed
- Defined in:
- lib/mongo/protocol/compressed.rb
Overview
MongoDB Wire protocol Compressed message.
This is a bi-directional message that compresses another opcode.
Constant Summary collapse
- ZLIB_BYTE =
The byte signaling that the message has been compressed with Zlib.
2.chr.force_encoding(BSON::BINARY).freeze
- ZLIB =
The Zlib compressor identifier.
'zlib'.freeze
- COMPRESSOR_ID_MAP =
The compressor identifier to byte map.
{ ZLIB => ZLIB_BYTE }.freeze
Constants inherited from Message
Message::BATCH_SIZE, Message::COLLECTION, Message::LIMIT, Message::MAX_MESSAGE_SIZE, Message::ORDERED, Message::Q
Instance Attribute Summary
Attributes inherited from Message
Instance Method Summary collapse
-
#inflate! ⇒ Protocol::Message
Inflate an OP_COMRESSED message and return the original message.
-
#initialize(message, compressor, zlib_compression_level = nil) ⇒ Compressed
constructor
Creates a new OP_COMPRESSED message.
-
#replyable? ⇒ true, false
Whether the message expects a reply from the database.
Methods inherited from Message
#==, #compress!, deserialize, #hash, #number_returned, #serialize, #set_request_id
Constructor Details
#initialize(message, compressor, zlib_compression_level = nil) ⇒ Compressed
Creates a new OP_COMPRESSED message.
55 56 57 58 59 60 61 62 63 |
# File 'lib/mongo/protocol/compressed.rb', line 55 def initialize(, compressor, zlib_compression_level = nil) @original_message = @original_op_code = .op_code @uncompressed_size = 0 @compressor_id = COMPRESSOR_ID_MAP[compressor] @compressed_message = '' @zlib_compression_level = zlib_compression_level if zlib_compression_level && zlib_compression_level != -1 @request_id = .set_request_id end |
Instance Method Details
#inflate! ⇒ Protocol::Message
Inflate an OP_COMRESSED message and return the original message.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mongo/protocol/compressed.rb', line 73 def inflate! = Registry.get(@original_op_code).allocate = Zlib::Inflate.inflate(@compressed_message) buf = BSON::ByteBuffer.new() .send(:fields).each do |field| if field[:multi] Message.deserialize_array(, buf, field) else Message.deserialize_field(, buf, field) end end end |
#replyable? ⇒ true, false
Whether the message expects a reply from the database.
97 98 99 |
# File 'lib/mongo/protocol/compressed.rb', line 97 def replyable? @original_message.replyable? end |