msgpack 0.5.3-x86-mingw32 → 0.5.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 2012-03-15 version 0.5.4:
3
+
4
+ * Added missing MessagePack::Unpacker#reset method
5
+
6
+
2
7
  2012-02-14 version 0.5.3:
3
8
 
4
9
  * Fixed segfault problem on Buffer#clear (reuse rmem internal fragment optimization)
@@ -78,7 +78,7 @@ module MessagePack
78
78
  end
79
79
 
80
80
  #
81
- # Read a header of an map and returns its size.
81
+ # Reads a header of an map and returns its size.
82
82
  # It converts a serialized map into a stream of key-value pairs.
83
83
  #
84
84
  # If the serialized object is not a map, it raises MessagePack::TypeError.
@@ -125,6 +125,14 @@ module MessagePack
125
125
  #
126
126
  def feed_each(data, &block)
127
127
  end
128
+
129
+ #
130
+ # Resets deserialization state of the unpacker and clears the internal buffer.
131
+ #
132
+ # @return nil
133
+ #
134
+ def reset
135
+ end
128
136
  end
129
137
 
130
138
  end
@@ -276,6 +276,15 @@ static VALUE Unpacker_feed_each(VALUE self, VALUE data)
276
276
  return Unpacker_each(self);
277
277
  }
278
278
 
279
+ static VALUE Unpacker_reset(VALUE self)
280
+ {
281
+ UNPACKER(self, uk);
282
+
283
+ msgpack_unpacker_reset(uk);
284
+
285
+ return Qnil;
286
+ }
287
+
279
288
  VALUE MessagePack_unpack(int argc, VALUE* argv)
280
289
  {
281
290
  VALUE src;
@@ -362,6 +371,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
362
371
  rb_define_method(cMessagePack_Unpacker, "feed", Unpacker_feed, 1);
363
372
  rb_define_method(cMessagePack_Unpacker, "each", Unpacker_each, 0);
364
373
  rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1);
374
+ rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
365
375
 
366
376
  s_unpacker_value = Unpacker_alloc(cMessagePack_Unpacker);
367
377
  rb_gc_register_address(&s_unpacker_value);
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -6,6 +6,10 @@ describe Unpacker do
6
6
  Unpacker.new
7
7
  end
8
8
 
9
+ let :packer do
10
+ Packer.new
11
+ end
12
+
9
13
  # TODO initialize
10
14
 
11
15
  it 'read_array_header succeeds' do
@@ -42,16 +46,90 @@ describe Unpacker do
42
46
  unpacker.skip_nil.should == false
43
47
  end
44
48
 
49
+ it 'skip skips objects' do
50
+ packer.write(1)
51
+ packer.write(2)
52
+ packer.write(3)
53
+ packer.write(4)
54
+ packer.write(5)
55
+
56
+ unpacker = Unpacker.new(packer.buffer)
57
+
58
+ unpacker.read.should == 1
59
+ unpacker.skip
60
+ unpacker.read.should == 3
61
+ unpacker.skip
62
+ unpacker.read.should == 5
63
+ end
64
+
65
+ it 'read raises EOFError' do
66
+ lambda {
67
+ unpacker.read
68
+ }.should raise_error(EOFError)
69
+ end
70
+
71
+ it 'skip raises EOFError' do
72
+ lambda {
73
+ unpacker.skip
74
+ }.should raise_error(EOFError)
75
+ end
76
+
45
77
  it 'skip_nil raises EOFError' do
46
78
  lambda {
47
79
  unpacker.skip_nil
48
80
  }.should raise_error(EOFError)
49
81
  end
50
82
 
51
- # TODO skip methods
52
- # TODO feed
53
- # TODO each
54
- # TODO feed_each
83
+ let :sample_object do
84
+ [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
85
+ end
86
+
87
+ it 'feed and each continue internal state' do
88
+ raw = sample_object.to_msgpack.to_s * 4
89
+ objects = []
90
+
91
+ raw.split(//).each do |b|
92
+ unpacker.feed(b)
93
+ unpacker.each {|c|
94
+ objects << c
95
+ }
96
+ end
97
+
98
+ objects.should == [sample_object] * 4
99
+ end
100
+
101
+ it 'feed_each continues internal state' do
102
+ raw = sample_object.to_msgpack.to_s * 4
103
+ objects = []
104
+
105
+ raw.split(//).each do |b|
106
+ unpacker.feed_each(b) {|c|
107
+ objects << c
108
+ }
109
+ end
110
+
111
+ objects.should == [sample_object] * 4
112
+ end
113
+
114
+ it 'reset clears internal buffer' do
115
+ # 1-element array
116
+ unpacker.feed("\x91")
117
+ unpacker.reset
118
+ unpacker.feed("\x01")
119
+
120
+ unpacker.each.map {|x| x }.should == [1]
121
+ end
122
+
123
+ it 'reset clears internal state' do
124
+ # 1-element array
125
+ unpacker.feed("\x91")
126
+ unpacker.each.map {|x| x }.should == []
127
+
128
+ unpacker.reset
129
+
130
+ unpacker.feed("\x01")
131
+ unpacker.each.map {|x| x }.should == [1]
132
+ end
55
133
 
56
134
  it 'buffer' do
57
135
  o1 = unpacker.buffer.object_id
@@ -60,11 +138,8 @@ describe Unpacker do
60
138
  unpacker.buffer.object_id.should == o1
61
139
  end
62
140
 
63
- it 'raises level stack too deep error' do
64
- packer = Packer.new
65
- 512.times do
66
- packer.write_array_header(1)
67
- end
141
+ it 'read raises level stack too deep error' do
142
+ 512.times { packer.write_array_header(1) }
68
143
  packer.write(nil)
69
144
 
70
145
  unpacker = Unpacker.new(packer.buffer)
@@ -73,23 +148,39 @@ describe Unpacker do
73
148
  }.should raise_error(MessagePack::StackError)
74
149
  end
75
150
 
76
- it 'raises invalid byte error' do
151
+ it 'skip raises level stack too deep error' do
152
+ 512.times { packer.write_array_header(1) }
153
+ packer.write(nil)
154
+
155
+ unpacker = Unpacker.new(packer.buffer)
156
+ lambda {
157
+ unpacker.skip
158
+ }.should raise_error(MessagePack::StackError)
159
+ end
160
+
161
+ it 'read raises invalid byte error' do
77
162
  unpacker.feed("\xc6")
78
163
  lambda {
79
164
  unpacker.read
80
165
  }.should raise_error(MessagePack::MalformedFormatError)
81
166
  end
82
167
 
168
+ it 'skip raises invalid byte error' do
169
+ unpacker.feed("\xc6")
170
+ lambda {
171
+ unpacker.skip
172
+ }.should raise_error(MessagePack::MalformedFormatError)
173
+ end
174
+
83
175
  it "gc mark" do
84
- obj = [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
85
- raw = obj.to_msgpack.to_s * 4
176
+ raw = sample_object.to_msgpack.to_s * 4
86
177
 
87
178
  n = 0
88
179
  raw.split(//).each do |b|
89
180
  GC.start
90
181
  unpacker.feed_each(b) {|o|
91
182
  GC.start
92
- o.should == obj
183
+ o.should == sample_object
93
184
  n += 1
94
185
  }
95
186
  GC.start
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - FURUHASHI Sadayuki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-14 00:00:00 +09:00
18
+ date: 2013-03-16 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency