msgpack-ably 0.5.10

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 (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +26 -0
  4. data/ChangeLog +101 -0
  5. data/README.rdoc +129 -0
  6. data/Rakefile +110 -0
  7. data/doclib/msgpack.rb +77 -0
  8. data/doclib/msgpack/buffer.rb +193 -0
  9. data/doclib/msgpack/core_ext.rb +101 -0
  10. data/doclib/msgpack/error.rb +14 -0
  11. data/doclib/msgpack/packer.rb +134 -0
  12. data/doclib/msgpack/unpacker.rb +146 -0
  13. data/ext/msgpack/buffer.c +678 -0
  14. data/ext/msgpack/buffer.h +441 -0
  15. data/ext/msgpack/buffer_class.c +507 -0
  16. data/ext/msgpack/buffer_class.h +32 -0
  17. data/ext/msgpack/compat.h +113 -0
  18. data/ext/msgpack/core_ext.c +129 -0
  19. data/ext/msgpack/core_ext.h +26 -0
  20. data/ext/msgpack/extconf.rb +28 -0
  21. data/ext/msgpack/packer.c +168 -0
  22. data/ext/msgpack/packer.h +429 -0
  23. data/ext/msgpack/packer_class.c +302 -0
  24. data/ext/msgpack/packer_class.h +30 -0
  25. data/ext/msgpack/rbinit.c +33 -0
  26. data/ext/msgpack/rmem.c +94 -0
  27. data/ext/msgpack/rmem.h +109 -0
  28. data/ext/msgpack/sysdep.h +115 -0
  29. data/ext/msgpack/sysdep_endian.h +50 -0
  30. data/ext/msgpack/sysdep_types.h +46 -0
  31. data/ext/msgpack/unpacker.c +781 -0
  32. data/ext/msgpack/unpacker.h +122 -0
  33. data/ext/msgpack/unpacker_class.c +405 -0
  34. data/ext/msgpack/unpacker_class.h +32 -0
  35. data/lib/msgpack.rb +6 -0
  36. data/lib/msgpack/version.rb +3 -0
  37. data/msgpack.gemspec +26 -0
  38. data/msgpack.org.md +49 -0
  39. data/spec/cases.json +1 -0
  40. data/spec/cases.msg +0 -0
  41. data/spec/cases_compact.msg +0 -0
  42. data/spec/cases_spec.rb +39 -0
  43. data/spec/cruby/buffer_io_spec.rb +256 -0
  44. data/spec/cruby/buffer_packer.rb +29 -0
  45. data/spec/cruby/buffer_spec.rb +572 -0
  46. data/spec/cruby/buffer_unpacker.rb +19 -0
  47. data/spec/format_spec.rb +256 -0
  48. data/spec/packer_spec.rb +120 -0
  49. data/spec/random_compat.rb +24 -0
  50. data/spec/spec_helper.rb +21 -0
  51. data/spec/unpacker_spec.rb +305 -0
  52. metadata +195 -0
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,256 @@
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<<8)-1
88
+ end
89
+
90
+ it "raw 16" do
91
+ check_raw 3, (1<<16)-1
92
+ end
93
+
94
+ it "raw 32" do
95
+ check_raw 5, (1<<16)
96
+ #check_raw 5, (1<<32)-1 # memory error
97
+ end
98
+
99
+ it "str encoding is UTF_8" do
100
+ pack_unpack('string'.force_encoding(Encoding::UTF_8)).encoding.should == Encoding::UTF_8
101
+ end
102
+
103
+ it "bin 8" do
104
+ check_bin 2, (1<<8)-1
105
+ end
106
+
107
+ it "bin 16" do
108
+ check_bin 3, (1<<16)-1
109
+ end
110
+
111
+ it "bin 32" do
112
+ check_bin 5, (1<<16)
113
+ end
114
+
115
+ it "bin encoding is ASCII_8BIT" do
116
+ pack_unpack('string'.force_encoding(Encoding::ASCII_8BIT)).encoding.should == Encoding::ASCII_8BIT
117
+ end
118
+
119
+ it "fixarray" do
120
+ check_array 1, 0
121
+ check_array 1, (1<<4)-1
122
+ end
123
+
124
+ it "array 16" do
125
+ check_array 3, (1<<4)
126
+ #check_array 3, (1<<16)-1
127
+ end
128
+
129
+ it "array 32" do
130
+ #check_array 5, (1<<16)
131
+ #check_array 5, (1<<32)-1 # memory error
132
+ end
133
+
134
+ it "nil" do
135
+ match nil, "\xc0"
136
+ end
137
+
138
+ it "false" do
139
+ match false, "\xc2"
140
+ end
141
+
142
+ it "true" do
143
+ match true, "\xc3"
144
+ end
145
+
146
+ it "0" do
147
+ match 0, "\x00"
148
+ end
149
+
150
+ it "127" do
151
+ match 127, "\x7f"
152
+ end
153
+
154
+ it "128" do
155
+ match 128, "\xcc\x80"
156
+ end
157
+
158
+ it "256" do
159
+ match 256, "\xcd\x01\x00"
160
+ end
161
+
162
+ it "-1" do
163
+ match -1, "\xff"
164
+ end
165
+
166
+ it "-33" do
167
+ match -33, "\xd0\xdf"
168
+ end
169
+
170
+ it "-129" do
171
+ match -129, "\xd1\xff\x7f"
172
+ end
173
+
174
+ it "{1=>1}" do
175
+ obj = {1=>1}
176
+ match obj, "\x81\x01\x01"
177
+ end
178
+
179
+ it "1.0" do
180
+ match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
181
+ end
182
+
183
+ it "[]" do
184
+ match [], "\x90"
185
+ end
186
+
187
+ it "[0, 1, ..., 14]" do
188
+ obj = (0..14).to_a
189
+ match obj, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
190
+ end
191
+
192
+ it "[0, 1, ..., 15]" do
193
+ obj = (0..15).to_a
194
+ match obj, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
195
+ end
196
+
197
+ it "{}" do
198
+ obj = {}
199
+ match obj, "\x80"
200
+ end
201
+
202
+ ## FIXME
203
+ # it "{0=>0, 1=>1, ..., 14=>14}" do
204
+ # a = (0..14).to_a;
205
+ # 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"
206
+ # end
207
+ #
208
+ # it "{0=>0, 1=>1, ..., 15=>15}" do
209
+ # a = (0..15).to_a;
210
+ # 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"
211
+ # end
212
+
213
+ ## FIXME
214
+ # it "fixmap" do
215
+ # check_map 1, 0
216
+ # check_map 1, (1<<4)-1
217
+ # end
218
+ #
219
+ # it "map 16" do
220
+ # check_map 3, (1<<4)
221
+ # check_map 3, (1<<16)-1
222
+ # end
223
+ #
224
+ # it "map 32" do
225
+ # check_map 5, (1<<16)
226
+ # #check_map 5, (1<<32)-1 # memory error
227
+ # end
228
+
229
+ def check(len, obj)
230
+ raw = obj.to_msgpack.to_s
231
+ raw.length.should == len
232
+ MessagePack.unpack(raw).should == obj
233
+ end
234
+
235
+ def check_raw(overhead, num)
236
+ check num+overhead, (" "*num).force_encoding(Encoding::UTF_8)
237
+ end
238
+
239
+ def check_bin(overhead, num)
240
+ check num+overhead, (" "*num).force_encoding(Encoding::ASCII_8BIT)
241
+ end
242
+
243
+ def check_array(overhead, num)
244
+ check num+overhead, Array.new(num)
245
+ end
246
+
247
+ def match(obj, buf)
248
+ raw = obj.to_msgpack.to_s
249
+ raw.should == buf
250
+ end
251
+
252
+ def pack_unpack(obj)
253
+ MessagePack.unpack(obj.to_msgpack)
254
+ end
255
+ end
256
+
@@ -0,0 +1,120 @@
1
+ # encoding: ascii-8bit
2
+ require 'spec_helper'
3
+
4
+ require 'stringio'
5
+ if defined?(Encoding)
6
+ Encoding.default_external = 'ASCII-8BIT'
7
+ end
8
+
9
+ describe Packer do
10
+ let :packer do
11
+ Packer.new
12
+ end
13
+
14
+ it 'initialize' do
15
+ Packer.new
16
+ Packer.new(nil)
17
+ Packer.new(StringIO.new)
18
+ Packer.new({})
19
+ Packer.new(StringIO.new, {})
20
+ end
21
+
22
+ #it 'Packer' do
23
+ # Packer(packer).object_id.should == packer.object_id
24
+ # Packer(nil).class.should == Packer
25
+ # Packer('').class.should == Packer
26
+ # Packer('initbuf').to_s.should == 'initbuf'
27
+ #end
28
+
29
+ it 'write' do
30
+ packer.write([])
31
+ packer.to_s.should == "\x90"
32
+ end
33
+
34
+ it 'write_nil' do
35
+ packer.write_nil
36
+ packer.to_s.should == "\xc0"
37
+ end
38
+
39
+ it 'write_array_header 0' do
40
+ packer.write_array_header(0)
41
+ packer.to_s.should == "\x90"
42
+ end
43
+
44
+ it 'write_array_header 1' do
45
+ packer.write_array_header(1)
46
+ packer.to_s.should == "\x91"
47
+ end
48
+
49
+ it 'write_map_header 0' do
50
+ packer.write_map_header(0)
51
+ packer.to_s.should == "\x80"
52
+ end
53
+
54
+ it 'write_map_header 1' do
55
+ packer.write_map_header(1)
56
+ packer.to_s.should == "\x81"
57
+ end
58
+
59
+ it 'flush' do
60
+ io = StringIO.new
61
+ pk = Packer.new(io)
62
+ pk.write_nil
63
+ pk.flush
64
+ pk.to_s.should == ''
65
+ io.string.should == "\xc0"
66
+ end
67
+
68
+ it 'to_msgpack returns String' do
69
+ nil.to_msgpack.class.should == String
70
+ true.to_msgpack.class.should == String
71
+ false.to_msgpack.class.should == String
72
+ 1.to_msgpack.class.should == String
73
+ 1.0.to_msgpack.class.should == String
74
+ "".to_msgpack.class.should == String
75
+ Hash.new.to_msgpack.class.should == String
76
+ Array.new.to_msgpack.class.should == String
77
+ end
78
+
79
+ class CustomPack01
80
+ def to_msgpack(pk=nil)
81
+ return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer
82
+ pk.write_array_header(2)
83
+ pk.write(1)
84
+ pk.write(2)
85
+ return pk
86
+ end
87
+ end
88
+
89
+ class CustomPack02
90
+ def to_msgpack(pk=nil)
91
+ [1,2].to_msgpack(pk)
92
+ end
93
+ end
94
+
95
+ it 'calls custom to_msgpack method' do
96
+ MessagePack.pack(CustomPack01.new).should == [1,2].to_msgpack
97
+ MessagePack.pack(CustomPack02.new).should == [1,2].to_msgpack
98
+ CustomPack01.new.to_msgpack.should == [1,2].to_msgpack
99
+ CustomPack02.new.to_msgpack.should == [1,2].to_msgpack
100
+ end
101
+
102
+ it 'calls custom to_msgpack method with io' do
103
+ s01 = StringIO.new
104
+ MessagePack.pack(CustomPack01.new, s01)
105
+ s01.string.should == [1,2].to_msgpack
106
+
107
+ s02 = StringIO.new
108
+ MessagePack.pack(CustomPack02.new, s02)
109
+ s02.string.should == [1,2].to_msgpack
110
+
111
+ s03 = StringIO.new
112
+ CustomPack01.new.to_msgpack(s03)
113
+ s03.string.should == [1,2].to_msgpack
114
+
115
+ s04 = StringIO.new
116
+ CustomPack02.new.to_msgpack(s04)
117
+ s04.string.should == [1,2].to_msgpack
118
+ end
119
+ end
120
+
@@ -0,0 +1,24 @@
1
+
2
+ unless defined? Random
3
+ class Random
4
+ def initialize(seed=Time.now.to_i)
5
+ Kernel.srand(seed)
6
+ @seed = seed
7
+ end
8
+
9
+ attr_reader :seed
10
+
11
+ def rand(arg)
12
+ Kernel.rand(arg)
13
+ end
14
+
15
+ def bytes(n)
16
+ array = []
17
+ n.times do
18
+ array << rand(256)
19
+ end
20
+ array.pack('C*')
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,21 @@
1
+
2
+ if ENV['SIMPLE_COV']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'spec/'
6
+ add_filter 'pkg/'
7
+ add_filter 'vendor/'
8
+ end
9
+ end
10
+
11
+ if ENV['GC_STRESS']
12
+ puts "enable GC.stress"
13
+ GC.stress = true
14
+ end
15
+
16
+ require 'msgpack'
17
+
18
+ Packer = MessagePack::Packer
19
+ Unpacker = MessagePack::Unpacker
20
+ Buffer = MessagePack::Buffer
21
+
@@ -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
+