msgpack 0.4.7-x86-mingw32 → 0.5.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +17 -0
  2. data/ChangeLog +47 -0
  3. data/README.rdoc +102 -0
  4. data/Rakefile +88 -0
  5. data/doclib/msgpack.rb +55 -0
  6. data/doclib/msgpack/buffer.rb +193 -0
  7. data/doclib/msgpack/core_ext.rb +101 -0
  8. data/doclib/msgpack/error.rb +14 -0
  9. data/doclib/msgpack/packer.rb +131 -0
  10. data/doclib/msgpack/unpacker.rb +130 -0
  11. data/ext/msgpack/buffer.c +679 -0
  12. data/ext/msgpack/buffer.h +442 -0
  13. data/ext/msgpack/buffer_class.c +507 -0
  14. data/ext/msgpack/buffer_class.h +32 -0
  15. data/ext/msgpack/compat.h +112 -0
  16. data/ext/msgpack/core_ext.c +129 -0
  17. data/ext/{pack.h → msgpack/core_ext.h} +7 -7
  18. data/ext/msgpack/extconf.rb +17 -0
  19. data/ext/msgpack/packer.c +137 -0
  20. data/ext/msgpack/packer.h +319 -0
  21. data/ext/msgpack/packer_class.c +285 -0
  22. data/ext/{unpack.h → msgpack/packer_class.h} +11 -7
  23. data/ext/msgpack/rbinit.c +33 -0
  24. data/ext/msgpack/rmem.c +110 -0
  25. data/ext/msgpack/rmem.h +100 -0
  26. data/ext/msgpack/sysdep.h +115 -0
  27. data/ext/msgpack/sysdep_endian.h +50 -0
  28. data/ext/msgpack/sysdep_types.h +46 -0
  29. data/ext/msgpack/unpacker.c +669 -0
  30. data/ext/msgpack/unpacker.h +112 -0
  31. data/ext/msgpack/unpacker_class.c +376 -0
  32. data/{msgpack/pack_define.h → ext/msgpack/unpacker_class.h} +12 -8
  33. data/lib/msgpack.rb +10 -1
  34. data/{ext → lib/msgpack}/version.rb +1 -1
  35. data/msgpack.gemspec +25 -0
  36. data/spec/buffer_io_spec.rb +237 -0
  37. data/spec/buffer_spec.rb +572 -0
  38. data/{test → spec}/cases.json +0 -0
  39. data/{test/cases.mpac → spec/cases.msg} +0 -0
  40. data/{test/cases_compact.mpac → spec/cases_compact.msg} +0 -0
  41. data/spec/cases_spec.rb +39 -0
  42. data/spec/format_spec.rb +225 -0
  43. data/spec/packer_spec.rb +127 -0
  44. data/spec/random_compat.rb +24 -0
  45. data/spec/spec_helper.rb +21 -0
  46. data/spec/unpacker_spec.rb +128 -0
  47. metadata +157 -39
  48. data/ext/compat.h +0 -99
  49. data/ext/extconf.rb +0 -7
  50. data/ext/pack.c +0 -314
  51. data/ext/rbinit.c +0 -66
  52. data/ext/unpack.c +0 -1001
  53. data/lib/1.8/msgpack.so +0 -0
  54. data/lib/1.9/msgpack.so +0 -0
  55. data/msgpack/pack_template.h +0 -771
  56. data/msgpack/sysdep.h +0 -195
  57. data/msgpack/unpack_define.h +0 -93
  58. data/msgpack/unpack_template.h +0 -413
  59. data/test/test_cases.rb +0 -46
  60. data/test/test_encoding.rb +0 -68
  61. data/test/test_helper.rb +0 -10
  62. data/test/test_pack_unpack.rb +0 -308
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env ruby
2
- here = File.dirname(__FILE__)
3
- require "#{here}/test_helper"
4
-
5
- begin
6
- require 'json'
7
- rescue LoadError
8
- require 'rubygems'
9
- require 'json'
10
- end
11
-
12
- CASES_PATH = "#{here}/cases.mpac"
13
- CASES_COMPACT_PATH = "#{here}/cases_compact.mpac"
14
- CASES_JSON_PATH = "#{here}/cases.json"
15
-
16
- class MessagePackTestCases < Test::Unit::TestCase
17
- def feed_file(path)
18
- pac = MessagePack::Unpacker.new
19
- pac.feed File.read(path)
20
- pac
21
- end
22
-
23
- def test_compare_compact
24
- pac = feed_file(CASES_PATH)
25
- cpac = feed_file(CASES_COMPACT_PATH)
26
-
27
- objs = []; pac.each {| obj| objs << obj }
28
- cobjs = []; cpac.each {|cobj| cobjs << cobj }
29
-
30
- objs.zip(cobjs).each {|obj, cobj|
31
- assert_equal(obj, cobj)
32
- }
33
- end
34
-
35
- def test_compare_json
36
- pac = feed_file(CASES_PATH)
37
-
38
- objs = []; pac.each {|obj| objs << obj }
39
- jobjs = JSON.load File.read(CASES_JSON_PATH)
40
-
41
- objs.zip(jobjs) {|obj, jobj|
42
- assert_equal(obj, jobj)
43
- }
44
- end
45
- end
46
-
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__)+'/test_helper'
3
-
4
- if RUBY_VERSION < "1.9"
5
- exit
6
- end
7
-
8
- class MessagePackTestEncoding < Test::Unit::TestCase
9
- def self.it(name, &block)
10
- define_method("test_#{name}", &block)
11
- end
12
-
13
- it "US-ASCII" do
14
- check_unpack "abc".force_encoding("US-ASCII")
15
- end
16
-
17
- it "UTF-8 ascii" do
18
- check_unpack "abc".force_encoding("UTF-8")
19
- end
20
-
21
- it "UTF-8 mbstr" do
22
- check_unpack "\xE3\x81\x82".force_encoding("UTF-8")
23
- end
24
-
25
- it "UTF-8 invalid" do
26
- check_unpack "\xD0".force_encoding("UTF-8")
27
- end
28
-
29
- it "ASCII-8BIT" do
30
- check_unpack "\xD0".force_encoding("ASCII-8BIT")
31
- end
32
-
33
- it "EUC-JP" do
34
- x = "\xA4\xA2".force_encoding("EUC-JP")
35
- check_unpack(x)
36
- end
37
-
38
- it "EUC-JP invalid" do
39
- begin
40
- "\xD0".force_encoding("EUC-JP").to_msgpack
41
- assert(false)
42
- rescue Encoding::InvalidByteSequenceError
43
- assert(true)
44
- end
45
- end
46
-
47
- private
48
- def check_unpack(str)
49
- if str.encoding.to_s == "ASCII-8BIT"
50
- should_str = str.dup.force_encoding("UTF-8")
51
- else
52
- should_str = str.encode("UTF-8")
53
- end
54
-
55
- raw = str.to_msgpack
56
- r = MessagePack.unpack(str.to_msgpack)
57
- assert_equal(r.encoding.to_s, "UTF-8")
58
- assert_equal(r, should_str.force_encoding("UTF-8"))
59
-
60
- if str.valid_encoding?
61
- sym = str.to_sym
62
- r = MessagePack.unpack(sym.to_msgpack)
63
- assert_equal(r.encoding.to_s, "UTF-8")
64
- assert_equal(r, should_str.force_encoding("UTF-8"))
65
- end
66
- end
67
- end
68
-
@@ -1,10 +0,0 @@
1
- require 'test/unit'
2
- begin
3
- require File.dirname(__FILE__) + '/../msgpack'
4
- rescue LoadError
5
- require File.dirname(__FILE__) + '/../lib/msgpack'
6
- end
7
-
8
- if ENV["GC_STRESS"]
9
- GC.stress = true
10
- end
@@ -1,308 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__)+'/test_helper'
3
-
4
- class MessagePackTestPackUnpack < 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 "double" do
79
- check 9, 1.0
80
- check 9, 0.1
81
- check 9, -0.1
82
- check 9, -1.0
83
- end
84
-
85
- it "fixraw" do
86
- check_raw 1, 0
87
- check_raw 1, (1<<5)-1
88
- end
89
-
90
- it "raw 16" do
91
- check_raw 3, (1<<5)
92
- check_raw 3, (1<<16)-1
93
- end
94
-
95
- it "raw 32" do
96
- check_raw 5, (1<<16)
97
- #check_raw 5, (1<<32)-1 # memory error
98
- end
99
-
100
- it "fixarray" do
101
- check_array 1, 0
102
- check_array 1, (1<<4)-1
103
- end
104
-
105
- it "array 16" do
106
- check_array 3, (1<<4)
107
- check_array 3, (1<<16)-1
108
- end
109
-
110
- it "array 32" do
111
- check_array 5, (1<<16)
112
- #check_array 5, (1<<32)-1 # memory error
113
- end
114
-
115
- it "nil" do
116
- match nil, "\xc0"
117
- end
118
-
119
- it "false" do
120
- match false, "\xc2"
121
- end
122
-
123
- it "true" do
124
- match true, "\xc3"
125
- end
126
-
127
- it "0" do
128
- match 0, "\x00"
129
- end
130
-
131
- it "127" do
132
- match 127, "\x7f"
133
- end
134
-
135
- it "128" do
136
- match 128, "\xcc\x80"
137
- end
138
-
139
- it "256" do
140
- match 256, "\xcd\x01\x00"
141
- end
142
-
143
- it "-1" do
144
- match -1, "\xff"
145
- end
146
-
147
- it "-33" do
148
- match -33, "\xd0\xdf"
149
- end
150
-
151
- it "-129" do
152
- match -129, "\xd1\xff\x7f"
153
- end
154
-
155
- it "{1=>1}" do
156
- obj = {1=>1}
157
- match obj, "\x81\x01\x01"
158
- end
159
-
160
- it "1.0" do
161
- match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
162
- end
163
-
164
- it "[]" do
165
- match [], "\x90"
166
- end
167
-
168
- it "[0, 1, ..., 14]" do
169
- obj = (0..14).to_a
170
- match obj, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
171
- end
172
-
173
- it "[0, 1, ..., 15]" do
174
- obj = (0..15).to_a
175
- match obj, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
176
- end
177
-
178
- it "{}" do
179
- obj = {}
180
- match obj, "\x80"
181
- end
182
-
183
- ## FIXME
184
- # it "{0=>0, 1=>1, ..., 14=>14}" do
185
- # a = (0..14).to_a;
186
- # 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"
187
- # end
188
- #
189
- # it "{0=>0, 1=>1, ..., 15=>15}" do
190
- # a = (0..15).to_a;
191
- # 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"
192
- # end
193
-
194
- ## FIXME
195
- # it "fixmap" do
196
- # check_map 1, 0
197
- # check_map 1, (1<<4)-1
198
- # end
199
- #
200
- # it "map 16" do
201
- # check_map 3, (1<<4)
202
- # check_map 3, (1<<16)-1
203
- # end
204
- #
205
- # it "map 32" do
206
- # check_map 5, (1<<16)
207
- # #check_map 5, (1<<32)-1 # memory error
208
- # end
209
-
210
- it "buffer" do
211
- str = "a"*32*1024*4
212
- raw = str.to_msgpack
213
- pac = MessagePack::Unpacker.new
214
-
215
- len = 0
216
- parsed = false
217
-
218
- n = 655
219
- time = raw.size / n
220
- time += 1 unless raw.size % n == 0
221
- off = 0
222
-
223
- time.times do
224
- assert(!parsed)
225
-
226
- fe = raw[off, n]
227
- assert(fe.length > 0)
228
- off += fe.length
229
-
230
- #pac.feed fe
231
- #pac.each {|obj|
232
- pac.feed_each(fe) {|obj|
233
- assert(!parsed)
234
- assert_equal(obj, str)
235
- parsed = true
236
- }
237
- end
238
-
239
- assert(parsed)
240
- end
241
-
242
- it "gc mark" do
243
- obj = [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
244
- num = 4
245
- raw = obj.to_msgpack * num
246
- pac = MessagePack::Unpacker.new
247
- parsed = 0
248
- raw.split(//).each do |b|
249
- #pac.feed(b)
250
- pac.feed_each(b) {|o|
251
- GC.start
252
- assert_equal(obj, o)
253
- parsed += 1
254
- }
255
- GC.start
256
- end
257
- assert_equal(parsed, num)
258
- end
259
-
260
- it "streaming backward compatibility" do
261
- obj = [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
262
- num = 4
263
- raw = obj.to_msgpack * num
264
- pac = MessagePack::Unpacker.new
265
- buffer = ""
266
- nread = 0
267
- parsed = 0
268
- raw.split(//).each do |b|
269
- buffer << b
270
- nread = pac.execute(buffer, nread)
271
- if pac.finished?
272
- o = pac.data
273
- assert_equal(obj, o)
274
- parsed += 1
275
- pac.reset
276
- buffer.slice!(0, nread)
277
- nread = 0
278
- next unless buffer.empty?
279
- end
280
- end
281
- assert_equal(parsed, num)
282
- end
283
-
284
- it "MessagePack::VERSION constant" do
285
- p MessagePack::VERSION
286
- end
287
-
288
- private
289
- def check(len, obj)
290
- v = obj.to_msgpack
291
- assert_equal(v.length, len)
292
- assert_equal(MessagePack.unpack(v), obj)
293
- end
294
-
295
- def check_raw(overhead, num)
296
- check num+overhead, " "*num
297
- end
298
-
299
- def check_array(overhead, num)
300
- check num+overhead, Array.new(num)
301
- end
302
-
303
- def match(obj, buf)
304
- assert_equal(obj.to_msgpack, buf)
305
- assert_equal(MessagePack::unpack(buf), obj)
306
- end
307
- end
308
-