msgpack 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/unpack.c +26 -8
- data/test/msgpack_test.rb +28 -2
- metadata +2 -2
data/ext/unpack.c
CHANGED
@@ -389,25 +389,43 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
|
389
389
|
}
|
390
390
|
|
391
391
|
|
392
|
+
static VALUE MessagePack_Unpacker_execute_impl(VALUE self, VALUE data,
|
393
|
+
size_t from, size_t limit)
|
394
|
+
{
|
395
|
+
UNPACKER(self, mp);
|
396
|
+
|
397
|
+
if(from >= limit) {
|
398
|
+
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
|
399
|
+
}
|
400
|
+
|
401
|
+
int ret = template_execute_wrap(mp, data, limit, &from);
|
402
|
+
|
403
|
+
if(ret < 0) {
|
404
|
+
rb_raise(eUnpackError, "parse error.");
|
405
|
+
} else if(ret > 0) {
|
406
|
+
mp->user.finished = 1;
|
407
|
+
return ULONG2NUM(from);
|
408
|
+
} else {
|
409
|
+
mp->user.finished = 0;
|
410
|
+
return ULONG2NUM(from);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
|
392
414
|
/* compat */
|
393
415
|
static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
|
394
416
|
VALUE off, VALUE limit)
|
395
417
|
{
|
396
418
|
CHECK_STRING_TYPE(data);
|
397
|
-
|
398
|
-
|
399
|
-
int ret = template_execute_wrap(mp, data, NUM2ULONG(limit), &from);
|
400
|
-
return INT2FIX(ret);
|
419
|
+
return MessagePack_Unpacker_execute_impl(self, data,
|
420
|
+
(size_t)NUM2ULONG(off), (size_t)NUM2ULONG(limit));
|
401
421
|
}
|
402
422
|
|
403
423
|
/* compat */
|
404
424
|
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
405
425
|
{
|
406
426
|
CHECK_STRING_TYPE(data);
|
407
|
-
|
408
|
-
|
409
|
-
int ret = template_execute_wrap(mp, data, RSTRING_LEN(data), &from);
|
410
|
-
return INT2FIX(ret);
|
427
|
+
return MessagePack_Unpacker_execute_impl(self, data,
|
428
|
+
(size_t)NUM2ULONG(off), (size_t)RSTRING_LEN(data));
|
411
429
|
}
|
412
430
|
|
413
431
|
/* compat */
|
data/test/msgpack_test.rb
CHANGED
@@ -204,9 +204,11 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
|
204
204
|
|
205
205
|
it "gc mark" do
|
206
206
|
obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"]
|
207
|
+
num = 4
|
208
|
+
raw = obj.to_msgpack * num
|
207
209
|
pac = MessagePack::Unpacker.new
|
208
210
|
parsed = 0
|
209
|
-
|
211
|
+
raw.split(//).each do |b|
|
210
212
|
pac.feed(b)
|
211
213
|
pac.each {|o|
|
212
214
|
GC.start
|
@@ -215,7 +217,31 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
|
215
217
|
}
|
216
218
|
GC.start
|
217
219
|
end
|
218
|
-
assert_equal(parsed,
|
220
|
+
assert_equal(parsed, num)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "streaming backward compatibility" do
|
224
|
+
obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"]
|
225
|
+
num = 4
|
226
|
+
raw = obj.to_msgpack * num
|
227
|
+
pac = MessagePack::Unpacker.new
|
228
|
+
buffer = ""
|
229
|
+
nread = 0
|
230
|
+
parsed = 0
|
231
|
+
raw.split(//).each do |b|
|
232
|
+
buffer << b
|
233
|
+
nread = pac.execute(buffer, nread)
|
234
|
+
if pac.finished?
|
235
|
+
o = pac.data
|
236
|
+
assert_equal(obj, o)
|
237
|
+
parsed += 1
|
238
|
+
pac.reset
|
239
|
+
buffer.slice!(0, nread)
|
240
|
+
nread = 0
|
241
|
+
next unless buffer.empty?
|
242
|
+
end
|
243
|
+
end
|
244
|
+
assert_equal(parsed, num)
|
219
245
|
end
|
220
246
|
|
221
247
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FURUHASHI Sadayuki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-23 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|