Module: Mongo::Protocol::Serializers::Document Private

Defined in:
build/ruby-driver-master/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 BSON Document.

Serializes and de-serializes a single document.

Class Method Summary collapse

Class Method Details

.deserialize(buffer, options = {}) ⇒ Hash

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 document from the IO stream

Parameters:

  • buffer (String)

    Buffer containing the BSON encoded document.

  • 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:

  • (Hash)

    The decoded BSON document.



379
380
381
382
# File 'build/ruby-driver-master/lib/mongo/protocol/serializers.rb', line 379

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 = BSON::Config.validating_keys?) ⇒ String

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 document into the buffer

Parameters:

  • buffer (String)

    Buffer to receive the BSON encoded document.

  • value (Hash)

    Document to serialize as BSON.

Returns:

  • (String)

    Buffer with serialized value.



359
360
361
362
363
364
365
366
367
# File 'build/ruby-driver-master/lib/mongo/protocol/serializers.rb', line 359

def self.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?)
  start_size = buffer.length
  value.to_bson(buffer, validating_keys)
  serialized_size = buffer.length - start_size
  if max_bson_size && serialized_size > max_bson_size
    raise Error::MaxBSONSize,
      "The document exceeds maximum allowed BSON object size after serialization. Serialized size: #{serialized_size} bytes, maximum allowed size: #{max_bson_size} bytes"
  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.0.0



389
390
391
# File 'build/ruby-driver-master/lib/mongo/protocol/serializers.rb', line 389

def self.size_limited?
  true
end