msgpack 0.6.0pre1-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +26 -0
  4. data/ChangeLog +117 -0
  5. data/Dockerfile +30 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +177 -0
  8. data/README.rdoc +129 -0
  9. data/Rakefile +114 -0
  10. data/bench/pack.rb +23 -0
  11. data/bench/pack_log.rb +33 -0
  12. data/bench/pack_log_long.rb +65 -0
  13. data/bench/run.sh +14 -0
  14. data/bench/run_long.sh +35 -0
  15. data/bench/unpack.rb +21 -0
  16. data/bench/unpack_log.rb +34 -0
  17. data/bench/unpack_log_long.rb +67 -0
  18. data/cross-build.sh +9 -0
  19. data/doclib/msgpack/buffer.rb +193 -0
  20. data/doclib/msgpack/core_ext.rb +101 -0
  21. data/doclib/msgpack/error.rb +14 -0
  22. data/doclib/msgpack/packer.rb +134 -0
  23. data/doclib/msgpack/unpacker.rb +146 -0
  24. data/doclib/msgpack.rb +77 -0
  25. data/ext/java/org/msgpack/jruby/Buffer.java +221 -0
  26. data/ext/java/org/msgpack/jruby/Decoder.java +201 -0
  27. data/ext/java/org/msgpack/jruby/Encoder.java +308 -0
  28. data/ext/java/org/msgpack/jruby/ExtensionValue.java +136 -0
  29. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +107 -0
  30. data/ext/java/org/msgpack/jruby/Packer.java +78 -0
  31. data/ext/java/org/msgpack/jruby/Types.java +37 -0
  32. data/ext/java/org/msgpack/jruby/Unpacker.java +170 -0
  33. data/ext/msgpack/buffer.c +695 -0
  34. data/ext/msgpack/buffer.h +447 -0
  35. data/ext/msgpack/buffer_class.c +507 -0
  36. data/ext/msgpack/buffer_class.h +32 -0
  37. data/ext/msgpack/compat.h +113 -0
  38. data/ext/msgpack/core_ext.c +129 -0
  39. data/ext/msgpack/core_ext.h +26 -0
  40. data/ext/msgpack/extconf.rb +28 -0
  41. data/ext/msgpack/packer.c +168 -0
  42. data/ext/msgpack/packer.h +441 -0
  43. data/ext/msgpack/packer_class.c +302 -0
  44. data/ext/msgpack/packer_class.h +30 -0
  45. data/ext/msgpack/rbinit.c +33 -0
  46. data/ext/msgpack/rmem.c +94 -0
  47. data/ext/msgpack/rmem.h +109 -0
  48. data/ext/msgpack/sysdep.h +115 -0
  49. data/ext/msgpack/sysdep_endian.h +50 -0
  50. data/ext/msgpack/sysdep_types.h +46 -0
  51. data/ext/msgpack/unpacker.c +771 -0
  52. data/ext/msgpack/unpacker.h +122 -0
  53. data/ext/msgpack/unpacker_class.c +405 -0
  54. data/ext/msgpack/unpacker_class.h +32 -0
  55. data/lib/msgpack/msgpack.so +0 -0
  56. data/lib/msgpack/version.rb +3 -0
  57. data/lib/msgpack.rb +13 -0
  58. data/msgpack.gemspec +31 -0
  59. data/msgpack.org.md +46 -0
  60. data/spec/cases.json +1 -0
  61. data/spec/cases.msg +0 -0
  62. data/spec/cases_compact.msg +0 -0
  63. data/spec/cases_spec.rb +39 -0
  64. data/spec/cruby/buffer_io_spec.rb +256 -0
  65. data/spec/cruby/buffer_packer.rb +29 -0
  66. data/spec/cruby/buffer_spec.rb +572 -0
  67. data/spec/cruby/buffer_unpacker.rb +19 -0
  68. data/spec/cruby/packer_spec.rb +120 -0
  69. data/spec/cruby/unpacker_spec.rb +305 -0
  70. data/spec/format_spec.rb +282 -0
  71. data/spec/jruby/benchmarks/shootout_bm.rb +73 -0
  72. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +25 -0
  73. data/spec/jruby/msgpack/unpacker_spec.rb +290 -0
  74. data/spec/jruby/msgpack_spec.rb +142 -0
  75. data/spec/pack_spec.rb +67 -0
  76. data/spec/random_compat.rb +24 -0
  77. data/spec/spec_helper.rb +27 -0
  78. data/spec/unpack_spec.rb +60 -0
  79. metadata +209 -0
@@ -0,0 +1,305 @@
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
+ # 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)
25
+ end
26
+
27
+ it 'read_map_header converts an map to key-value sequence' do
28
+ packer.write_array_header(2)
29
+ packer.write("e")
30
+ packer.write(1)
31
+ unpacker = Unpacker.new
32
+ unpacker.feed(packer.to_s)
33
+ unpacker.read_array_header.should == 2
34
+ unpacker.read.should == "e"
35
+ unpacker.read.should == 1
36
+ end
37
+
38
+ it 'read_map_header succeeds' do
39
+ unpacker.feed("\x81")
40
+ unpacker.read_map_header.should == 1
41
+ end
42
+
43
+ it 'read_map_header converts an map to key-value sequence' do
44
+ packer.write_map_header(1)
45
+ packer.write("k")
46
+ packer.write("v")
47
+ unpacker = Unpacker.new
48
+ unpacker.feed(packer.to_s)
49
+ unpacker.read_map_header.should == 1
50
+ unpacker.read.should == "k"
51
+ unpacker.read.should == "v"
52
+ end
53
+
54
+ it 'read_map_header fails' do
55
+ unpacker.feed("\x91")
56
+ lambda {
57
+ unpacker.read_map_header
58
+ }.should raise_error(MessagePack::TypeError)
59
+ end
60
+
61
+ it 'skip_nil succeeds' do
62
+ unpacker.feed("\xc0")
63
+ unpacker.skip_nil.should == true
64
+ end
65
+
66
+ it 'skip_nil fails' do
67
+ unpacker.feed("\x90")
68
+ unpacker.skip_nil.should == false
69
+ end
70
+
71
+ it 'skip skips objects' do
72
+ packer.write(1)
73
+ packer.write(2)
74
+ packer.write(3)
75
+ packer.write(4)
76
+ packer.write(5)
77
+
78
+ unpacker = Unpacker.new
79
+ unpacker.feed(packer.to_s)
80
+
81
+ unpacker.read.should == 1
82
+ unpacker.skip
83
+ unpacker.read.should == 3
84
+ unpacker.skip
85
+ unpacker.read.should == 5
86
+ end
87
+
88
+ it 'read raises EOFError' do
89
+ lambda {
90
+ unpacker.read
91
+ }.should raise_error(EOFError)
92
+ end
93
+
94
+ it 'skip raises EOFError' do
95
+ lambda {
96
+ unpacker.skip
97
+ }.should raise_error(EOFError)
98
+ end
99
+
100
+ it 'skip_nil raises EOFError' do
101
+ lambda {
102
+ unpacker.skip_nil
103
+ }.should raise_error(EOFError)
104
+ end
105
+
106
+ let :sample_object do
107
+ [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
108
+ end
109
+
110
+ it 'feed and each continue internal state' do
111
+ raw = sample_object.to_msgpack.to_s * 4
112
+ objects = []
113
+
114
+ raw.split(//).each do |b|
115
+ unpacker.feed(b)
116
+ unpacker.each {|c|
117
+ objects << c
118
+ }
119
+ end
120
+
121
+ objects.should == [sample_object] * 4
122
+ end
123
+
124
+ it 'feed_each continues internal state' do
125
+ raw = sample_object.to_msgpack.to_s * 4
126
+ objects = []
127
+
128
+ raw.split(//).each do |b|
129
+ unpacker.feed_each(b) {|c|
130
+ objects << c
131
+ }
132
+ end
133
+
134
+ objects.should == [sample_object] * 4
135
+ end
136
+
137
+ it 'reset clears internal buffer' do
138
+ # 1-element array
139
+ unpacker.feed("\x91")
140
+ unpacker.reset
141
+ unpacker.feed("\x01")
142
+
143
+ unpacker.each.map {|x| x }.should == [1]
144
+ end
145
+
146
+ it 'reset clears internal state' do
147
+ # 1-element array
148
+ unpacker.feed("\x91")
149
+ unpacker.each.map {|x| x }.should == []
150
+
151
+ unpacker.reset
152
+
153
+ unpacker.feed("\x01")
154
+ unpacker.each.map {|x| x }.should == [1]
155
+ end
156
+
157
+ it 'frozen short strings' do
158
+ raw = sample_object.to_msgpack.to_s.force_encoding('UTF-8')
159
+ lambda {
160
+ unpacker.feed_each(raw.freeze) { }
161
+ }.should_not raise_error
162
+ end
163
+
164
+ it 'frozen long strings' do
165
+ raw = (sample_object.to_msgpack.to_s * 10240).force_encoding('UTF-8')
166
+ lambda {
167
+ unpacker.feed_each(raw.freeze) { }
168
+ }.should_not raise_error
169
+ end
170
+
171
+ it 'read raises level stack too deep error' do
172
+ 512.times { packer.write_array_header(1) }
173
+ packer.write(nil)
174
+
175
+ unpacker = Unpacker.new
176
+ unpacker.feed(packer.to_s)
177
+ lambda {
178
+ unpacker.read
179
+ }.should raise_error(MessagePack::StackError)
180
+ end
181
+
182
+ it 'skip raises level stack too deep error' do
183
+ 512.times { packer.write_array_header(1) }
184
+ packer.write(nil)
185
+
186
+ unpacker = Unpacker.new
187
+ unpacker.feed(packer.to_s)
188
+ lambda {
189
+ unpacker.skip
190
+ }.should raise_error(MessagePack::StackError)
191
+ end
192
+
193
+ it 'read raises invalid byte error' do
194
+ unpacker.feed("\xc1")
195
+ lambda {
196
+ unpacker.read
197
+ }.should raise_error(MessagePack::MalformedFormatError)
198
+ end
199
+
200
+ it 'skip raises invalid byte error' do
201
+ unpacker.feed("\xc1")
202
+ lambda {
203
+ unpacker.skip
204
+ }.should raise_error(MessagePack::MalformedFormatError)
205
+ end
206
+
207
+ it "gc mark" do
208
+ raw = sample_object.to_msgpack.to_s * 4
209
+
210
+ n = 0
211
+ raw.split(//).each do |b|
212
+ GC.start
213
+ unpacker.feed_each(b) {|o|
214
+ GC.start
215
+ o.should == sample_object
216
+ n += 1
217
+ }
218
+ GC.start
219
+ end
220
+
221
+ n.should == 4
222
+ end
223
+
224
+ it "buffer" do
225
+ orig = "a"*32*1024*4
226
+ raw = orig.to_msgpack.to_s
227
+
228
+ n = 655
229
+ times = raw.size / n
230
+ times += 1 unless raw.size % n == 0
231
+
232
+ off = 0
233
+ parsed = false
234
+
235
+ times.times do
236
+ parsed.should == false
237
+
238
+ seg = raw[off, n]
239
+ off += seg.length
240
+
241
+ unpacker.feed_each(seg) {|obj|
242
+ parsed.should == false
243
+ obj.should == orig
244
+ parsed = true
245
+ }
246
+ end
247
+
248
+ parsed.should == true
249
+ end
250
+
251
+ it 'MessagePack.unpack symbolize_keys' do
252
+ symbolized_hash = {:a => 'b', :c => 'd'}
253
+ MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
254
+ MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
255
+ end
256
+
257
+ it 'Unpacker#unpack symbolize_keys' do
258
+ unpacker = Unpacker.new(:symbolize_keys => true)
259
+ symbolized_hash = {:a => 'b', :c => 'd'}
260
+ unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
261
+ end
262
+
263
+ it "msgpack str 8 type" do
264
+ MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
265
+ MessagePack.unpack([0xd9, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
266
+ MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
267
+ MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
268
+ end
269
+
270
+ it "msgpack str 16 type" do
271
+ MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
272
+ MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
273
+ MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
274
+ MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
275
+ end
276
+
277
+ it "msgpack str 32 type" do
278
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
279
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
280
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
281
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
282
+ end
283
+
284
+ it "msgpack bin 8 type" do
285
+ MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
286
+ MessagePack.unpack([0xc4, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
287
+ MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
288
+ MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
289
+ end
290
+
291
+ it "msgpack bin 16 type" do
292
+ MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
293
+ MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
294
+ MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
295
+ MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
296
+ end
297
+
298
+ it "msgpack bin 32 type" do
299
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
300
+ MessagePack.unpack([0xc6, 0x0, 0x00, 0x00, 0x000].pack('C*')).encoding.should == Encoding::ASCII_8BIT
301
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
302
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
303
+ end
304
+ end
305
+
@@ -0,0 +1,282 @@
1
+ # encoding: ascii-8bit
2
+ require 'spec_helper'
3
+
4
+ describe MessagePack do
5
+ it "nil" do
6
+ check 1, nil
7
+ end
8
+
9
+ it "true" do
10
+ check 1, true
11
+ end
12
+
13
+ it "false" do
14
+ check 1, false
15
+ end
16
+
17
+ it "zero" do
18
+ check 1, 0
19
+ end
20
+
21
+ it "positive fixnum" do
22
+ check 1, 1
23
+ check 1, (1 << 6)
24
+ check 1, (1 << 7)-1
25
+ end
26
+
27
+ it "positive int 8" do
28
+ check 1, -1
29
+ check 2, (1 << 7)
30
+ check 2, (1 << 8) - 1
31
+ end
32
+
33
+ it "positive int 16" do
34
+ check 3, (1 << 8)
35
+ check 3, (1 << 16) - 1
36
+ end
37
+
38
+ it "positive int 32" do
39
+ check 5, (1 << 16)
40
+ check 5, (1 << 32) - 1
41
+ end
42
+
43
+ it "positive int 64" do
44
+ check 9, (1 << 32)
45
+ #check 9, (1<<64)-1
46
+ end
47
+
48
+ it "negative fixnum" do
49
+ check 1, -1
50
+ check 1, -((1 << 5)-1)
51
+ check 1, -(1 << 5)
52
+ end
53
+
54
+ it "negative int 8" do
55
+ check 2, -((1 << 5)+1)
56
+ check 2, -(1 << 7)
57
+ end
58
+
59
+ it "negative int 16" do
60
+ check 3, -((1 << 7)+1)
61
+ check 3, -(1 << 15)
62
+ end
63
+
64
+ it "negative int 32" do
65
+ check 5, -((1 << 15)+1)
66
+ check 5, -(1 << 31)
67
+ end
68
+
69
+ it "negative int 64" do
70
+ check 9, -((1 << 31)+1)
71
+ check 9, -(1 << 63)
72
+ end
73
+
74
+ it "double" do
75
+ check 9, 1.0
76
+ check 9, 0.1
77
+ check 9, -0.1
78
+ check 9, -1.0
79
+ end
80
+
81
+ it "fixraw" do
82
+ check_raw 1, 0
83
+ check_raw 1, (1 << 5)-1
84
+ end
85
+
86
+ it "raw 8" do
87
+ check_raw 2, (1 << 5)
88
+ check_raw 2, (1 << 8)-1
89
+ end
90
+
91
+ it "raw 16" do
92
+ check_raw 3, (1 << 8)
93
+ check_raw 3, (1 << 16)-1
94
+ end
95
+
96
+ it "raw 32" do
97
+ check_raw 5, (1 << 16)
98
+ #check_raw 5, (1 << 32)-1 # memory error
99
+ end
100
+
101
+ it "str encoding is UTF_8" do
102
+ v = pack_unpack('string'.force_encoding(Encoding::UTF_8))
103
+ v.encoding.should == Encoding::UTF_8
104
+ end
105
+
106
+ it "str transcode US-ASCII" do
107
+ v = pack_unpack('string'.force_encoding(Encoding::US_ASCII))
108
+ v.encoding.should == Encoding::UTF_8
109
+ end
110
+
111
+ it "str transcode UTF-16" do
112
+ v = pack_unpack('string'.encode(Encoding::UTF_16))
113
+ v.encoding.should == Encoding::UTF_8
114
+ v.should == 'string'
115
+ end
116
+
117
+ it "str transcode EUC-JP 7bit safe" do
118
+ v = pack_unpack('string'.force_encoding(Encoding::EUC_JP))
119
+ v.encoding.should == Encoding::UTF_8
120
+ v.should == 'string'
121
+ end
122
+
123
+ it "str transcode EUC-JP 7bit unsafe" do
124
+ v = pack_unpack([0xa4, 0xa2].pack('C*').force_encoding(Encoding::EUC_JP))
125
+ v.encoding.should == Encoding::UTF_8
126
+ v.should == "\xE3\x81\x82".force_encoding('UTF-8')
127
+ end
128
+
129
+ it "bin 8" do
130
+ check_bin 2, (1<<8)-1
131
+ end
132
+
133
+ it "bin 16" do
134
+ check_bin 3, (1<<16)-1
135
+ end
136
+
137
+ it "bin 32" do
138
+ check_bin 5, (1<<16)
139
+ end
140
+
141
+ it "bin encoding is ASCII_8BIT" do
142
+ pack_unpack('string'.force_encoding(Encoding::ASCII_8BIT)).encoding.should == Encoding::ASCII_8BIT
143
+ end
144
+
145
+ it "fixarray" do
146
+ check_array 1, 0
147
+ check_array 1, (1 << 4)-1
148
+ end
149
+
150
+ it "array 16" do
151
+ check_array 3, (1 << 4)
152
+ #check_array 3, (1 << 16)-1
153
+ end
154
+
155
+ it "array 32" do
156
+ #check_array 5, (1 << 16)
157
+ #check_array 5, (1 << 32)-1 # memory error
158
+ end
159
+
160
+ it "nil" do
161
+ match nil, "\xc0"
162
+ end
163
+
164
+ it "false" do
165
+ match false, "\xc2"
166
+ end
167
+
168
+ it "true" do
169
+ match true, "\xc3"
170
+ end
171
+
172
+ it "0" do
173
+ match 0, "\x00"
174
+ end
175
+
176
+ it "127" do
177
+ match 127, "\x7f"
178
+ end
179
+
180
+ it "128" do
181
+ match 128, "\xcc\x80"
182
+ end
183
+
184
+ it "256" do
185
+ match 256, "\xcd\x01\x00"
186
+ end
187
+
188
+ it "-1" do
189
+ match -1, "\xff"
190
+ end
191
+
192
+ it "-33" do
193
+ match -33, "\xd0\xdf"
194
+ end
195
+
196
+ it "-129" do
197
+ match -129, "\xd1\xff\x7f"
198
+ end
199
+
200
+ it "{1=>1}" do
201
+ obj = {1=>1}
202
+ match obj, "\x81\x01\x01"
203
+ end
204
+
205
+ it "1.0" do
206
+ match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
207
+ end
208
+
209
+ it "[]" do
210
+ match [], "\x90"
211
+ end
212
+
213
+ it "[0, 1, ..., 14]" do
214
+ obj = (0..14).to_a
215
+ match obj, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
216
+ end
217
+
218
+ it "[0, 1, ..., 15]" do
219
+ obj = (0..15).to_a
220
+ match obj, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
221
+ end
222
+
223
+ it "{}" do
224
+ obj = {}
225
+ match obj, "\x80"
226
+ end
227
+
228
+ ## FIXME
229
+ # it "{0=>0, 1=>1, ..., 14=>14}" do
230
+ # a = (0..14).to_a;
231
+ # match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
232
+ # end
233
+ #
234
+ # it "{0=>0, 1=>1, ..., 15=>15}" do
235
+ # a = (0..15).to_a;
236
+ # match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
237
+ # end
238
+
239
+ ## FIXME
240
+ # it "fixmap" do
241
+ # check_map 1, 0
242
+ # check_map 1, (1<<4)-1
243
+ # end
244
+ #
245
+ # it "map 16" do
246
+ # check_map 3, (1<<4)
247
+ # check_map 3, (1<<16)-1
248
+ # end
249
+ #
250
+ # it "map 32" do
251
+ # check_map 5, (1<<16)
252
+ # #check_map 5, (1<<32)-1 # memory error
253
+ # end
254
+
255
+ def check(len, obj)
256
+ raw = obj.to_msgpack.to_s
257
+ raw.length.should == len
258
+ MessagePack.unpack(raw).should == obj
259
+ end
260
+
261
+ def check_raw(overhead, num)
262
+ check num+overhead, (" "*num).force_encoding(Encoding::UTF_8)
263
+ end
264
+
265
+ def check_bin(overhead, num)
266
+ check num+overhead, (" "*num).force_encoding(Encoding::ASCII_8BIT)
267
+ end
268
+
269
+ def check_array(overhead, num)
270
+ check num+overhead, Array.new(num)
271
+ end
272
+
273
+ def match(obj, buf)
274
+ raw = obj.to_msgpack.to_s
275
+ raw.should == buf
276
+ end
277
+
278
+ def pack_unpack(obj)
279
+ MessagePack.unpack(obj.to_msgpack)
280
+ end
281
+ end
282
+
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ if RUBY_PLATFORM.include?('java')
4
+ # JRuby should use this library, MRI should use the standard gem
5
+ $: << File.expand_path('../../../lib', __FILE__)
6
+ end
7
+
8
+ require 'viiite'
9
+ require 'msgpack'
10
+ require 'json'
11
+ require 'bson'
12
+
13
+ if RUBY_PLATFORM.include?('java')
14
+ BSON_IMPL = BSON::BSON_JAVA
15
+ else
16
+ BSON_IMPL = BSON::BSON_C
17
+ end
18
+
19
+ OBJECT_STRUCTURE = {'x' => ['y', 34, 2**30 + 3, 2.1223423423356, {'hello' => 'world', '5' => [63, 'asjdl']}]}
20
+ ENCODED_MSGPACK = "\x81\xA1x\x95\xA1y\"\xCE@\x00\x00\x03\xCB@\x00\xFA\x8E\x9F9\xFA\xC1\x82\xA5hello\xA5world\xA15\x92?\xA5asjdl"
21
+ ENCODED_BSON = "d\x00\x00\x00\x04x\x00\\\x00\x00\x00\x020\x00\x02\x00\x00\x00y\x00\x101\x00\"\x00\x00\x00\x102\x00\x03\x00\x00@\x013\x00\xC1\xFA9\x9F\x8E\xFA\x00@\x034\x002\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x045\x00\x19\x00\x00\x00\x100\x00?\x00\x00\x00\x021\x00\x06\x00\x00\x00asjdl\x00\x00\x00\x00\x00"
22
+ ENCODED_JSON = '{"x":["y",34,1073741827,2.1223423423356,{"hello":"world","5":[63,"asjdl"]}]}'
23
+ ITERATIONS = 1_00_000
24
+ IMPLEMENTATIONS = ENV.fetch('IMPLEMENTATIONS', 'json,bson,msgpack').split(',').map(&:to_sym)
25
+
26
+ Viiite.bm do |b|
27
+ b.variation_point :ruby, Viiite.which_ruby
28
+
29
+ IMPLEMENTATIONS.each do |lib|
30
+ b.variation_point :lib, lib
31
+
32
+
33
+ b.report(:pack) do
34
+ ITERATIONS.times do
35
+ case lib
36
+ when :msgpack then MessagePack.pack(OBJECT_STRUCTURE)
37
+ when :bson then BSON_IMPL.serialize(OBJECT_STRUCTURE).to_s
38
+ when :json then OBJECT_STRUCTURE.to_json
39
+ end
40
+ end
41
+ end
42
+
43
+ b.report(:unpack) do
44
+ ITERATIONS.times do
45
+ case lib
46
+ when :msgpack then MessagePack.unpack(ENCODED_MSGPACK)
47
+ when :bson then BSON_IMPL.deserialize(ENCODED_BSON)
48
+ when :json then JSON.parse(ENCODED_JSON)
49
+ end
50
+ end
51
+ end
52
+
53
+ b.report(:pack_unpack) do
54
+ ITERATIONS.times do
55
+ case lib
56
+ when :msgpack then MessagePack.unpack(MessagePack.pack(OBJECT_STRUCTURE))
57
+ when :bson then BSON_IMPL.deserialize(BSON_IMPL.serialize(OBJECT_STRUCTURE).to_s)
58
+ when :json then JSON.parse(OBJECT_STRUCTURE.to_json)
59
+ end
60
+ end
61
+ end
62
+
63
+ b.report(:unpack_pack) do
64
+ ITERATIONS.times do
65
+ case lib
66
+ when :msgpack then MessagePack.pack(MessagePack.unpack(ENCODED_MSGPACK))
67
+ when :bson then BSON_IMPL.serialize(BSON_IMPL.deserialize(ENCODED_BSON)).to_s
68
+ when :json then OBJECT_STRUCTURE.to_json(JSON.parse(ENCODED_JSON))
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ $: << File.expand_path('../../../lib', __FILE__)
4
+
5
+ require 'viiite'
6
+ require 'msgpack'
7
+
8
+
9
+ iterations = 10_000
10
+ data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
11
+
12
+ Viiite.bm do |b|
13
+ b.report(:strings) do
14
+ iterations.times do
15
+ MessagePack.unpack(data)
16
+ end
17
+ end
18
+
19
+ b.report(:symbols) do
20
+ options = {:symbolize_keys => true}
21
+ iterations.times do
22
+ MessagePack.unpack(data, options)
23
+ end
24
+ end
25
+ end