class TJSON::DataType::SignedInt

Signed 64-bit integer

Public Instance Methods

decode(str) click to toggle source
# File lib/tjson/datatype/integer.rb, line 19
def decode(str)
  raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String)
  raise TJSON::ParseError, "invalid integer: #{str.inspect}" unless str =~ /\A\-?(0|[1-9][0-9]*)\z/

  result = Integer(str, 10)
  raise TJSON::ParseError, "oversized integer: #{result}"  if result > 9_223_372_036_854_775_807
  raise TJSON::ParseError, "undersized integer: #{result}" if result < -9_223_372_036_854_775_808

  result
end
tag() click to toggle source
# File lib/tjson/datatype/integer.rb, line 15
def tag
  "i"
end