class BSON::Int64

@since 2.0.0
@see bsonspec.org/#/specification<br><br>Represents int64 type.

def self.from_bson(buffer, **options)

Other tags:
    Since: - 2.0.0

Other tags:
    See: http://bsonspec.org/#/specification -

Returns:
  • (Integer | BSON::Int64) - The decoded Integer.

Options Hash: (**options)
  • :mode (nil | :bson) -- Decoding mode to use.

Parameters:
  • buffer (ByteBuffer) -- The byte buffer.
def self.from_bson(buffer, **options)
  value = buffer.get_int64
  if options[:mode] == :bson
    new(value)
  else
    value
  end
end

def ==(other)

Other tags:
    Since: - 4.4.0

Returns:
  • (true, false) - If the objects are equal.

Parameters:
  • other (Object) -- The object to check against.
def ==(other)
  return false unless other.is_a?(Int64)
  value == other.value
end

def as_extended_json(**options)

Returns:
  • (Hash | Integer) - The extended json representation.

Options Hash: (**opts)
  • :mode (nil | :relaxed | :legacy) -- Serialization mode
def as_extended_json(**options)
  if options[:mode] == :relaxed || options[:mode] == :legacy
    value
  else
    {'$numberLong' => value.to_s}
  end
end

def as_json(**options)

Returns:
  • (Integer) - The Int64 as an Integer.

Other tags:
    Example: Get the Int64 as a JSON-serializable object. -
def as_json(**options)
  value
end

def initialize(value)

Other tags:
    Since: - 4.2.0

Other tags:
    See: http://bsonspec.org/#/specification -

Parameters:
  • value (Integer) -- The 64-bit integer.
def initialize(value)
  if value.is_a?(self.class)
    @value = value.value
    return
  end
  unless value.bson_int64?
    raise RangeError.new("#{value} cannot be stored in 64 bits")
  end
  @value = value.freeze
end

def to_bson(buffer = ByteBuffer.new)

Other tags:
    Since: - 4.2.0

Other tags:
    See: http://bsonspec.org/#/specification -

Returns:
  • (BSON::ByteBuffer) - The buffer with the encoded integer.

Other tags:
    Example: Encoded the integer and append to a ByteBuffer. -
def to_bson(buffer = ByteBuffer.new)
  buffer.put_int64(value)
end

def to_bson_key

Other tags:
    Since: - 4.2.0

Returns:
  • (String) - The string key.

Other tags:
    Example: Convert the integer to a BSON key string. -
def to_bson_key
  value
end