oj 3.16.4 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/oj/usual.c +17 -1
- data/lib/oj/mimic.rb +1 -5
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +16 -4
- data/test/test_parser_usual.rb +24 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eef89e8f6c362f4ff8c384bba7a892bff9e730a1225bb0bc986acf50ba45dd4
|
4
|
+
data.tar.gz: 2d915ffcec2b55a4a91ad2292053e847efa5aa4ee6ef24e686cadd30218d7533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 845799a9624881305218a82d4d7ceb1ee535da2192ee44e30d38cd4727739749b5c9b18d891e5b363ca0a9b8e8025ee89a66f789f0bf4338493f2c34e1f6a576
|
7
|
+
data.tar.gz: f2cad391b8de831efbf419332b5cc12f29e9cfae1a7a1cf4bf98348de722a3b400cddb4aa29a98576f38cf929061fd57f6e97424eff2bf0e33a9d5f78cfa27c1
|
data/CHANGELOG.md
CHANGED
data/ext/oj/usual.c
CHANGED
@@ -289,9 +289,14 @@ static void close_object(ojParser p) {
|
|
289
289
|
}
|
290
290
|
rb_hash_bulk_insert(d->vtail - head, head, obj);
|
291
291
|
d->ktail = d->khead + c->ki;
|
292
|
+
|
292
293
|
d->vtail = head;
|
293
294
|
head--;
|
294
295
|
*head = obj;
|
296
|
+
if (1 == d->vtail - d->vhead && rb_block_given_p()) {
|
297
|
+
d->vtail = d->vhead;
|
298
|
+
rb_yield(obj);
|
299
|
+
}
|
295
300
|
}
|
296
301
|
|
297
302
|
static void close_object_class(ojParser p) {
|
@@ -572,7 +577,18 @@ static VALUE result(ojParser p) {
|
|
572
577
|
Usual d = (Usual)p->ctx;
|
573
578
|
|
574
579
|
if (d->vhead < d->vtail) {
|
575
|
-
|
580
|
+
long cnt = d->vtail - d->vhead;
|
581
|
+
volatile VALUE ary;
|
582
|
+
volatile VALUE *vp;
|
583
|
+
|
584
|
+
if (1 == cnt) {
|
585
|
+
return *d->vhead;
|
586
|
+
}
|
587
|
+
ary = rb_ary_new();
|
588
|
+
for (vp = d->vhead; vp < d->vtail; vp++) {
|
589
|
+
rb_ary_push(ary, *vp);
|
590
|
+
}
|
591
|
+
return ary;
|
576
592
|
}
|
577
593
|
if (d->raise_on_empty) {
|
578
594
|
rb_raise(oj_parse_error_class, "empty string");
|
data/lib/oj/mimic.rb
CHANGED
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -5,10 +5,22 @@ $LOAD_PATH << '.'
|
|
5
5
|
$LOAD_PATH << File.join(__dir__, '../lib')
|
6
6
|
$LOAD_PATH << File.join(__dir__, '../ext')
|
7
7
|
|
8
|
-
require 'json'
|
9
8
|
require 'oj'
|
10
|
-
require 'oj/json'
|
11
9
|
|
12
|
-
|
10
|
+
reader, writer = IO.pipe
|
13
11
|
|
14
|
-
|
12
|
+
thread =
|
13
|
+
Thread.new do
|
14
|
+
5.times do |id|
|
15
|
+
Oj.to_stream(writer, { "id" => id })
|
16
|
+
sleep(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
writer.close
|
20
|
+
end
|
21
|
+
|
22
|
+
p = Oj::Parser.new(:usual)
|
23
|
+
p.load(reader) { |data| puts "#{Time.now} -- ID: #{data["id"]}" }
|
24
|
+
|
25
|
+
reader.close
|
26
|
+
thread.join
|
data/test/test_parser_usual.rb
CHANGED
@@ -114,6 +114,30 @@ class UsualTest < Minitest::Test
|
|
114
114
|
assert_equal(Float, doc.class)
|
115
115
|
end
|
116
116
|
|
117
|
+
def test_multi_parse
|
118
|
+
p = Oj::Parser.new(:usual)
|
119
|
+
out = []
|
120
|
+
p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| out.push(j) }
|
121
|
+
assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_multi_load
|
125
|
+
p = Oj::Parser.new(:usual)
|
126
|
+
out = []
|
127
|
+
r, w = IO.pipe
|
128
|
+
thread = Thread.new do
|
129
|
+
['{"a":1}', '{"b":{"x"', ':2}}{"c":', '3}'].each { |seg|
|
130
|
+
w.write(seg)
|
131
|
+
sleep(0.1)
|
132
|
+
}
|
133
|
+
w.close
|
134
|
+
end
|
135
|
+
p.load(r) { |j| out.push(j) }
|
136
|
+
r.close
|
137
|
+
thread.join
|
138
|
+
assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
|
139
|
+
end
|
140
|
+
|
117
141
|
def test_omit_null
|
118
142
|
p = Oj::Parser.new(:usual)
|
119
143
|
p.omit_null = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.16.
|
4
|
+
version: 3.16.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ostruct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|