msgpack 0.5.6 → 0.5.7

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.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 2013-10-12 version 0.5.7:
3
+
4
+ * Added deserialization support for the new MessagePack spec
5
+
6
+
2
7
  2013-09-23 version 0.5.6:
3
8
 
4
9
  * Fixed "can't modify frozen String" exception in Unpacker with ruby 2.1.0-dev
data/Rakefile CHANGED
@@ -72,23 +72,30 @@ task :default => :build
72
72
  # exec $SHELL -l
73
73
  #
74
74
  ### install cross-compiled ruby 2.0.0
75
- # rbenv install 2.0.0-p0
75
+ # rbenv install 2.0.0-p247
76
+ # rbenv shell 2.0.0-p247
77
+ # gem update --system
76
78
  # gem install rake-compiler
77
- # rake-compiler cross-ruby VERSION=2.0.0-p0
79
+ # rake-compiler cross-ruby VERSION=2.0.0-p247
78
80
  #
79
81
  ### install cross-compiled ruby 1.9.3
80
82
  # rbenv install 1.9.3-p327
83
+ # rbenv shell 1.9.3-p327
84
+ # gem update --system
81
85
  # gem install rake-compiler
82
86
  # rake-compiler cross-ruby VERSION=1.9.3-p327
83
87
  #
84
88
  ### install cross-compiled ruby 1.8.7
85
- # rbenv install 1.8.7-p371
89
+ # rbenv install 1.8.7-p374
90
+ # rbenv shell 1.8.7-p374
91
+ # gem update --system
86
92
  # gem install rake-compiler
87
- # rake-compiler cross-ruby VERSION=1.8.7-p371
93
+ # rake-compiler cross-ruby VERSION=1.8.7-p374
88
94
  #
89
95
  ### build gem
90
- # rbenv shell 1.8.7-p371
91
- # gem install bundler && bundle
96
+ # rbenv shell 1.8.7-p374
97
+ # gem install bundler
98
+ # bundle
92
99
  # rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0
93
100
  #
94
101
 
@@ -50,7 +50,7 @@ void msgpack_unpacker_static_destroy()
50
50
  #endif
51
51
  }
52
52
 
53
- #define HEAD_BYTE_REQUIRED 0xc6
53
+ #define HEAD_BYTE_REQUIRED 0xc1
54
54
 
55
55
  void msgpack_unpacker_init(msgpack_unpacker_t* uk)
56
56
  {
@@ -247,7 +247,7 @@ static int read_raw_body_cont(msgpack_unpacker_t* uk)
247
247
  return PRIMITIVE_OBJECT_COMPLETE;
248
248
  }
249
249
 
250
- static inline int read_raw_body_begin(msgpack_unpacker_t* uk)
250
+ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, bool str)
251
251
  {
252
252
  /* assuming uk->reading_raw == Qnil */
253
253
 
@@ -287,14 +287,14 @@ static int read_primitive(msgpack_unpacker_t* uk)
287
287
  SWITCH_RANGE(b, 0xe0, 0xff) // Negative Fixnum
288
288
  return object_complete(uk, INT2NUM((int8_t)b));
289
289
 
290
- SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw
290
+ SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw / fixstr
291
291
  int count = b & 0x1f;
292
292
  if(count == 0) {
293
293
  return object_complete_string(uk, rb_str_buf_new(0));
294
294
  }
295
295
  /* read_raw_body_begin sets uk->reading_raw */
296
296
  uk->reading_raw_remaining = count;
297
- return read_raw_body_begin(uk);
297
+ return read_raw_body_begin(uk, true);
298
298
 
299
299
  SWITCH_RANGE(b, 0x90, 0x9f) // FixArray
300
300
  int count = b & 0x0f;
@@ -323,12 +323,9 @@ static int read_primitive(msgpack_unpacker_t* uk)
323
323
  case 0xc3: // true
324
324
  return object_complete(uk, Qtrue);
325
325
 
326
- //case 0xc4:
327
- //case 0xc5:
328
- //case 0xc6:
329
- //case 0xc7:
330
- //case 0xc8:
331
- //case 0xc9:
326
+ //case 0xc7: // ext 8
327
+ //case 0xc8: // ext 16
328
+ //case 0xc9: // ext 32
332
329
 
333
330
  case 0xca: // float
334
331
  {
@@ -400,14 +397,25 @@ static int read_primitive(msgpack_unpacker_t* uk)
400
397
  return object_complete(uk, rb_ll2inum(i64));
401
398
  }
402
399
 
403
- //case 0xd4:
404
- //case 0xd5:
405
- //case 0xd6: // big integer 16
406
- //case 0xd7: // big integer 32
407
- //case 0xd8: // big float 16
408
- //case 0xd9: // big float 32
400
+ //case 0xd4: // fixext 1
401
+ //case 0xd5: // fixext 2
402
+ //case 0xd6: // fixext 4
403
+ //case 0xd7: // fixext 8
404
+ //case 0xd8: // fixext 16
409
405
 
410
- case 0xda: // raw 16
406
+ case 0xd9: // raw 8 / str 8
407
+ {
408
+ READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
409
+ uint8_t count = cb->u8;
410
+ if(count == 0) {
411
+ return object_complete_string(uk, rb_str_buf_new(0));
412
+ }
413
+ /* read_raw_body_begin sets uk->reading_raw */
414
+ uk->reading_raw_remaining = count;
415
+ return read_raw_body_begin(uk, true);
416
+ }
417
+
418
+ case 0xda: // raw 16 / str 16
411
419
  {
412
420
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
413
421
  uint16_t count = _msgpack_be16(cb->u16);
@@ -416,10 +424,10 @@ static int read_primitive(msgpack_unpacker_t* uk)
416
424
  }
417
425
  /* read_raw_body_begin sets uk->reading_raw */
418
426
  uk->reading_raw_remaining = count;
419
- return read_raw_body_begin(uk);
427
+ return read_raw_body_begin(uk, true);
420
428
  }
421
429
 
422
- case 0xdb: // raw 32
430
+ case 0xdb: // raw 32 / str 16
423
431
  {
424
432
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
425
433
  uint32_t count = _msgpack_be32(cb->u32);
@@ -428,7 +436,43 @@ static int read_primitive(msgpack_unpacker_t* uk)
428
436
  }
429
437
  /* read_raw_body_begin sets uk->reading_raw */
430
438
  uk->reading_raw_remaining = count;
431
- return read_raw_body_begin(uk);
439
+ return read_raw_body_begin(uk, true);
440
+ }
441
+
442
+ case 0xc4: // bin 8
443
+ {
444
+ READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
445
+ uint8_t count = cb->u8;
446
+ if(count == 0) {
447
+ return object_complete_string(uk, rb_str_buf_new(0));
448
+ }
449
+ /* read_raw_body_begin sets uk->reading_raw */
450
+ uk->reading_raw_remaining = count;
451
+ return read_raw_body_begin(uk, false);
452
+ }
453
+
454
+ case 0xc5: // bin 16
455
+ {
456
+ READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
457
+ uint16_t count = _msgpack_be16(cb->u16);
458
+ if(count == 0) {
459
+ return object_complete_string(uk, rb_str_buf_new(0));
460
+ }
461
+ /* read_raw_body_begin sets uk->reading_raw */
462
+ uk->reading_raw_remaining = count;
463
+ return read_raw_body_begin(uk, false);
464
+ }
465
+
466
+ case 0xc6: // bin 32
467
+ {
468
+ READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
469
+ uint32_t count = _msgpack_be32(cb->u32);
470
+ if(count == 0) {
471
+ return object_complete_string(uk, rb_str_buf_new(0));
472
+ }
473
+ /* read_raw_body_begin sets uk->reading_raw */
474
+ uk->reading_raw_remaining = count;
475
+ return read_raw_body_begin(uk, false);
432
476
  }
433
477
 
434
478
  case 0xdc: // array 16
@@ -664,8 +708,14 @@ int msgpack_unpacker_peek_next_object_type(msgpack_unpacker_t* uk)
664
708
  case 0xd3: // signed int 64
665
709
  return TYPE_INTEGER;
666
710
 
667
- case 0xda: // raw 16
668
- case 0xdb: // raw 32
711
+ case 0xd9: // raw 8 / str 8
712
+ case 0xda: // raw 16 / str 16
713
+ case 0xdb: // raw 32 / str 32
714
+ return TYPE_RAW;
715
+
716
+ case 0xc4: // bin 8
717
+ case 0xc5: // bin 16
718
+ case 0xc6: // bin 32
669
719
  return TYPE_RAW;
670
720
 
671
721
  case 0xdc: // array 16
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -173,14 +173,14 @@ describe Unpacker do
173
173
  end
174
174
 
175
175
  it 'read raises invalid byte error' do
176
- unpacker.feed("\xc6")
176
+ unpacker.feed("\xc1")
177
177
  lambda {
178
178
  unpacker.read
179
179
  }.should raise_error(MessagePack::MalformedFormatError)
180
180
  end
181
181
 
182
182
  it 'skip raises invalid byte error' do
183
- unpacker.feed("\xc6")
183
+ unpacker.feed("\xc1")
184
184
  lambda {
185
185
  unpacker.skip
186
186
  }.should raise_error(MessagePack::MalformedFormatError)
@@ -229,5 +229,41 @@ describe Unpacker do
229
229
 
230
230
  parsed.should == true
231
231
  end
232
+
233
+ it "msgpack str 8 type" do
234
+ MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
235
+ MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
236
+ MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
237
+ end
238
+
239
+ it "msgpack str 16 type" do
240
+ MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
241
+ MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
242
+ MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
243
+ end
244
+
245
+ it "msgpack str 32 type" do
246
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
247
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
248
+ MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
249
+ end
250
+
251
+ it "msgpack bin 8 type" do
252
+ MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
253
+ MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
254
+ MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
255
+ end
256
+
257
+ it "msgpack bin 16 type" do
258
+ MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
259
+ MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
260
+ MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
261
+ end
262
+
263
+ it "msgpack bin 32 type" do
264
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
265
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
266
+ MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
267
+ end
232
268
  end
233
269
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler