123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: lib/mongo/protocol/serializers.rb

Overview

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

Since:

  • 2.5.0

Constant Summary

Class Method Summary

Class Method Details

.deserialize(buffer, options = {}) ⇒ Array<BSON::Document>

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

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer containing the sections.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :deserialize_as_bson (Boolean)

    Whether to perform section deserialization using BSON types instead of native Ruby types wherever possible.

Returns:

  • (Array<BSON::Document>)

    Deserialized section.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 287

def self.deserialize(buffer, options = {})
  mode = options[:deserialize_as_bson] ? :bson : nil
  BSON::Document.from_bson(buffer, **{ mode: mode })
end

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

Serializes a section of an OP_MSG, payload type 0.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer to receive the serialized ::Mongo::Protocol::Serializers::Sections.

  • value (BSON::Document, Hash)

    The object to serialize.

  • max_bson_size (Fixnum) (defaults to: nil)

    The max bson size of documents in the section.

  • validating_keys (true, false) (defaults to: nil)

    Whether to validate document keys. This option is deprecated and will not be used. It will removed in version 3.0.

Returns:

  • (BSON::ByteBuffer)

    Buffer with serialized value.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 270

def self.serialize(buffer, value, max_bson_size = nil, validating_keys = nil)
  buffer.put_byte(TYPE_BYTE)
  Serializers::Document.serialize(buffer, value, max_bson_size)
end