class Jubatus::Common::TInt

Public Class Methods

new(signed, byts) click to toggle source
# 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

Public Instance Methods

from_msgpack(m) click to toggle source
# 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) click to toggle source
# 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