Class: Jubatus::Common::TInt
- Inherits:
-
TPrimitive
- Object
- TPrimitive
- Jubatus::Common::TInt
- Defined in:
- lib/jubatus/common/types.rb
Instance Method Summary collapse
- #from_msgpack(m) ⇒ Object
-
#initialize(signed, byts) ⇒ TInt
constructor
A new instance of TInt.
- #to_msgpack(m) ⇒ Object
Constructor Details
#initialize(signed, byts) ⇒ TInt
Returns a new instance of TInt.
38 39 40 41 42 43 44 45 46 |
# File 'lib/jubatus/common/types.rb', line 38 def initialize(signed, byts) if signed @max = (1 << (8 * byts - 1)) - 1 @min = - (1 << (8 * byts - 1)) else @max = (1 << (8 * byts)) - 1 @min = 0 end end |
Instance Method Details
#from_msgpack(m) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/jubatus/common/types.rb', line 48 def from_msgpack(m) Jubatus::Common.check_type(m, Integer) if not (@min <= m and m <= @max) raise ValueError, "int value must be in (%d, %d), but %d is given" % [@min, @max, m] end return m end |
#to_msgpack(m) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/jubatus/common/types.rb', line 56 def to_msgpack(m) Jubatus::Common.check_type(m, Integer) if not (@min <= m and m <= @max) raise ValueError, "int value must be in (%d, %d), but %d is given" % [@min, @max, m] end return m end |