module Mongo::Protocol::Serializers::Document

MongoDB wire protocol serialization strategy for a BSON Document.

Serializes and de-serializes a single document.

Public Class Methods

deserialize(buffer) click to toggle source

Deserializes a document from the IO stream

@param [ String ] buffer Buffer containing the BSON encoded document.

@return [ Hash ] The decoded BSON document.

# File lib/mongo/protocol/serializers.rb, line 353
def self.deserialize(buffer)
  BSON::Document.from_bson(buffer)
end
serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?) click to toggle source

Serializes a document into the buffer

@param buffer [ String ] Buffer to receive the BSON encoded document. @param value [ Hash ] Document to serialize as BSON.

@return [ String ] Buffer with serialized value.

# File lib/mongo/protocol/serializers.rb, line 340
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)
  if max_bson_size && buffer.length - start_size > max_bson_size
    raise Error::MaxBSONSize.new(max_bson_size)
  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.0.0

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