Class: BSON::Int64
- Inherits:
-
Object
- Object
- BSON::Int64
- Defined in:
- lib/bson/int64.rb
Overview
Represents int64 type.
Constant Summary collapse
- BSON_TYPE =
A boolean is type 0x08 in the BSON spec.
18.chr.force_encoding(BINARY).freeze
- PACK =
Constant for the int 64 pack directive.
"q<".freeze
Class Method Summary collapse
-
.from_bson(buffer) ⇒ Integer
Deserialize an Integer from BSON.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?, #===)
Check equality of the int64 with another object.
-
#initialize(integer) ⇒ Int64
constructor
Instantiate a BSON Int64.
-
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ BSON::ByteBuffer
Append the integer as encoded BSON to a ByteBuffer.
-
#to_bson_key(validating_keys = Config.validating_keys?) ⇒ String
Convert the integer to a BSON string key.
Constructor Details
#initialize(integer) ⇒ Int64
Instantiate a BSON Int64.
54 55 56 57 |
# File 'lib/bson/int64.rb', line 54 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.
43 44 45 |
# File 'lib/bson/int64.rb', line 43 def self.from_bson(buffer) buffer.get_int64 end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?, ===
Check equality of the int64 with another object.
94 95 96 97 |
# File 'lib/bson/int64.rb', line 94 def ==(other) return false unless other.is_a?(Int64) @integer == other.instance_variable_get('@integer') end |
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ BSON::ByteBuffer
Append the integer as encoded BSON to a ByteBuffer.
69 70 71 |
# File 'lib/bson/int64.rb', line 69 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.
83 84 85 |
# File 'lib/bson/int64.rb', line 83 def to_bson_key(validating_keys = Config.validating_keys?) @integer end |