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

Defined in:
lib/mongo/protocol/serializers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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 collapse

Class Method Details

.deserialize(buffer) ⇒ Array<Fixnum>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deserializes the header value from the IO stream

Parameters:

  • buffer (String)

    Buffer containing the message header.

Returns:

  • (Array<Fixnum>)

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



63
64
65
# File 'lib/mongo/protocol/serializers.rb', line 63

def self.deserialize(buffer)
  buffer.get_bytes(16).unpack(HEADER_PACK)
end

.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serializes the header value into the buffer

Parameters:

  • buffer (String)

    Buffer to receive the serialized value.

  • value (String)

    Header value to be serialized.

Returns:

  • (String)

    Buffer with serialized value.



53
54
55
# File 'lib/mongo/protocol/serializers.rb', line 53

def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
  buffer.put_bytes(value.pack(HEADER_PACK))
end