msgpack 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/unpack.c +11 -2
- data/lib/msgpack/version.rb +1 -1
- data/msgpack/unpack_define.h +3 -1
- metadata +4 -4
- data/test/test_format.rb +0 -142
data/ext/unpack.c
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
|
22
22
|
typedef struct {
|
23
23
|
int finished;
|
24
|
+
VALUE origstr;
|
24
25
|
} msgpack_unpack_context;
|
25
26
|
|
26
27
|
|
@@ -104,7 +105,7 @@ static inline void template_callback_map_item(msgpack_unpack_context* x, VALUE*
|
|
104
105
|
{ rb_hash_aset(*c, k, v); }
|
105
106
|
|
106
107
|
static inline VALUE template_callback_raw(msgpack_unpack_context* x, const char* b, const char* p, unsigned int l)
|
107
|
-
{ return rb_str_new(p, l); }
|
108
|
+
{ return l == 0 ? rb_str_new(0,0) : rb_str_substr(x->origstr, p - b, l); }
|
108
109
|
|
109
110
|
|
110
111
|
#include "msgpack/unpack_template.h"
|
@@ -152,8 +153,9 @@ static VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
|
152
153
|
static VALUE MessagePack_Unpacker_reset(VALUE self)
|
153
154
|
{
|
154
155
|
UNPACKER(self, mp);
|
155
|
-
mp->user.finished = 0;
|
156
156
|
msgpack_unpacker_init(mp);
|
157
|
+
msgpack_unpack_context ctx = {0, Qnil};
|
158
|
+
mp->user = ctx;
|
157
159
|
return self;
|
158
160
|
}
|
159
161
|
|
@@ -179,7 +181,9 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
|
|
179
181
|
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
|
180
182
|
}
|
181
183
|
|
184
|
+
mp->user.origstr = data;
|
182
185
|
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
|
186
|
+
mp->user.origstr = Qnil;
|
183
187
|
|
184
188
|
if(ret < 0) {
|
185
189
|
rb_raise(eUnpackError, "parse error.");
|
@@ -239,7 +243,9 @@ static VALUE MessagePack_unpack_impl(VALUE args)
|
|
239
243
|
long dlen = RSTRING_LEN(data);
|
240
244
|
int ret;
|
241
245
|
|
246
|
+
mp->user.origstr = data;
|
242
247
|
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
|
248
|
+
mp->user.origstr = Qnil;
|
243
249
|
|
244
250
|
if(ret < 0) {
|
245
251
|
rb_raise(eUnpackError, "parse error.");
|
@@ -268,6 +274,9 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
|
268
274
|
CHECK_STRING_TYPE(data);
|
269
275
|
msgpack_unpacker mp;
|
270
276
|
msgpack_unpacker_init(&mp);
|
277
|
+
msgpack_unpack_context ctx = {0, Qnil};
|
278
|
+
mp.user = ctx;
|
279
|
+
|
271
280
|
rb_gc_disable();
|
272
281
|
VALUE args[2] = {(VALUE)&mp, data};
|
273
282
|
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
data/lib/msgpack/version.rb
CHANGED
data/msgpack/unpack_define.h
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
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: 2008-12-
|
12
|
+
date: 2008-12-10 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -87,5 +87,5 @@ rubygems_version: 1.3.1
|
|
87
87
|
signing_key:
|
88
88
|
specification_version: 2
|
89
89
|
summary: An object-oriented parser generator based on Parser Expression Grammar
|
90
|
-
test_files:
|
91
|
-
|
90
|
+
test_files: []
|
91
|
+
|
data/test/test_format.rb
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
class MessagePackTestFormat < Test::Unit::TestCase
|
5
|
-
def self.it(name, &block)
|
6
|
-
define_method("test_#{name}", &block)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "nil" do
|
10
|
-
check 1, nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "true" do
|
14
|
-
check 1, true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "false" do
|
18
|
-
check 1, false
|
19
|
-
end
|
20
|
-
|
21
|
-
it "zero" do
|
22
|
-
check 1, 0
|
23
|
-
end
|
24
|
-
|
25
|
-
it "positive fixnum" do
|
26
|
-
check 1, 1
|
27
|
-
check 1, (1<<6)
|
28
|
-
check 1, (1<<7)-1
|
29
|
-
end
|
30
|
-
|
31
|
-
it "positive int 8" do
|
32
|
-
check 1, -1
|
33
|
-
check 2, (1<<7)
|
34
|
-
check 2, (1<<8)-1
|
35
|
-
end
|
36
|
-
|
37
|
-
it "positive int 16" do
|
38
|
-
check 3, (1<<8)
|
39
|
-
check 3, (1<<16)-1
|
40
|
-
end
|
41
|
-
|
42
|
-
it "positive int 32" do
|
43
|
-
check 5, (1<<16)
|
44
|
-
check 5, (1<<32)-1
|
45
|
-
end
|
46
|
-
|
47
|
-
it "positive int 64" do
|
48
|
-
check 9, (1<<32)
|
49
|
-
check 9, (1<<64)-1
|
50
|
-
end
|
51
|
-
|
52
|
-
it "negative fixnum" do
|
53
|
-
check 1, -1
|
54
|
-
check 1, -((1<<5)-1)
|
55
|
-
check 1, -(1<<5)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "negative int 8" do
|
59
|
-
check 2, -((1<<5)+1)
|
60
|
-
check 2, -(1<<7)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "negative int 16" do
|
64
|
-
check 3, -((1<<7)+1)
|
65
|
-
check 3, -(1<<15)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "negative int 32" do
|
69
|
-
check 5, -((1<<15)+1)
|
70
|
-
check 5, -(1<<31)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "negative int 64" do
|
74
|
-
check 9, -((1<<31)+1)
|
75
|
-
check 9, -(1<<63)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "fixraw" do
|
79
|
-
check_raw 1, 0
|
80
|
-
check_raw 1, (1<<5)-1
|
81
|
-
end
|
82
|
-
|
83
|
-
it "raw 16" do
|
84
|
-
check_raw 3, (1<<5)
|
85
|
-
check_raw 3, (1<<16)-1
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raw 32" do
|
89
|
-
check_raw 5, (1<<16)
|
90
|
-
#check_raw 5, (1<<32)-1 # memory error
|
91
|
-
end
|
92
|
-
|
93
|
-
it "fixarray" do
|
94
|
-
check_array 1, 0
|
95
|
-
check_array 1, (1<<4)-1
|
96
|
-
end
|
97
|
-
|
98
|
-
it "array 16" do
|
99
|
-
check_array 3, (1<<4)
|
100
|
-
check_array 3, (1<<16)-1
|
101
|
-
end
|
102
|
-
|
103
|
-
it "array 32" do
|
104
|
-
check_array 5, (1<<16)
|
105
|
-
#check_array 5, (1<<32)-1 # memory error
|
106
|
-
end
|
107
|
-
|
108
|
-
# it "fixmap" do
|
109
|
-
# check_map 1, 0
|
110
|
-
# check_map 1, (1<<4)-1
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# it "map 16" do
|
114
|
-
# check_map 3, (1<<4)
|
115
|
-
# check_map 3, (1<<16)-1
|
116
|
-
# end
|
117
|
-
#
|
118
|
-
# it "map 32" do
|
119
|
-
# check_map 5, (1<<16)
|
120
|
-
# #check_map 5, (1<<32)-1 # memory error
|
121
|
-
# end
|
122
|
-
|
123
|
-
private
|
124
|
-
def check(len, obj)
|
125
|
-
v = obj.to_msgpack
|
126
|
-
assert_equal(v.length, len)
|
127
|
-
assert_equal(MessagePack.unpack(v), obj)
|
128
|
-
end
|
129
|
-
|
130
|
-
def check_raw(overhead, num)
|
131
|
-
check num+overhead, " "*num
|
132
|
-
end
|
133
|
-
|
134
|
-
def check_array(overhead, num)
|
135
|
-
check num+overhead, Array.new(num)
|
136
|
-
end
|
137
|
-
|
138
|
-
def check_map(overhead, num)
|
139
|
-
# FIXME
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|