ed-precompiled_json 2.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/BSDL +22 -0
- data/CHANGES.md +693 -0
- data/COPYING +56 -0
- data/LEGAL +8 -0
- data/README.md +283 -0
- data/ext/json/ext/fbuffer/fbuffer.h +296 -0
- data/ext/json/ext/generator/extconf.rb +16 -0
- data/ext/json/ext/generator/generator.c +2169 -0
- data/ext/json/ext/parser/extconf.rb +15 -0
- data/ext/json/ext/parser/parser.c +1557 -0
- data/ext/json/ext/simd/conf.rb +24 -0
- data/ext/json/ext/simd/simd.h +188 -0
- data/ext/json/ext/vendor/fpconv.c +480 -0
- data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
- data/json.gemspec +62 -0
- data/lib/json/add/bigdecimal.rb +58 -0
- data/lib/json/add/complex.rb +51 -0
- data/lib/json/add/core.rb +13 -0
- data/lib/json/add/date.rb +54 -0
- data/lib/json/add/date_time.rb +67 -0
- data/lib/json/add/exception.rb +49 -0
- data/lib/json/add/ostruct.rb +54 -0
- data/lib/json/add/range.rb +54 -0
- data/lib/json/add/rational.rb +49 -0
- data/lib/json/add/regexp.rb +48 -0
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/string.rb +35 -0
- data/lib/json/add/struct.rb +52 -0
- data/lib/json/add/symbol.rb +52 -0
- data/lib/json/add/time.rb +52 -0
- data/lib/json/common.rb +1130 -0
- data/lib/json/ext/generator/state.rb +99 -0
- data/lib/json/ext.rb +57 -0
- data/lib/json/generic_object.rb +67 -0
- data/lib/json/truffle_ruby/generator.rb +708 -0
- data/lib/json/version.rb +5 -0
- data/lib/json.rb +642 -0
- metadata +88 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Range
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
new(*object['a'])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Methods <tt>Range#as_json</tt> and +Range.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Range object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Range#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/range'
|
|
21
|
+
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
|
22
|
+
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
|
23
|
+
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
|
24
|
+
#
|
|
25
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Range object:
|
|
26
|
+
#
|
|
27
|
+
# Range.json_create(x) # => 1..4
|
|
28
|
+
# Range.json_create(y) # => 1...4
|
|
29
|
+
# Range.json_create(z) # => "a".."d"
|
|
30
|
+
#
|
|
31
|
+
def as_json(*)
|
|
32
|
+
{
|
|
33
|
+
JSON.create_id => self.class.name,
|
|
34
|
+
'a' => [ first, last, exclude_end? ]
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns a JSON string representing +self+:
|
|
39
|
+
#
|
|
40
|
+
# require 'json/add/range'
|
|
41
|
+
# puts (1..4).to_json
|
|
42
|
+
# puts (1...4).to_json
|
|
43
|
+
# puts ('a'..'d').to_json
|
|
44
|
+
#
|
|
45
|
+
# Output:
|
|
46
|
+
#
|
|
47
|
+
# {"json_class":"Range","a":[1,4,false]}
|
|
48
|
+
# {"json_class":"Range","a":[1,4,true]}
|
|
49
|
+
# {"json_class":"Range","a":["a","d",false]}
|
|
50
|
+
#
|
|
51
|
+
def to_json(*args)
|
|
52
|
+
as_json.to_json(*args)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Rational
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
Rational(object['n'], object['d'])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Methods <tt>Rational#as_json</tt> and +Rational.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Rational object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Rational#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/rational'
|
|
21
|
+
# x = Rational(2, 3).as_json
|
|
22
|
+
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Rational object:
|
|
25
|
+
#
|
|
26
|
+
# Rational.json_create(x)
|
|
27
|
+
# # => (2/3)
|
|
28
|
+
#
|
|
29
|
+
def as_json(*)
|
|
30
|
+
{
|
|
31
|
+
JSON.create_id => self.class.name,
|
|
32
|
+
'n' => numerator,
|
|
33
|
+
'd' => denominator,
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Returns a JSON string representing +self+:
|
|
38
|
+
#
|
|
39
|
+
# require 'json/add/rational'
|
|
40
|
+
# puts Rational(2, 3).to_json
|
|
41
|
+
#
|
|
42
|
+
# Output:
|
|
43
|
+
#
|
|
44
|
+
# {"json_class":"Rational","n":2,"d":3}
|
|
45
|
+
#
|
|
46
|
+
def to_json(*args)
|
|
47
|
+
as_json.to_json(*args)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Regexp
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
new(object['s'], object['o'])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Methods <tt>Regexp#as_json</tt> and +Regexp.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Regexp object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Regexp#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/regexp'
|
|
21
|
+
# x = /foo/.as_json
|
|
22
|
+
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Regexp object:
|
|
25
|
+
#
|
|
26
|
+
# Regexp.json_create(x) # => /foo/
|
|
27
|
+
#
|
|
28
|
+
def as_json(*)
|
|
29
|
+
{
|
|
30
|
+
JSON.create_id => self.class.name,
|
|
31
|
+
'o' => options,
|
|
32
|
+
's' => source,
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Returns a JSON string representing +self+:
|
|
37
|
+
#
|
|
38
|
+
# require 'json/add/regexp'
|
|
39
|
+
# puts /foo/.to_json
|
|
40
|
+
#
|
|
41
|
+
# Output:
|
|
42
|
+
#
|
|
43
|
+
# {"json_class":"Regexp","o":0,"s":"foo"}
|
|
44
|
+
#
|
|
45
|
+
def to_json(*args)
|
|
46
|
+
as_json.to_json(*args)
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/json/add/set.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
2
|
+
require 'json'
|
|
3
|
+
end
|
|
4
|
+
defined?(::Set) or require 'set'
|
|
5
|
+
|
|
6
|
+
class Set
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
new object['a']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Methods <tt>Set#as_json</tt> and +Set.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Set object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Set#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/set'
|
|
21
|
+
# x = Set.new(%w/foo bar baz/).as_json
|
|
22
|
+
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Set object:
|
|
25
|
+
#
|
|
26
|
+
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
|
27
|
+
#
|
|
28
|
+
def as_json(*)
|
|
29
|
+
{
|
|
30
|
+
JSON.create_id => self.class.name,
|
|
31
|
+
'a' => to_a,
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Returns a JSON string representing +self+:
|
|
36
|
+
#
|
|
37
|
+
# require 'json/add/set'
|
|
38
|
+
# puts Set.new(%w/foo bar baz/).to_json
|
|
39
|
+
#
|
|
40
|
+
# Output:
|
|
41
|
+
#
|
|
42
|
+
# {"json_class":"Set","a":["foo","bar","baz"]}
|
|
43
|
+
#
|
|
44
|
+
def to_json(*args)
|
|
45
|
+
as_json.to_json(*args)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class String
|
|
7
|
+
# call-seq: json_create(o)
|
|
8
|
+
#
|
|
9
|
+
# Raw Strings are JSON Objects (the raw bytes are stored in an array for the
|
|
10
|
+
# key "raw"). The Ruby String can be created by this class method.
|
|
11
|
+
def self.json_create(object)
|
|
12
|
+
object["raw"].pack("C*")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# call-seq: to_json_raw_object()
|
|
16
|
+
#
|
|
17
|
+
# This method creates a raw object hash, that can be nested into
|
|
18
|
+
# other data structures and will be generated as a raw string. This
|
|
19
|
+
# method should be used, if you want to convert raw strings to JSON
|
|
20
|
+
# instead of UTF-8 strings, e. g. binary data.
|
|
21
|
+
def to_json_raw_object
|
|
22
|
+
{
|
|
23
|
+
JSON.create_id => self.class.name,
|
|
24
|
+
"raw" => unpack("C*"),
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# call-seq: to_json_raw(*args)
|
|
29
|
+
#
|
|
30
|
+
# This method creates a JSON text from the result of a call to
|
|
31
|
+
# to_json_raw_object of this String.
|
|
32
|
+
def to_json_raw(...)
|
|
33
|
+
to_json_raw_object.to_json(...)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Struct
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
new(*object['v'])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Methods <tt>Struct#as_json</tt> and +Struct.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Struct object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Struct#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/struct'
|
|
21
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
|
22
|
+
# x = Struct::Customer.new.as_json
|
|
23
|
+
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
|
24
|
+
#
|
|
25
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Struct object:
|
|
26
|
+
#
|
|
27
|
+
# Struct::Customer.json_create(x)
|
|
28
|
+
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
|
29
|
+
#
|
|
30
|
+
def as_json(*)
|
|
31
|
+
klass = self.class.name
|
|
32
|
+
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
|
33
|
+
{
|
|
34
|
+
JSON.create_id => klass,
|
|
35
|
+
'v' => values,
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns a JSON string representing +self+:
|
|
40
|
+
#
|
|
41
|
+
# require 'json/add/struct'
|
|
42
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
|
43
|
+
# puts Struct::Customer.new.to_json
|
|
44
|
+
#
|
|
45
|
+
# Output:
|
|
46
|
+
#
|
|
47
|
+
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
|
48
|
+
#
|
|
49
|
+
def to_json(*args)
|
|
50
|
+
as_json.to_json(*args)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Symbol
|
|
7
|
+
|
|
8
|
+
# Methods <tt>Symbol#as_json</tt> and +Symbol.json_create+ may be used
|
|
9
|
+
# to serialize and deserialize a \Symbol object;
|
|
10
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
11
|
+
#
|
|
12
|
+
# \Method <tt>Symbol#as_json</tt> serializes +self+,
|
|
13
|
+
# returning a 2-element hash representing +self+:
|
|
14
|
+
#
|
|
15
|
+
# require 'json/add/symbol'
|
|
16
|
+
# x = :foo.as_json
|
|
17
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
|
18
|
+
#
|
|
19
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Symbol object:
|
|
20
|
+
#
|
|
21
|
+
# Symbol.json_create(x) # => :foo
|
|
22
|
+
#
|
|
23
|
+
def as_json(*)
|
|
24
|
+
{
|
|
25
|
+
JSON.create_id => self.class.name,
|
|
26
|
+
's' => to_s,
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns a JSON string representing +self+:
|
|
31
|
+
#
|
|
32
|
+
# require 'json/add/symbol'
|
|
33
|
+
# puts :foo.to_json
|
|
34
|
+
#
|
|
35
|
+
# Output:
|
|
36
|
+
#
|
|
37
|
+
# # {"json_class":"Symbol","s":"foo"}
|
|
38
|
+
#
|
|
39
|
+
def to_json(state = nil, *a)
|
|
40
|
+
state = ::JSON::State.from_state(state)
|
|
41
|
+
if state.strict?
|
|
42
|
+
super
|
|
43
|
+
else
|
|
44
|
+
as_json.to_json(state, *a)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# See #as_json.
|
|
49
|
+
def self.json_create(o)
|
|
50
|
+
o['s'].to_sym
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
|
+
require 'json'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Time
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
|
+
def self.json_create(object)
|
|
10
|
+
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
|
11
|
+
object['n'] = usec * 1000
|
|
12
|
+
end
|
|
13
|
+
at(object['s'], Rational(object['n'], 1000))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
|
|
17
|
+
# to serialize and deserialize a \Time object;
|
|
18
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
19
|
+
#
|
|
20
|
+
# \Method <tt>Time#as_json</tt> serializes +self+,
|
|
21
|
+
# returning a 2-element hash representing +self+:
|
|
22
|
+
#
|
|
23
|
+
# require 'json/add/time'
|
|
24
|
+
# x = Time.now.as_json
|
|
25
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
|
26
|
+
#
|
|
27
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Time object:
|
|
28
|
+
#
|
|
29
|
+
# Time.json_create(x)
|
|
30
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
|
31
|
+
#
|
|
32
|
+
def as_json(*)
|
|
33
|
+
{
|
|
34
|
+
JSON.create_id => self.class.name,
|
|
35
|
+
's' => tv_sec,
|
|
36
|
+
'n' => tv_nsec,
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Returns a JSON string representing +self+:
|
|
41
|
+
#
|
|
42
|
+
# require 'json/add/time'
|
|
43
|
+
# puts Time.now.to_json
|
|
44
|
+
#
|
|
45
|
+
# Output:
|
|
46
|
+
#
|
|
47
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
|
48
|
+
#
|
|
49
|
+
def to_json(*args)
|
|
50
|
+
as_json.to_json(*args)
|
|
51
|
+
end
|
|
52
|
+
end
|