Module: Mongo::Protocol::Serializers::Sections Private

Defined in:
lib/mongo/protocol/serializers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

MongoDB wire protocol serialization strategy for a Section of OP_MSG.

Serializes and de-serializes a list of Sections.

Since:

  • 2.5.0

Defined Under Namespace

Modules: PayloadOne, PayloadZero

Class Method Summary collapse

Class Method Details

.deserialize(buffer) ⇒ Array<BSON::Document>

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.

Deserializes a section of an OP_MSG from the IO stream.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer containing the sections.

Returns:

  • (Array<BSON::Document>)

    Deserialized sections.

Since:

  • 2.5.0



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/mongo/protocol/serializers.rb', line 189

def self.deserialize(buffer)
  end_length = (@flag_bits & Msg::FLAGS.index(:checksum_present)) == 1 ? 32 : 0
  sections = []
  until buffer.length == end_length
    case byte = buffer.get_byte
    when PayloadZero::TYPE_BYTE
      sections << PayloadZero.deserialize(buffer)
    when PayloadOne::TYPE_BYTE
      sections += PayloadOne.deserialize(buffer)
    else
      raise Error::UnknownPayloadType.new(byte)
    end
  end
  sections
end

.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?) ⇒ BSON::ByteBuffer

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.

Serializes the sections of an OP_MSG, payload type 0 or 1.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer to receive the serialized Sections.

  • value (Array<Hash, BSON::Document>)

    The sections to be serialized.

  • max_bson_size (Fixnum) (defaults to: nil)

    The max bson size of documents in the sections.

  • validating_keys (true, false) (defaults to: BSON::Config.validating_keys?)

    Whether to validate document keys.

Returns:

  • (BSON::ByteBuffer)

    Buffer with serialized value.

Since:

  • 2.5.0



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/mongo/protocol/serializers.rb', line 167

def self.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?)
  value.each do |section|
    case section[:type]
    when PayloadZero::TYPE
      PayloadZero.serialize(buffer, section[:payload], max_bson_size, false)
    when nil
      PayloadZero.serialize(buffer, section[:payload], max_bson_size, false)
    when PayloadOne::TYPE
      PayloadOne.serialize(buffer, section[:payload], max_bson_size, validating_keys)
    else
      raise Error::UnknownPayloadType.new(section[:type])
    end
  end
end

.size_limited?true

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.

Whether there can be a size limit on this type after serialization.

Returns:

  • (true)

    Documents can be size limited upon serialization.

Since:

  • 2.5.0



210
211
212
# File 'lib/mongo/protocol/serializers.rb', line 210

def self.size_limited?
  true
end