Class: BSON::Int64

Inherits:
Object
  • Object
show all
Defined in:
lib/bson/int64.rb

Overview

Represents a $maxKey type, which compares less than any other value in the specification.

See Also:

Since:

  • 2.0.0

Constant Summary collapse

BSON_TYPE =

A boolean is type 0x08 in the BSON spec.

Since:

  • 2.0.0

18.chr.force_encoding(BINARY).freeze
PACK =

Constant for the int 64 pack directive.

Since:

  • 2.0.0

"q<".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integer) ⇒ Int64

Instantiate a BSON Int64.

Parameters:

  • integer (Integer)

    The 64-bit integer.

See Also:

Since:

  • 4.2.0



55
56
57
58
# File 'lib/bson/int64.rb', line 55

def initialize(integer)
  out_of_range! unless integer.bson_int64?
  @integer = integer.freeze
end

Class Method Details

.from_bson(buffer) ⇒ Integer

Deserialize an Integer from BSON.

Parameters:

Returns:

  • (Integer)

    The decoded Integer.

See Also:

Since:

  • 2.0.0



44
45
46
# File 'lib/bson/int64.rb', line 44

def self.from_bson(buffer)
  buffer.get_int64
end

Instance Method Details

#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ BSON::ByteBuffer

Append the integer as encoded BSON to a ByteBuffer.

Examples:

Encoded the integer and append to a ByteBuffer.

int64.to_bson

Returns:

See Also:

Since:

  • 4.2.0



70
71
72
# File 'lib/bson/int64.rb', line 70

def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
  buffer.put_int64(@integer)
end

#to_bson_key(validating_keys = Config.validating_keys?) ⇒ String

Convert the integer to a BSON string key.

Examples:

Convert the integer to a BSON key string.

int.to_bson_key

Parameters:

  • validating_keys (true, false) (defaults to: Config.validating_keys?)

    If BSON should validate the key.

Returns:

  • (String)

    The string key.

Since:

  • 4.2.0



84
85
86
# File 'lib/bson/int64.rb', line 84

def to_bson_key(validating_keys = Config.validating_keys?)
  @integer.to_bson_key(validating_keys)
end