Module: Mongo::Protocol::Serializers::Sections::PayloadOne Private
Relationships & Source Files | |
Defined in: | lib/mongo/protocol/serializers.rb |
Overview
MongoDB wire protocol serialization strategy for a payload 1 type Section of OP_MSG.
Constant Summary
-
TYPE =
The byte identifier for this payload type.
0x1
-
TYPE_BYTE =
The byte corresponding to this payload type.
TYPE.chr.force_encoding(BSON::BINARY).freeze
Class Method Summary
-
.deserialize(buffer) ⇒ Array<BSON::Document>
Internal use only
Deserializes a section of payload type 1 of an OP_MSG from the IO stream.
-
.serialize(buffer, value, max_bson_size = nil, validating_keys = nil) ⇒ BSON::ByteBuffer
Internal use only
Serializes a section of an OP_MSG, payload type 1.
Class Method Details
.deserialize(buffer) ⇒ Array
<BSON::Document
>
Deserializes a section of payload type 1 of an OP_MSG from the IO stream.
# File 'lib/mongo/protocol/serializers.rb', line 337
def self.deserialize(buffer) raise NotImplementedError 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 = nil) ⇒ BSON::ByteBuffer
Serializes a section of an OP_MSG, payload type 1.
# File 'lib/mongo/protocol/serializers.rb', line 319
def self.serialize(buffer, value, max_bson_size = nil, validating_keys = nil) 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) end buffer.replace_int32(start, buffer.length - start) end