module Mongo::Protocol::Serializers::Sections

MongoDB wire protocol serialization strategy for a Section of OP_MSG.

Serializes and de-serializes a list of Sections.

@since 2.5.0

Public Class Methods

deserialize(buffer) click to toggle source

Deserializes a section of an OP_MSG from the IO stream.

@param [ BSON::ByteBuffer ] buffer Buffer containing the sections.

@return [ Array<BSON::Document> ] Deserialized sections.

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 195
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?) click to toggle source

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

@param [ BSON::ByteBuffer ] buffer Buffer to receive the serialized Sections. @param [ Array<Hash, BSON::Document> ] value The sections to be serialized. @param [ Fixnum ] max_bson_size The max bson size of documents in the sections. @param [ true, false ] validating_keys Whether to validate document keys.

@return [ BSON::ByteBuffer ] Buffer with serialized value.

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 173
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?() click to toggle source

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

@return [ true ] Documents can be size limited upon serialization.

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 216
def self.size_limited?
  true
end