Module: Mongo::Protocol::Serializers::Int32 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 32-bit integers.

Serializes and de-serializes one 32-bit integer.

Class Method Summary collapse

Class Method Details

.deserialize(buffer, _options = {}) ⇒ 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 a 32-bit Fixnum from the IO stream

Parameters:

  • buffer (String)

    Buffer containing the 32-bit integer

  • options (Hash)

    This method currently accepts no options.

Returns:

  • (Fixnum)

    Deserialized Int32



126
127
128
# File 'lib/mongo/protocol/serializers.rb', line 126

def self.deserialize(buffer, _options = {})
  buffer.get_int32
end

.serialize(buffer, value, _validating_keys = nil) ⇒ 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 a number to a 32-bit integer

Parameters:

  • buffer (String)

    Buffer to receive the serialized Int32.

  • value (Integer | BSON::Int32)

    32-bit integer to be serialized.

Returns:

  • (String)

    Buffer with serialized value.



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/mongo/protocol/serializers.rb', line 108

def self.serialize(buffer, value, _validating_keys = nil)
  if value.is_a?(BSON::Int32)
    value = if value.respond_to?(:value)
              # bson-ruby >= 4.6.0
              value.value
            else
              value.instance_variable_get(:@integer)
            end
  end
  buffer.put_int32(value)
end