class BSON::Int32
@since 2.0.0
@see bsonspec.org/#/specification<br><br>Represents int32 type.
def self.from_bson(buffer, **options)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(Integer)- 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) buffer.get_int32 end
def ==(other)
- 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?(Int32) value == other.value end
def as_extended_json(**options)
-
(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 {'$numberInt' => value.to_s} end end
def as_json(**options)
-
(Integer)- The Int32 as an Integer.
Other tags:
- Example: Get the Int32 as a JSON-serializable object. -
def as_json(**options) value end
def initialize(value)
- Since: - 4.2.0
Other tags:
- See: http://bsonspec.org/#/specification -
Parameters:
-
value(Integer) -- The 32-bit integer.
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
def to_bson(buffer = ByteBuffer.new)
- 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_int32(value) end
def to_bson_key
- 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