module Mongo::Protocol::Serializers::Sections::PayloadOne

MongoDB wire protocol serialization strategy for a payload 1 type Section of OP_MSG.

@since 2.5.0

Constants

TYPE

The byte identifier for this payload type.

@since 2.5.0

TYPE_BYTE

The byte corresponding to this payload type.

@since 2.5.0

Public Class Methods

deserialize(buffer) click to toggle source

Deserializes a section of payload type 1 of an OP_MSG from the IO stream.

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

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

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 305
def self.deserialize(buffer)
  start_size = buffer.length
  section_size = buffer.get_int32 # get the size
  end_size = start_size - section_size
  buffer.get_cstring # get the identifier
  documents = []
  until buffer.length == end_size
    documents << BSON::Document.from_bson(buffer)
  end
  documents
end
serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?) click to toggle source

Serializes a section of an OP_MSG, payload type 1.

@param [ BSON::ByteBuffer ] buffer Buffer to receive the serialized Sections. @param [ BSON::Document, Hash ] value The object to serialize. @param [ Fixnum ] max_bson_size The max bson size of documents in the section. @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 287
def self.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?)
  buffer.put_byte(TYPE_BYTE)
  start = buffer.length
  buffer.put_int32(0) # hold for size
  buffer.put_cstring(value[:identifier])
  value[:sequence].each do |document|
    Document.serialize(buffer, document, max_bson_size, validating_keys)
  end
  buffer.replace_int32(start, buffer.length - start)
end