Class: TJSON::DataType::SignedInt

Inherits:
Integer show all
Defined in:
lib/tjson/datatype/integer.rb

Overview

Signed 64-bit integer

Constant Summary

Constants inherited from TJSON::DataType

TAGS

Instance Method Summary collapse

Methods inherited from Integer

#encode

Methods inherited from Scalar

#inspect

Methods inherited from TJSON::DataType

[], #encode, encode, identify_type, parse

Instance Method Details

#decode(str) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
# 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

#tagObject



15
16
17
# File 'lib/tjson/datatype/integer.rb', line 15

def tag
  "i"
end