msgpack 0.7.0dev1-java → 0.7.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1074cd38a1217bb758be1ce482c293956f051c29
4
- data.tar.gz: 53cac06789fb384cf3407e61e7cbb5d4ef2f263b
3
+ metadata.gz: c1d1fa6b2057865db28f74f3aea49b89ef699c98
4
+ data.tar.gz: 3c9a9f7ffcf915ef89719801269bee1582dd0c8a
5
5
  SHA512:
6
- metadata.gz: 0d311e9a8d3729e29398660f0416d83a93e1d6c751851a0b240e11ec6ee18bd904d9b3ab2a249028a9591b8cb13281493eaf1fe7c97148ab56999be9bbea19f5
7
- data.tar.gz: 274602def6f21adeb764c70ac6b506ef72f245983c9c63ab12d977bbd981da9e94976858d583750cd55c2d4c93c4a5333f2103ed04fa8feaa68079261ea8a8b4
6
+ metadata.gz: 4aafb7193dc1418a1dfa0d83307b057c747035e06824f6acd9b577b413ce55c123371b861541987894469cc784e5e9a08236d57126708f33a169507b2ecb46d8
7
+ data.tar.gz: a6be87fb55c743a644e5efbda54944a2d1b84f39f01e896e04c2e974ab5d0e1a404f6428985750c9f2a33d283aa6592f913abb1aea7030673045146e43dd958b
Binary file
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.7.0dev1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -10,60 +10,6 @@ describe Unpacker do
10
10
  Packer.new
11
11
  end
12
12
 
13
- # TODO initialize
14
-
15
- it 'read_array_header succeeds' do
16
- unpacker.feed("\x91")
17
- unpacker.read_array_header.should == 1
18
- end
19
-
20
- it 'read_array_header fails' do
21
- unpacker.feed("\x81")
22
- lambda {
23
- unpacker.read_array_header
24
- }.should raise_error(MessagePack::TypeError) # TypeError is included in UnexpectedTypeError
25
- lambda {
26
- unpacker.read_array_header
27
- }.should raise_error(MessagePack::UnexpectedTypeError)
28
- end
29
-
30
- it 'read_map_header converts an map to key-value sequence' do
31
- packer.write_array_header(2)
32
- packer.write("e")
33
- packer.write(1)
34
- unpacker = Unpacker.new
35
- unpacker.feed(packer.to_s)
36
- unpacker.read_array_header.should == 2
37
- unpacker.read.should == "e"
38
- unpacker.read.should == 1
39
- end
40
-
41
- it 'read_map_header succeeds' do
42
- unpacker.feed("\x81")
43
- unpacker.read_map_header.should == 1
44
- end
45
-
46
- it 'read_map_header converts an map to key-value sequence' do
47
- packer.write_map_header(1)
48
- packer.write("k")
49
- packer.write("v")
50
- unpacker = Unpacker.new
51
- unpacker.feed(packer.to_s)
52
- unpacker.read_map_header.should == 1
53
- unpacker.read.should == "k"
54
- unpacker.read.should == "v"
55
- end
56
-
57
- it 'read_map_header fails' do
58
- unpacker.feed("\x91")
59
- lambda {
60
- unpacker.read_map_header
61
- }.should raise_error(MessagePack::TypeError) # TypeError is included in UnexpectedTypeError
62
- lambda {
63
- unpacker.read_map_header
64
- }.should raise_error(MessagePack::UnexpectedTypeError)
65
- end
66
-
67
13
  it 'skip_nil succeeds' do
68
14
  unpacker.feed("\xc0")
69
15
  unpacker.skip_nil.should == true
@@ -91,12 +37,6 @@ describe Unpacker do
91
37
  unpacker.read.should == 5
92
38
  end
93
39
 
94
- it 'read raises EOFError' do
95
- lambda {
96
- unpacker.read
97
- }.should raise_error(EOFError)
98
- end
99
-
100
40
  it 'skip raises EOFError' do
101
41
  lambda {
102
42
  unpacker.skip
@@ -109,88 +49,6 @@ describe Unpacker do
109
49
  }.should raise_error(EOFError)
110
50
  end
111
51
 
112
- let :sample_object do
113
- [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
114
- end
115
-
116
- it 'feed and each continue internal state' do
117
- raw = sample_object.to_msgpack.to_s * 4
118
- objects = []
119
-
120
- raw.split(//).each do |b|
121
- unpacker.feed(b)
122
- unpacker.each {|c|
123
- objects << c
124
- }
125
- end
126
-
127
- objects.should == [sample_object] * 4
128
- end
129
-
130
- it 'feed_each continues internal state' do
131
- raw = sample_object.to_msgpack.to_s * 4
132
- objects = []
133
-
134
- raw.split(//).each do |b|
135
- unpacker.feed_each(b) {|c|
136
- objects << c
137
- }
138
- end
139
-
140
- objects.should == [sample_object] * 4
141
- end
142
-
143
- it 'feed_each enumerator' do
144
- raw = sample_object.to_msgpack.to_s * 4
145
-
146
- unpacker.feed_each(raw).to_a.should == [sample_object] * 4
147
- end
148
-
149
- it 'reset clears internal buffer' do
150
- # 1-element array
151
- unpacker.feed("\x91")
152
- unpacker.reset
153
- unpacker.feed("\x01")
154
-
155
- unpacker.each.map {|x| x }.should == [1]
156
- end
157
-
158
- it 'reset clears internal state' do
159
- # 1-element array
160
- unpacker.feed("\x91")
161
- unpacker.each.map {|x| x }.should == []
162
-
163
- unpacker.reset
164
-
165
- unpacker.feed("\x01")
166
- unpacker.each.map {|x| x }.should == [1]
167
- end
168
-
169
- it 'frozen short strings' do
170
- raw = sample_object.to_msgpack.to_s.force_encoding('UTF-8')
171
- lambda {
172
- unpacker.feed_each(raw.freeze) { }
173
- }.should_not raise_error
174
- end
175
-
176
- it 'frozen long strings' do
177
- raw = (sample_object.to_msgpack.to_s * 10240).force_encoding('UTF-8')
178
- lambda {
179
- unpacker.feed_each(raw.freeze) { }
180
- }.should_not raise_error
181
- end
182
-
183
- it 'read raises level stack too deep error' do
184
- 512.times { packer.write_array_header(1) }
185
- packer.write(nil)
186
-
187
- unpacker = Unpacker.new
188
- unpacker.feed(packer.to_s)
189
- lambda {
190
- unpacker.read
191
- }.should raise_error(MessagePack::StackError)
192
- end
193
-
194
52
  it 'skip raises level stack too deep error' do
195
53
  512.times { packer.write_array_header(1) }
196
54
  packer.write(nil)
@@ -202,116 +60,11 @@ describe Unpacker do
202
60
  }.should raise_error(MessagePack::StackError)
203
61
  end
204
62
 
205
- it 'read raises invalid byte error' do
206
- unpacker.feed("\xc1")
207
- lambda {
208
- unpacker.read
209
- }.should raise_error(MessagePack::MalformedFormatError)
210
- end
211
-
212
63
  it 'skip raises invalid byte error' do
213
64
  unpacker.feed("\xc1")
214
65
  lambda {
215
66
  unpacker.skip
216
67
  }.should raise_error(MessagePack::MalformedFormatError)
217
68
  end
218
-
219
- it "gc mark" do
220
- raw = sample_object.to_msgpack.to_s * 4
221
-
222
- n = 0
223
- raw.split(//).each do |b|
224
- GC.start
225
- unpacker.feed_each(b) {|o|
226
- GC.start
227
- o.should == sample_object
228
- n += 1
229
- }
230
- GC.start
231
- end
232
-
233
- n.should == 4
234
- end
235
-
236
- it "buffer" do
237
- orig = "a"*32*1024*4
238
- raw = orig.to_msgpack.to_s
239
-
240
- n = 655
241
- times = raw.size / n
242
- times += 1 unless raw.size % n == 0
243
-
244
- off = 0
245
- parsed = false
246
-
247
- times.times do
248
- parsed.should == false
249
-
250
- seg = raw[off, n]
251
- off += seg.length
252
-
253
- unpacker.feed_each(seg) {|obj|
254
- parsed.should == false
255
- obj.should == orig
256
- parsed = true
257
- }
258
- end
259
-
260
- parsed.should == true
261
- end
262
-
263
- it 'MessagePack.unpack symbolize_keys' do
264
- symbolized_hash = {:a => 'b', :c => 'd'}
265
- MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
266
- MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
267
- end
268
-
269
- it 'Unpacker#unpack symbolize_keys' do
270
- unpacker = Unpacker.new(:symbolize_keys => true)
271
- symbolized_hash = {:a => 'b', :c => 'd'}
272
- unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
273
- end
274
-
275
- it "msgpack str 8 type" do
276
- MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
277
- MessagePack.unpack([0xd9, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
278
- MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
279
- MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
280
- end
281
-
282
- it "msgpack str 16 type" do
283
- MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
284
- MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
285
- MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
286
- MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
287
- end
288
-
289
- it "msgpack str 32 type" do
290
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
291
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
292
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
293
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
294
- end
295
-
296
- it "msgpack bin 8 type" do
297
- MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
298
- MessagePack.unpack([0xc4, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
299
- MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
300
- MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
301
- end
302
-
303
- it "msgpack bin 16 type" do
304
- MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
305
- MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
306
- MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
307
- MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
308
- end
309
-
310
- it "msgpack bin 32 type" do
311
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
312
- MessagePack.unpack([0xc6, 0x0, 0x00, 0x00, 0x000].pack('C*')).encoding.should == Encoding::ASCII_8BIT
313
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
314
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
315
- end
316
69
  end
317
70
 
@@ -1,8 +1,6 @@
1
1
  # encoding: ascii-8bit
2
2
  require 'spec_helper'
3
3
 
4
- eval("return") if java?
5
-
6
4
  describe MessagePack::Factory do
7
5
  subject do
8
6
  described_class.new
@@ -220,7 +218,6 @@ describe MessagePack::Factory do
220
218
  require_relative 'exttypes'
221
219
 
222
220
  it 'should be referred by MessagePack.pack and MessagePack.unpack' do
223
- skip("not supported yet in JRuby implementation") if java?
224
221
  MessagePack::DefaultFactory.register_type(DummyTimeStamp1::TYPE, DummyTimeStamp1)
225
222
  MessagePack::DefaultFactory.register_type(DummyTimeStamp2::TYPE, DummyTimeStamp2, packer: :serialize, unpacker: :deserialize)
226
223
 
@@ -2,43 +2,35 @@
2
2
 
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
- require 'spec_helper'
6
5
 
6
+ require 'spec_helper'
7
7
 
8
- describe ::MessagePack::Unpacker do
9
- def flatten(struct, results = [])
10
- case struct
11
- when Array
12
- struct.each { |v| flatten(v, results) }
13
- when Hash
14
- struct.each { |k, v| flatten(v, flatten(k, results)) }
15
- else
16
- results << struct
17
- end
18
- results
8
+ describe MessagePack::Unpacker do
9
+ let :unpacker do
10
+ MessagePack::Unpacker.new
19
11
  end
20
12
 
21
- subject do
22
- described_class.new
13
+ let :packer do
14
+ MessagePack::Packer.new
23
15
  end
24
-
16
+
25
17
  let :buffer1 do
26
18
  MessagePack.pack(:foo => 'bar')
27
19
  end
28
-
20
+
29
21
  let :buffer2 do
30
22
  MessagePack.pack(:hello => {:world => [1, 2, 3]})
31
23
  end
32
-
24
+
33
25
  let :buffer3 do
34
26
  MessagePack.pack(:x => 'y')
35
27
  end
36
-
28
+
37
29
  describe '#execute/#execute_limit/#finished?' do
38
30
  let :buffer do
39
31
  buffer1 + buffer2 + buffer3
40
32
  end
41
-
33
+
42
34
  it 'extracts an object from the buffer' do
43
35
  subject.execute(buffer, 0)
44
36
  subject.data.should == {'foo' => 'bar'}
@@ -53,7 +45,7 @@ describe ::MessagePack::Unpacker do
53
45
  subject.execute_limit(buffer, buffer1.length, buffer2.length)
54
46
  subject.data.should == {'hello' => {'world' => [1, 2, 3]}}
55
47
  end
56
-
48
+
57
49
  it 'extracts nothing if the limit cuts an object in half' do
58
50
  subject.execute_limit(buffer, buffer1.length, 3)
59
51
  subject.data.should be_nil
@@ -63,63 +55,17 @@ describe ::MessagePack::Unpacker do
63
55
  subject.execute(buffer, 0).should == buffer1.length
64
56
  subject.execute(buffer, buffer1.length).should == buffer1.length + buffer2.length
65
57
  end
66
-
58
+
67
59
  it 'is finished if #data returns an object' do
68
60
  subject.execute_limit(buffer, buffer1.length, buffer2.length)
69
61
  subject.should be_finished
70
-
62
+
71
63
  subject.execute_limit(buffer, buffer1.length, 3)
72
64
  subject.should_not be_finished
73
65
  end
74
66
  end
75
67
 
76
- describe '#read' do
77
- context 'with a buffer' do
78
- it 'reads objects' do
79
- objects = []
80
- subject.feed(buffer1)
81
- subject.feed(buffer2)
82
- subject.feed(buffer3)
83
- objects << subject.read
84
- objects << subject.read
85
- objects << subject.read
86
- objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
87
- end
88
-
89
- it 'reads map header' do
90
- subject.feed({}.to_msgpack)
91
- subject.read_map_header.should == 0
92
- end
93
-
94
- it 'reads array header' do
95
- subject.feed([].to_msgpack)
96
- subject.read_array_header.should == 0
97
- end
98
- end
99
- end
100
-
101
68
  describe '#each' do
102
- context 'with a buffer' do
103
- it 'yields each object in the buffer' do
104
- objects = []
105
- subject.feed(buffer1)
106
- subject.feed(buffer2)
107
- subject.feed(buffer3)
108
- subject.each do |obj|
109
- objects << obj
110
- end
111
- objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
112
- end
113
-
114
- it 'returns an enumerator when no block is given' do
115
- subject.feed(buffer1)
116
- subject.feed(buffer2)
117
- subject.feed(buffer3)
118
- enum = subject.each
119
- enum.map { |obj| obj.keys.first }.should == %w[foo hello x]
120
- end
121
- end
122
-
123
69
  context 'with a StringIO stream' do
124
70
  it 'yields each object in the stream' do
125
71
  objects = []
@@ -130,7 +76,7 @@ describe ::MessagePack::Unpacker do
130
76
  objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
131
77
  end
132
78
  end
133
-
79
+
134
80
  context 'with a File stream' do
135
81
  it 'yields each object in the stream' do
136
82
  objects = []
@@ -146,40 +92,8 @@ describe ::MessagePack::Unpacker do
146
92
  objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
147
93
  end
148
94
  end
149
-
150
- context 'with a stream passed to the constructor' do
151
- it 'yields each object in the stream' do
152
- objects = []
153
- unpacker = described_class.new(StringIO.new(buffer1 + buffer2 + buffer3))
154
- unpacker.each do |obj|
155
- objects << obj
156
- end
157
- objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
158
- end
159
- end
160
95
  end
161
-
162
- describe '#feed_each' do
163
- it 'feeds the buffer then runs #each' do
164
- objects = []
165
- subject.feed_each(buffer1 + buffer2 + buffer3) do |obj|
166
- objects << obj
167
- end
168
- objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
169
- end
170
96
 
171
- it 'handles chunked data' do
172
- objects = []
173
- buffer = buffer1 + buffer2 + buffer3
174
- buffer.chars.each do |ch|
175
- subject.feed_each(ch) do |obj|
176
- objects << obj
177
- end
178
- end
179
- objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
180
- end
181
- end
182
-
183
97
  describe '#fill' do
184
98
  it 'is a no-op' do
185
99
  subject.stream = StringIO.new(buffer1 + buffer2 + buffer3)
@@ -187,22 +101,17 @@ describe ::MessagePack::Unpacker do
187
101
  subject.each { |obj| }
188
102
  end
189
103
  end
190
-
191
- describe '#reset' do
192
- context 'with a buffer' do
193
- it 'is unclear what it is supposed to do'
194
- end
195
-
196
- context 'with a stream' do
197
- it 'is unclear what it is supposed to do'
198
- end
199
- end
200
104
 
201
- context 'regressions' do
202
- it 'handles massive arrays (issue #2)' do
203
- array = ['foo'] * 10_000
204
- MessagePack.unpack(MessagePack.pack(array)).should have(10_000).items
105
+ def flatten(struct, results = [])
106
+ case struct
107
+ when Array
108
+ struct.each { |v| flatten(v, results) }
109
+ when Hash
110
+ struct.each { |k, v| flatten(v, flatten(k, results)) }
111
+ else
112
+ results << struct
205
113
  end
114
+ results
206
115
  end
207
116
 
208
117
  context 'encoding', :encodings do
@@ -229,15 +138,15 @@ describe ::MessagePack::Unpacker do
229
138
  Encoding.default_external = Encoding::ISO_8859_1
230
139
  end
231
140
 
232
- it 'produces results with default internal encoding' do
141
+ it 'produces results with encoding as binary or string(utf8)' do
233
142
  unpacker.execute(buffer, 0)
234
143
  strings = flatten(unpacker.data).grep(String)
235
- strings.map(&:encoding).uniq.should == [Encoding.default_internal]
144
+ strings.map(&:encoding).uniq.sort{|a,b| a.to_s <=> b.to_s}.should == [Encoding::ASCII_8BIT, Encoding::UTF_8]
236
145
  end
237
146
 
238
147
  it 'recodes to internal encoding' do
239
148
  unpacker.execute(buffer, 0)
240
- unpacker.data['nested'][1].keys.should == ["sk\xC3\xA5l".force_encoding(Encoding.default_internal)]
149
+ unpacker.data['nested'][1].keys.should == ["sk\xC3\xA5l".force_encoding(Encoding::UTF_8)]
241
150
  end
242
151
  end
243
152
 
@@ -255,23 +164,6 @@ describe ::MessagePack::Unpacker do
255
164
  unpacker.execute(buffer, 0)
256
165
  unpacker.data.should == {:hello => 'world', :nested => ['object', {:structure => true}]}
257
166
  end
258
-
259
- it 'can symbolize keys when using #each' do
260
- objs = []
261
- unpacker.feed(buffer)
262
- unpacker.each do |obj|
263
- objs << obj
264
- end
265
- objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}]
266
- end
267
-
268
- it 'can symbolize keys when using #feed_each' do
269
- objs = []
270
- unpacker.feed_each(buffer) do |obj|
271
- objs << obj
272
- end
273
- objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}]
274
- end
275
167
  end
276
168
 
277
169
  context 'encoding', :encodings do
@@ -280,35 +172,14 @@ describe ::MessagePack::Unpacker do
280
172
  end
281
173
 
282
174
  let :unpacker do
283
- described_class.new(:encoding => 'UTF-8')
175
+ described_class.new()
284
176
  end
285
177
 
286
- it 'can hardcode encoding when using #execute' do
178
+ it 'decode binary as ascii-8bit string when using #execute' do
287
179
  unpacker.execute(buffer, 0)
288
180
  strings = flatten(unpacker.data).grep(String)
289
181
  strings.should == %w[hello world nested object structure]
290
- strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
291
- end
292
-
293
- it 'can hardcode encoding when using #each' do
294
- objs = []
295
- unpacker.feed(buffer)
296
- unpacker.each do |obj|
297
- objs << obj
298
- end
299
- strings = flatten(objs).grep(String)
300
- strings.should == %w[hello world nested object structure]
301
- strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
302
- end
303
-
304
- it 'can hardcode encoding when using #feed_each' do
305
- objs = []
306
- unpacker.feed_each(buffer) do |obj|
307
- objs << obj
308
- end
309
- strings = flatten(objs).grep(String)
310
- strings.should == %w[hello world nested object structure]
311
- strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
182
+ strings.map(&:encoding).uniq.should == [Encoding::ASCII_8BIT]
312
183
  end
313
184
  end
314
185
  end