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. See https://github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.md
Constant Summary collapse
- NOOP =
The noop compressor identifier.
'noop'- 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'- 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'- ZSTD =
The zstd compressor identifier.
'zstd'- 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
Constants included from Serializers
Serializers::HEADER_PACK, Serializers::INT32_PACK, Serializers::INT64_PACK, Serializers::NULL, Serializers::ZERO
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.
- #serialize_fields(buffer, max_bson_size) ⇒ Object private
Methods inherited from Message
#==, deserialize, #deserialize_array, #deserialize_field, deserialize_header, field, fields, #fields, #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.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mongo/protocol/compressed.rb', line 76 def initialize(, compressor, zlib_compression_level = nil) super() @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 # A compressed message must reuse the wrapped message's request id, # overriding the fresh id assigned by the superclass initializer. @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 |
# File 'lib/mongo/protocol/compressed.rb', line 95 def maybe_inflate = Registry.get(@original_op_code).allocate buf = decompress(@compressed_message) .fields.each do |field| if field[:multi] .deserialize_array(buf, field) else .deserialize_field(buf, field) end end .fix_after_deserialization if .is_a?(Msg) end |
#replyable? ⇒ true, false
Whether the message expects a reply from the database.
118 119 120 |
# File 'lib/mongo/protocol/compressed.rb', line 118 def replyable? @original_message.replyable? end |
#serialize_fields(buffer, max_bson_size) ⇒ Object
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.
123 124 125 126 127 128 129 |
# File 'lib/mongo/protocol/compressed.rb', line 123 def serialize_fields(buffer, max_bson_size) buf = BSON::ByteBuffer.new @original_message.serialize_fields(buf, max_bson_size) @uncompressed_size = buf.length @compressed_message = compress(buf) super end |