123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Protocol::Serializers::Header Private

Relationships & Source Files
Defined in: lib/mongo/protocol/serializers.rb

Overview

MongoDB wire protocol serialization strategy for message headers.

Serializes and de-serializes four 32-bit integers consisting of the length of the message, the request id, the response id, and the op code for the operation.

Class Method Summary

Class Method Details

.deserialize(buffer, options = {}) ⇒ Array<Fixnum>

Deserializes the header value from the IO stream

Parameters:

  • buffer (String)

    Buffer containing the message header.

  • options (Hash) (defaults to: {})

    This method currently accepts no options.

Returns:

  • (Array<Fixnum>)

    Array consisting of the deserialized length, request id, response id, and op code.

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 69

def self.deserialize(buffer, options = {})
  buffer.get_bytes(16).unpack(HEADER_PACK)
end

.serialize(buffer, value, validating_keys = nil) ⇒ String

Serializes the header value into the buffer

Parameters:

  • buffer (String)

    Buffer to receive the serialized value.

  • value (String)

    Header value to be serialized.

  • validating_keys (true, false) (defaults to: nil)

    Whether keys should be validated when serializing. This option is deprecated and will not be used. It will removed in version 3.0.

Returns:

  • (String)

    Buffer with serialized value.

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 58

def self.serialize(buffer, value, validating_keys = nil)
  buffer.put_bytes(value.pack(HEADER_PACK))
end