Module: Mongo::Protocol::Serializers::Sections::PayloadOne 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 payload 1 type Section of OP_MSG.

Since:

  • 2.5.0

Constant Summary collapse

TYPE =

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

The byte identifier for this payload type.

Since:

  • 2.5.0

0x1
TYPE_BYTE =

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

The byte corresponding to this payload type.

Since:

  • 2.5.0

TYPE.chr.force_encoding(BSON::BINARY).freeze

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 payload type 1 of an OP_MSG from the IO stream.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer containing the sections.

Returns:

  • (Array<BSON::Document>)

    Deserialized section.

Since:

  • 2.5.0



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/mongo/protocol/serializers.rb', line 299

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?) ⇒ 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 a section of an OP_MSG, payload type 1.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer to receive the serialized 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: BSON::Config.validating_keys?)

    Whether to validate document keys.

Returns:

  • (BSON::ByteBuffer)

    Buffer with serialized value.

Since:

  • 2.5.0



281
282
283
284
285
286
287
288
289
290
# File 'lib/mongo/protocol/serializers.rb', line 281

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