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
-
#initialize(message, compressor, zlib_compression_level = nil) ⇒ Compressed
constructor
Creates a new OP_COMPRESSED message.
-
#maybe_inflate ⇒ Protocol::Message
private
Inflates an OP_COMRESSED message and returns the original message.
-
#replyable? ⇒ true, false
Whether the message expects a reply from the database.
Methods inherited from Message
#==, deserialize, #hash, #maybe_compress, #maybe_decrypt, #maybe_encrypt, #number_returned, #serialize, #set_request_id
Methods included from Id
Constructor Details
#initialize(message, compressor, zlib_compression_level = nil) ⇒ Compressed
Creates a new OP_COMPRESSED message.
53 54 55 56 57 58 59 60 61 |
# File 'lib/mongo/protocol/compressed.rb', line 53 def initialize(, compressor, zlib_compression_level = nil) = @original_op_code = .op_code @uncompressed_size = 0 @compressor_id = COMPRESSOR_ID_MAP[compressor] = '' @zlib_compression_level = zlib_compression_level if zlib_compression_level && zlib_compression_level != -1 @request_id = .request_id end |
Instance Method Details
#maybe_inflate ⇒ Protocol::Message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Inflates an OP_COMRESSED message and returns the original message.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mongo/protocol/compressed.rb', line 69 def maybe_inflate = Registry.get(@original_op_code).allocate = Zlib::Inflate.inflate() 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 if .is_a?(Msg) .fix_after_deserialization end end |
#replyable? ⇒ true, false
Whether the message expects a reply from the database.
96 97 98 |
# File 'lib/mongo/protocol/compressed.rb', line 96 def replyable? .replyable? end |