msgpack 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +6 -0
  3. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +4 -9
  4. data/ext/msgpack/buffer_class.c +4 -4
  5. data/ext/msgpack/extconf.rb +3 -1
  6. data/ext/msgpack/packer.c +1 -0
  7. data/ext/msgpack/packer_class.c +5 -19
  8. data/ext/msgpack/rbinit.c +1 -1
  9. data/ext/msgpack/unpacker.c +1 -0
  10. data/ext/msgpack/unpacker_class.c +5 -7
  11. data/lib/msgpack/buffer.rb +9 -0
  12. data/lib/msgpack/packer.rb +4 -0
  13. data/lib/msgpack/unpacker.rb +4 -0
  14. data/lib/msgpack/version.rb +1 -1
  15. data/lib/msgpack.rb +1 -0
  16. data/msgpack.gemspec +5 -2
  17. metadata +18 -47
  18. data/.github/workflows/ci.yaml +0 -57
  19. data/.gitignore +0 -23
  20. data/.rubocop.yml +0 -36
  21. data/Gemfile +0 -9
  22. data/Rakefile +0 -70
  23. data/appveyor.yml +0 -18
  24. data/bench/bench.rb +0 -78
  25. data/bin/console +0 -8
  26. data/doclib/msgpack/buffer.rb +0 -193
  27. data/doclib/msgpack/core_ext.rb +0 -101
  28. data/doclib/msgpack/error.rb +0 -19
  29. data/doclib/msgpack/extension_value.rb +0 -9
  30. data/doclib/msgpack/factory.rb +0 -145
  31. data/doclib/msgpack/packer.rb +0 -209
  32. data/doclib/msgpack/time.rb +0 -22
  33. data/doclib/msgpack/timestamp.rb +0 -44
  34. data/doclib/msgpack/unpacker.rb +0 -183
  35. data/doclib/msgpack.rb +0 -87
  36. data/msgpack.org.md +0 -46
  37. data/spec/bigint_spec.rb +0 -26
  38. data/spec/cases.json +0 -1
  39. data/spec/cases.msg +0 -0
  40. data/spec/cases_compact.msg +0 -0
  41. data/spec/cases_spec.rb +0 -39
  42. data/spec/cruby/buffer_io_spec.rb +0 -255
  43. data/spec/cruby/buffer_packer.rb +0 -29
  44. data/spec/cruby/buffer_spec.rb +0 -592
  45. data/spec/cruby/buffer_unpacker.rb +0 -19
  46. data/spec/cruby/unpacker_spec.rb +0 -70
  47. data/spec/ext_value_spec.rb +0 -99
  48. data/spec/exttypes.rb +0 -51
  49. data/spec/factory_spec.rb +0 -706
  50. data/spec/format_spec.rb +0 -301
  51. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  52. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  53. data/spec/jruby/unpacker_spec.rb +0 -186
  54. data/spec/msgpack_spec.rb +0 -214
  55. data/spec/pack_spec.rb +0 -61
  56. data/spec/packer_spec.rb +0 -575
  57. data/spec/random_compat.rb +0 -24
  58. data/spec/spec_helper.rb +0 -72
  59. data/spec/timestamp_spec.rb +0 -159
  60. data/spec/unpack_spec.rb +0 -57
  61. data/spec/unpacker_spec.rb +0 -869
@@ -1,592 +0,0 @@
1
- require 'spec_helper'
2
- require 'random_compat'
3
-
4
- require 'stringio'
5
- if defined?(Encoding)
6
- Encoding.default_external = 'ASCII-8BIT'
7
- end
8
-
9
- describe Buffer do
10
- STATIC_EXAMPLES = {}
11
- STATIC_EXAMPLES[:empty01] = ''
12
- STATIC_EXAMPLES[:empty02] = ''
13
- STATIC_EXAMPLES[:copy01] = 'short'
14
- STATIC_EXAMPLES[:copy02] = 'short'*2
15
- STATIC_EXAMPLES[:ref01] = 'short'*128
16
- STATIC_EXAMPLES[:ref02] = 'short'*128*2
17
- STATIC_EXAMPLES[:ref03] = 'a'*((1024*1024+2)*2)
18
- STATIC_EXAMPLES[:refcopy01] = 'short'*128
19
- STATIC_EXAMPLES[:expand01] = 'short'*1024
20
- STATIC_EXAMPLES[:expand02] = 'short'*(127+1024)
21
- STATIC_EXAMPLES[:offset01] = 'ort'+'short'
22
- STATIC_EXAMPLES[:offset02] = 'ort'+'short'*127
23
- STATIC_EXAMPLES[:offset03] = 'ort'+'short'*(126+1024)
24
-
25
- if ''.respond_to?(:force_encoding)
26
- STATIC_EXAMPLES.each_value {|v| v.force_encoding('ASCII-8BIT') }
27
- end
28
- STATIC_EXAMPLES.each_value {|v| v.freeze }
29
-
30
- r = Random.new
31
- random_seed = r.seed
32
- puts "buffer random seed: 0x#{random_seed.to_s(16)}"
33
-
34
- let :random_cases_examples do
35
- r = Random.new(random_seed)
36
- cases = {}
37
- examples = {}
38
-
39
- 10.times do |i|
40
- b = Buffer.new
41
- s = r.bytes(0)
42
- r.rand(3).times do
43
- n = r.rand(1024*1400)
44
- x = r.bytes(n)
45
- s << x
46
- b << x
47
- end
48
- r.rand(2).times do
49
- n = r.rand(1024*1400)
50
- b.read(n)
51
- s.slice!(0, n)
52
- end
53
- key = :"random#{"%02d" % i}"
54
- cases[key] = b
55
- examples[key] = s
56
- end
57
-
58
- [cases, examples]
59
- end
60
-
61
- let :static_cases do
62
- map = {}
63
- map[:empty01] = empty01
64
- map[:empty02] = empty02
65
- map[:copy01] = copy01
66
- map[:copy02] = copy02
67
- map[:ref01] = ref01
68
- map[:ref02] = ref02
69
- map[:ref03] = ref03
70
- map[:refcopy01] = refcopy01
71
- map[:expand01] = expand01
72
- map[:expand02] = expand02
73
- map[:offset01] = offset01
74
- map[:offset02] = offset02
75
- map[:offset03] = offset03
76
- map
77
- end
78
-
79
- let :static_examples do
80
- STATIC_EXAMPLES
81
- end
82
-
83
- let :random_cases do
84
- random_cases_examples[0]
85
- end
86
-
87
- let :random_examples do
88
- random_cases_examples[1]
89
- end
90
-
91
- let :cases do
92
- static_cases.merge(random_cases)
93
- end
94
-
95
- let :examples do
96
- static_examples.merge(random_examples)
97
- end
98
-
99
- let :case_keys do
100
- examples.keys
101
- end
102
-
103
- let :empty01 do
104
- Buffer.new
105
- end
106
-
107
- let :empty02 do
108
- b = Buffer.new
109
- b << 'a'
110
- b.read_all(1)
111
- b
112
- end
113
-
114
- let :copy01 do
115
- # one copy chunk
116
- b = Buffer.new
117
- b << 'short'
118
- b
119
- end
120
-
121
- let :copy02 do
122
- # one copy chunk
123
- b = Buffer.new
124
- b << 'short'
125
- b << 'short'
126
- b
127
- end
128
-
129
- let :expand02 do
130
- # one copy chunk / expanded
131
- b = Buffer.new
132
- 1024.times do
133
- b << 'short'
134
- end
135
- b
136
- end
137
-
138
- let :ref01 do
139
- # one reference chunk
140
- b = Buffer.new
141
- b << 'short'*128
142
- b.to_s
143
- b
144
- end
145
-
146
- let :ref02 do
147
- # two reference chunks
148
- b = Buffer.new
149
- b << 'short'*128
150
- b.to_s
151
- b << 'short'*128
152
- b.to_a
153
- b
154
- end
155
-
156
- let :ref03 do
157
- # two reference chunks
158
- b = Buffer.new
159
- b << 'a'*(1024*1024+2)
160
- b << 'a'*(1024*1024+2)
161
- b
162
- end
163
-
164
- let :refcopy01 do
165
- # one reference chunk + one copy chunk
166
- b = Buffer.new
167
- b << 'short'*127
168
- b.to_s
169
- b << 'short'
170
- b
171
- end
172
-
173
- let :expand01 do
174
- # one copy chunk / expanded
175
- b = Buffer.new
176
- 1024.times do
177
- b << 'short'
178
- end
179
- b
180
- end
181
-
182
- let :expand02 do
183
- # one reference chunk + one copy chunk / expanded
184
- b = Buffer.new
185
- b << 'short'*127
186
- b.to_s
187
- 1024.times do
188
- b << 'short'
189
- end
190
- b
191
- end
192
-
193
- let :offset01 do
194
- # one copy chunk / offset
195
- b = Buffer.new
196
- b << 'short'
197
- b << 'short'
198
- b.skip(2)
199
- b
200
- end
201
-
202
- let :offset02 do
203
- # one reference chunk / offset
204
- b = Buffer.new
205
- b << 'short'*127
206
- b.to_s
207
- b.skip(2)
208
- b << 'short'
209
- b
210
- end
211
-
212
- let :offset03 do
213
- # one reference chunk / offset + one copy chunk / expanded
214
- b = Buffer.new
215
- b << 'short'*127
216
- b.to_s
217
- 1024.times do
218
- b << 'short'
219
- end
220
- b.skip(2)
221
- b
222
- end
223
-
224
- it 'empty?' do
225
- empty01.empty?.should == true
226
- empty02.empty?.should == true
227
- end
228
-
229
- it 'size' do
230
- case_keys.each {|k|
231
- cases[k].size.should == examples[k].size
232
- }
233
- end
234
-
235
- it 'short write increments size' do
236
- case_keys.each {|k|
237
- sz = examples[k].size
238
- 10.times do |i|
239
- cases[k].write 'short'
240
- sz += 'short'.size
241
- cases[k].size.should == sz
242
- end
243
- }
244
- end
245
-
246
- it 'read with limit decrements size' do
247
- case_keys.each {|k|
248
- sz = examples[k].size
249
- next if sz < 2
250
-
251
- cases[k].read(1).should == examples[k][0,1]
252
- sz -= 1
253
- cases[k].size.should == sz
254
-
255
- cases[k].read(1).should == examples[k][1,1]
256
- sz -= 1
257
- cases[k].size.should == sz
258
- }
259
- end
260
-
261
- it 'read_all with limit decrements size' do
262
- case_keys.each {|k|
263
- sz = examples[k].size
264
- next if sz < 2
265
-
266
- cases[k].read_all(1).should == examples[k][0,1]
267
- sz -= 1
268
- cases[k].size.should == sz
269
-
270
- cases[k].read_all(1).should == examples[k][1,1]
271
- sz -= 1
272
- cases[k].size.should == sz
273
- }
274
- end
275
-
276
- it 'skip decrements size' do
277
- case_keys.each {|k|
278
- sz = examples[k].size
279
- next if sz < 2
280
-
281
- cases[k].skip(1).should == 1
282
- sz -= 1
283
- cases[k].size.should == sz
284
-
285
- cases[k].skip(1).should == 1
286
- sz -= 1
287
- cases[k].size.should == sz
288
- }
289
- end
290
-
291
- it 'skip_all decrements size' do
292
- case_keys.each {|k|
293
- sz = examples[k].size
294
- next if sz < 2
295
-
296
- cases[k].skip_all(1)
297
- sz -= 1
298
- cases[k].size.should == sz
299
-
300
- cases[k].skip_all(1)
301
- sz -= 1
302
- cases[k].size.should == sz
303
- }
304
- end
305
-
306
- it 'read_all against insufficient buffer raises EOFError and consumes nothing' do
307
- case_keys.each {|k|
308
- sz = examples[k].size
309
- lambda {
310
- cases[k].read_all(sz+1)
311
- }.should raise_error(EOFError)
312
- cases[k].size.should == sz
313
- }
314
- end
315
-
316
- it 'skip_all against insufficient buffer raises EOFError and consumes nothing' do
317
- case_keys.each {|k|
318
- sz = examples[k].size
319
- lambda {
320
- cases[k].skip_all(sz+1)
321
- }.should raise_error(EOFError)
322
- cases[k].size.should == sz
323
- }
324
- end
325
-
326
- it 'read against insufficient buffer consumes all buffer or return nil' do
327
- case_keys.each {|k|
328
- sz = examples[k].size
329
- if sz == 0
330
- cases[k].read(sz+1).should == nil
331
- else
332
- cases[k].read(sz+1).should == examples[k]
333
- end
334
- cases[k].size.should == 0
335
- }
336
- end
337
-
338
- it 'skip against insufficient buffer consumes all buffer' do
339
- case_keys.each {|k|
340
- sz = examples[k].size
341
- cases[k].skip(sz+1).should == examples[k].size
342
- cases[k].size.should == 0
343
- }
344
- end
345
-
346
- it 'read with no arguments consumes all buffer and returns string and do not return nil' do
347
- case_keys.each {|k|
348
- cases[k].read_all.should == examples[k]
349
- cases[k].size.should == 0
350
- }
351
- end
352
-
353
- it 'read_all with no arguments consumes all buffer and returns string' do
354
- case_keys.each {|k|
355
- cases[k].read_all.should == examples[k]
356
- cases[k].size.should == 0
357
- }
358
- end
359
-
360
- it 'to_s returns a string and consume nothing' do
361
- case_keys.each {|k|
362
- cases[k].to_s.should == examples[k]
363
- cases[k].size.should == examples[k].size
364
- }
365
- end
366
-
367
- it 'to_s and modify' do
368
- case_keys.each {|k|
369
- s = cases[k].to_s
370
- s << 'x'
371
- cases[k].to_s.should == examples[k]
372
- }
373
- end
374
-
375
- it 'big write and modify reference' do
376
- big2 = "a" * (1024*1024 + 2)
377
-
378
- case_keys.each {|k|
379
- big1 = "a" * (1024*1024 + 2)
380
- cases[k].write(big1)
381
- big1 << 'x'
382
- cases[k].read.should == examples[k] + big2
383
- }
384
- end
385
-
386
- it 'big write -> short write' do
387
- big1 = "a" * (1024*1024 + 2)
388
-
389
- case_keys.each {|k|
390
- sz = examples[k].size
391
-
392
- cases[k].write big1
393
- cases[k].size.should == sz + big1.size
394
-
395
- cases[k].write("c")
396
- cases[k].size.should == sz + big1.size + 1
397
-
398
- cases[k].read_all.should == examples[k] + big1 + "c"
399
- cases[k].size.should == 0
400
- cases[k].empty?.should == true
401
- }
402
- end
403
-
404
- it 'big write 2'do
405
- big1 = "a" * (1024*1024 + 2)
406
- big2 = "b" * (1024*1024 + 2)
407
-
408
- case_keys.each {|k|
409
- sz = examples[k].size
410
-
411
- cases[k].write big1
412
- cases[k].write big2
413
- cases[k].size.should == sz + big1.size + big2.size
414
-
415
- cases[k].read_all(sz + big1.size).should == examples[k] + big1
416
- cases[k].size.should == big2.size
417
-
418
- cases[k].read.should == big2
419
- cases[k].size.should == 0
420
- cases[k].empty?.should == true
421
- }
422
- end
423
-
424
- it 'read 0' do
425
- case_keys.each {|k|
426
- cases[k].read(0).should == ''
427
- cases[k].read.should == examples[k]
428
- }
429
- end
430
-
431
- it 'skip 0' do
432
- case_keys.each {|k|
433
- cases[k].skip(0).should == 0
434
- cases[k].read.should == examples[k]
435
- }
436
- end
437
-
438
- it 'read_all 0' do
439
- case_keys.each {|k|
440
- cases[k].read_all(0).should == ''
441
- cases[k].read_all.should == examples[k]
442
- }
443
- end
444
-
445
- it 'skip_all 0' do
446
- case_keys.each {|k|
447
- cases[k].skip_all(0)
448
- cases[k].read_all.should == examples[k]
449
- }
450
- end
451
-
452
- it 'write_to' do
453
- case_keys.each {|k|
454
- sio = StringIO.new
455
- cases[k].write_to(sio).should == examples[k].size
456
- cases[k].size.should == 0
457
- sio.string.should == examples[k]
458
- }
459
- end
460
-
461
- it 'random read/write' do
462
- r = Random.new(random_seed)
463
- s = r.bytes(0)
464
- b = Buffer.new
465
-
466
- 10.times {
467
- # write
468
- r.rand(4).times do
469
- n = r.rand(1024*1400)
470
- x = r.bytes(n)
471
- s << x
472
- b.write(x)
473
- end
474
-
475
- # read
476
- r.rand(3).times do
477
- n = r.rand(1024*1400)
478
- ex = s.slice!(0, n)
479
- ex = nil if ex.empty?
480
- x = b.read(n)
481
- x.size == ex.size if x != nil
482
- x.should == ex
483
- b.size.should == s.size
484
- end
485
- }
486
- end
487
-
488
- it 'random read_all/write' do
489
- r = Random.new(random_seed)
490
- s = r.bytes(0)
491
- b = Buffer.new
492
-
493
- 10.times {
494
- # write
495
- r.rand(4).times do
496
- n = r.rand(1024*1400)
497
- x = r.bytes(n)
498
- s << x
499
- b.write(x)
500
- end
501
-
502
- # read_all
503
- r.rand(3).times do
504
- n = r.rand(1024*1400)
505
- begin
506
- x = b.read_all(n)
507
- ex = s.slice!(0, n)
508
- x.size == n
509
- x.should == ex
510
- b.size.should == s.size
511
- rescue EOFError
512
- b.size.should == s.size
513
- b.read.should == s
514
- s.clear
515
- break
516
- end
517
- end
518
- }
519
- end
520
-
521
- it 'random skip write' do
522
- r = Random.new(random_seed)
523
- s = r.bytes(0)
524
- b = Buffer.new
525
-
526
- 10.times {
527
- # write
528
- r.rand(4).times do
529
- n = r.rand(1024*1400)
530
- x = r.bytes(n)
531
- s << x
532
- b.write(x)
533
- end
534
-
535
- # skip
536
- r.rand(3).times do
537
- n = r.rand(1024*1400)
538
- ex = s.slice!(0, n)
539
- b.skip(n).should == ex.size
540
- b.size.should == s.size
541
- end
542
- }
543
- end
544
-
545
- it 'random skip_all write' do
546
- r = Random.new(random_seed)
547
- s = r.bytes(0)
548
- b = Buffer.new
549
-
550
- 10.times {
551
- # write
552
- r.rand(4).times do
553
- n = r.rand(1024*1400)
554
- x = r.bytes(n)
555
- s << x
556
- b.write(x)
557
- end
558
-
559
- # skip_all
560
- r.rand(3).times do
561
- n = r.rand(1024*1400)
562
- begin
563
- b.skip_all(n)
564
- s.slice!(0, n)
565
- b.size.should == s.size
566
- ensure EOFError
567
- b.size.should == s.size
568
- b.read.should == s
569
- s.clear
570
- break
571
- end
572
- end
573
- }
574
- end
575
-
576
- it "defines a function for ObjectSpace.memsize_of" do
577
- skip "JRuby doesn't support ObjectSpace.memsize_of" if IS_JRUBY
578
-
579
- buffer = MessagePack::Buffer.new
580
- empty_size = ObjectSpace.memsize_of(buffer)
581
- expect(empty_size).to be < 400
582
- 10.times do
583
- buffer << "a" * 500
584
- end
585
- memsize = ObjectSpace.memsize_of(buffer)
586
- expect(memsize).to be > empty_size
587
- buffer.read(10)
588
- expect(ObjectSpace.memsize_of(buffer)).to be == memsize
589
- buffer.read_all
590
- expect(ObjectSpace.memsize_of(buffer)).to be == empty_size
591
- end
592
- end
@@ -1,19 +0,0 @@
1
- # encoding: ascii-8bit
2
- require 'spec_helper'
3
-
4
- describe Unpacker do
5
- let :unpacker do
6
- Unpacker.new
7
- end
8
-
9
- let :packer do
10
- Packer.new
11
- end
12
-
13
- it 'buffer' do
14
- o1 = unpacker.buffer.object_id
15
- unpacker.buffer << 'frsyuki'
16
- unpacker.buffer.to_s.should == 'frsyuki'
17
- unpacker.buffer.object_id.should == o1
18
- end
19
- end
@@ -1,70 +0,0 @@
1
- # encoding: ascii-8bit
2
- require 'spec_helper'
3
-
4
- describe Unpacker do
5
- let :unpacker do
6
- Unpacker.new
7
- end
8
-
9
- let :packer do
10
- Packer.new
11
- end
12
-
13
- it 'skip_nil succeeds' do
14
- unpacker.feed("\xc0")
15
- unpacker.skip_nil.should == true
16
- end
17
-
18
- it 'skip_nil fails' do
19
- unpacker.feed("\x90")
20
- unpacker.skip_nil.should == false
21
- end
22
-
23
- it 'skip skips objects' do
24
- packer.write(1)
25
- packer.write(2)
26
- packer.write(3)
27
- packer.write(4)
28
- packer.write(5)
29
-
30
- unpacker = Unpacker.new
31
- unpacker.feed(packer.to_s)
32
-
33
- unpacker.read.should == 1
34
- unpacker.skip
35
- unpacker.read.should == 3
36
- unpacker.skip
37
- unpacker.read.should == 5
38
- end
39
-
40
- it 'skip raises EOFError' do
41
- lambda {
42
- unpacker.skip
43
- }.should raise_error(EOFError)
44
- end
45
-
46
- it 'skip_nil raises EOFError' do
47
- lambda {
48
- unpacker.skip_nil
49
- }.should raise_error(EOFError)
50
- end
51
-
52
- it 'skip raises level stack too deep error' do
53
- 512.times { packer.write_array_header(1) }
54
- packer.write(nil)
55
-
56
- unpacker = Unpacker.new
57
- unpacker.feed(packer.to_s)
58
- lambda {
59
- unpacker.skip
60
- }.should raise_error(MessagePack::StackError)
61
- end
62
-
63
- it 'skip raises invalid byte error' do
64
- unpacker.feed("\xc1")
65
- lambda {
66
- unpacker.skip
67
- }.should raise_error(MessagePack::MalformedFormatError)
68
- end
69
- end
70
-