Class: BSON::Int32

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

Overview

Represents int32 type.

See Also:

Since:

  • 2.0.0

Constant Summary collapse

BSON_TYPE =

A boolean is type 0x08 in the BSON spec.

Since:

  • 2.0.0

16.chr.force_encoding(BINARY).freeze
BYTES_LENGTH =

The number of bytes constant.

Since:

  • 4.0.0

4
PACK =

Constant for the int 32 pack directive.

Since:

  • 2.0.0

"l<".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integer) ⇒ Int32

Instantiate a BSON Int32.

Parameters:

  • integer (Integer)

    The 32-bit integer.

See Also:

Since:

  • 4.2.0



59
60
61
62
# File 'lib/bson/int32.rb', line 59

def initialize(integer)
  out_of_range! unless integer.bson_int32?
  @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



48
49
50
# File 'lib/bson/int32.rb', line 48

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.

Parameters:

  • other (Object)

    The object to check against.

Returns:

  • (true, false)

    If the objects are equal.

Since:

  • 4.4.0



99
100
101
102
# File 'lib/bson/int32.rb', line 99

def ==(other)
  return false unless other.is_a?(Int32)
  @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.

Examples:

Encoded the integer and append to a ByteBuffer.

int32.to_bson

Returns:

See Also:

Since:

  • 4.2.0



74
75
76
# File 'lib/bson/int32.rb', line 74

def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
  buffer.put_int32(@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



88
89
90
# File 'lib/bson/int32.rb', line 88

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