Class: BSON::Int32
Overview
Represents int32 type.
Constant Summary collapse
- BSON_TYPE =
A boolean is type 0x08 in the BSON spec.
::String.new(16.chr, encoding: BINARY).freeze
- BYTES_LENGTH =
The number of bytes constant.
4
- PACK =
Constant for the int 32 pack directive.
"l<"
Instance Attribute Summary collapse
-
#value ⇒ Integer
readonly
Returns the value of this Int32.
Class Method Summary collapse
-
.from_bson(buffer, **options) ⇒ Integer
Deserialize an Integer from BSON.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?, #===)
Check equality of the int32 with another object.
-
#as_extended_json(**options) ⇒ Hash | Integer
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
-
#as_json(**options) ⇒ Integer
Return a string representation of the Int32 for use in application-level JSON serialization.
-
#initialize(value) ⇒ Int32
constructor
Instantiate a BSON Int32.
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Append the integer as encoded BSON to a ByteBuffer.
-
#to_bson_key ⇒ String
Convert the integer to a BSON string key.
Methods included from JSON
Constructor Details
#initialize(value) ⇒ Int32
Instantiate a BSON Int32.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bson/int32.rb', line 64 def initialize(value) if value.is_a?(self.class) @value = value.value return end unless value.bson_int32? raise RangeError.new("#{value} cannot be stored in 32 bits") end @value = value.freeze end |
Instance Attribute Details
#value ⇒ Integer (readonly)
Returns the value of this Int32.
79 80 81 |
# File 'lib/bson/int32.rb', line 79 def value @value end |
Class Method Details
.from_bson(buffer, **options) ⇒ Integer
Deserialize an Integer from BSON.
53 54 55 |
# File 'lib/bson/int32.rb', line 53 def self.from_bson(buffer, **) buffer.get_int32 end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?, ===
Check equality of the int32 with another object.
114 115 116 117 |
# File 'lib/bson/int32.rb', line 114 def ==(other) return false unless other.is_a?(Int32) value == other.value end |
#as_extended_json(**options) ⇒ Hash | Integer
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
This method returns the integer value if relaxed representation is requested, otherwise a $numberInt hash.
143 144 145 146 147 148 149 |
# File 'lib/bson/int32.rb', line 143 def as_extended_json(**) if [:mode] == :relaxed || [:mode] == :legacy value else {'$numberInt' => value.to_s} end end |
#as_json(**options) ⇒ Integer
Return a string representation of the Int32 for use in application-level JSON serialization. This method is intentionally different from #as_extended_json.
129 130 131 |
# File 'lib/bson/int32.rb', line 129 def as_json(**) value end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Append the integer as encoded BSON to a ByteBuffer.
91 92 93 |
# File 'lib/bson/int32.rb', line 91 def to_bson(buffer = ByteBuffer.new) buffer.put_int32(value) end |
#to_bson_key ⇒ String
Convert the integer to a BSON string key.
103 104 105 |
# File 'lib/bson/int32.rb', line 103 def to_bson_key value end |