123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Protocol::Serializers::Int64 Private

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

Overview

MongoDB wire protocol serialization strategy for 64-bit integers.

Serializes and de-serializes one 64-bit integer.

Class Method Summary

Class Method Details

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

Deserializes a 64-bit Fixnum from the IO stream

Parameters:

  • buffer (String)

    Buffer containing the 64-bit integer.

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

    This method currently accepts no options.

Returns:

  • (Fixnum)

    Deserialized Int64.

[ GitHub ]

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

def self.deserialize(buffer, options = {})
  buffer.get_int64
end

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

Serializes a number to a 64-bit integer

Parameters:

  • buffer (String)

    Buffer to receive the serialized Int64.

  • value (Integer | BSON::Int64)

    64-bit integer to be serialized.

Returns:

  • (String)

    Buffer with serialized value.

[ GitHub ]

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

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