Class: Mongo::Protocol::Compressed
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/protocol/compressed.rb
Overview
MongoDB Wire protocol Compressed message.
This is a bi-directional message that compresses another opcode. See github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.rst
Constant Summary collapse
- NOOP =
The noop compressor identifier.
'noop'.freeze
- NOOP_BYTE =
The byte signaling that the message has not been compressed (test mode).
0.chr.force_encoding(BSON::BINARY).freeze
- SNAPPY =
The snappy compressor identifier.
'snappy'.freeze
- SNAPPY_BYTE =
The byte signaling that the message has been compressed with snappy.
1.chr.force_encoding(BSON::BINARY).freeze
- 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
- ZSTD =
The zstd compressor identifier.
'zstd'.freeze
- ZSTD_BYTE =
The byte signaling that the message has been compressed with zstd.
3.chr.force_encoding(BSON::BINARY).freeze
- COMPRESSOR_ID_MAP =
The compressor identifier to byte map.
{ SNAPPY => SNAPPY_BYTE, ZSTD => ZSTD_BYTE, 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_add_server_api, #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.
79 80 81 82 83 84 85 86 87 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/compressed.rb', line 79 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 = .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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/compressed.rb', line 95 def maybe_inflate = Registry.get(@original_op_code).allocate buf = decompress(@compressed_message) .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.
120 121 122 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/compressed.rb', line 120 def replyable? @original_message.replyable? end |