Module: Mongo::Protocol::Serializers::Document Private
Relationships & Source Files | |
Defined in: | lib/mongo/protocol/serializers.rb |
Overview
MongoDB wire protocol serialization strategy for a BSON Document.
Serializes and de-serializes a single document.
Class Attribute Summary
-
.size_limited? ⇒ true
readonly
Internal use only
Whether there can be a size limit on this type after serialization.
Class Method Summary
-
.deserialize(buffer, options = {}) ⇒ Hash
Internal use only
Deserializes a document from the IO stream.
-
.serialize(buffer, value, max_bson_size = nil, validating_keys = nil) ⇒ String
Internal use only
Serializes a document into the buffer.
Class Attribute Details
.size_limited? ⇒ true
(readonly)
Whether there can be a size limit on this type after serialization.
# File 'lib/mongo/protocol/serializers.rb', line 394
def self.size_limited? true end
Class Method Details
.deserialize(buffer, options = {}) ⇒ Hash
Deserializes a document from the IO stream
# File 'lib/mongo/protocol/serializers.rb', line 384
def self.deserialize(buffer, = {}) mode = [:deserialize_as_bson] ? :bson : nil BSON::Document.from_bson(buffer, **{ mode: mode }) end
.serialize(buffer, value, max_bson_size = nil, validating_keys = nil) ⇒ String
Serializes a document into the buffer
# File 'lib/mongo/protocol/serializers.rb', line 364
def self.serialize(buffer, value, max_bson_size = nil, validating_keys = nil) start_size = buffer.length value.to_bson(buffer) 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