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, options = {})
click to toggle source
Deserializes a document from the IO stream
@param [ String ] buffer Buffer containing the BSON encoded document. @param [ Hash ] options
@option options [ Boolean ] :deserialize_as_bson Whether to perform
section deserialization using BSON types instead of native Ruby types wherever possible.
@return [ Hash ] The decoded BSON document.
# File lib/mongo/protocol/serializers.rb, line 376 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?)
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 356 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?()
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 386 def self.size_limited? true end