msgpack 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/ChangeLog +4 -0
- data/doclib/msgpack.rb +10 -0
- data/ext/java/org/msgpack/jruby/Decoder.java +2 -2
- data/ext/msgpack/buffer.c +7 -7
- data/ext/msgpack/buffer_class.c +1 -1
- data/ext/msgpack/factory_class.c +1 -1
- data/ext/msgpack/packer.h +1 -1
- data/ext/msgpack/packer_class.c +1 -1
- data/ext/msgpack/rmem.c +7 -7
- data/ext/msgpack/unpacker.c +4 -4
- data/ext/msgpack/unpacker_class.c +1 -1
- data/lib/msgpack/version.rb +1 -1
- data/spec/packer_spec.rb +30 -0
- data/spec/unpacker_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ca0c3abd8883f5ba34b519986e789b6e029505a
|
4
|
+
data.tar.gz: 2d8db1bcaeccbccebe206b99cdd361e7c32621a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1adc454c670e6cb401bf103f389b0d3cff36f644bb1eeb57a2795c6757718a9124cb09c71a56a38e4a22345aec4a1f18178e45407fa5528566e762abaf3dc48
|
7
|
+
data.tar.gz: 820785bf3360304db2d1011d108fbc167a827c07b43b3a17f0f9c6359a734aa6572f01c72946af6f6be923266c3d0e47e148009f557875cf66ecf8ce57f47a3c
|
data/.travis.yml
CHANGED
data/ChangeLog
CHANGED
data/doclib/msgpack.rb
CHANGED
@@ -73,5 +73,15 @@ module MessagePack
|
|
73
73
|
#
|
74
74
|
def self.unpack(src, options={})
|
75
75
|
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# An instance of Factory class. DefaultFactory is also used
|
79
|
+
# by global pack/unpack methods such as MessagePack.dump/load,
|
80
|
+
# Hash#to_msgpack, and other to_msgpack methods.
|
81
|
+
#
|
82
|
+
# Calling DefaultFactory.register_type lets you add an extension
|
83
|
+
# type globally.
|
84
|
+
#
|
85
|
+
DefaultFactory = Factory.new
|
76
86
|
end
|
77
87
|
|
@@ -236,8 +236,8 @@ public class Decoder implements Iterator<IRubyObject> {
|
|
236
236
|
case BIN8: return consumeString(buffer.get() & 0xff, binaryEncoding);
|
237
237
|
case BIN16: return consumeString(buffer.getShort() & 0xffff, binaryEncoding);
|
238
238
|
case BIN32: return consumeString(buffer.getInt(), binaryEncoding);
|
239
|
-
case VAREXT8: return consumeExtension(buffer.get());
|
240
|
-
case VAREXT16: return consumeExtension(buffer.getShort());
|
239
|
+
case VAREXT8: return consumeExtension(buffer.get() & 0xff);
|
240
|
+
case VAREXT16: return consumeExtension(buffer.getShort() & 0xffff);
|
241
241
|
case VAREXT32: return consumeExtension(buffer.getInt());
|
242
242
|
case FLOAT32: return runtime.newFloat(buffer.getFloat());
|
243
243
|
case FLOAT64: return runtime.newFloat(buffer.getDouble());
|
data/ext/msgpack/buffer.c
CHANGED
@@ -74,13 +74,13 @@ static void _msgpack_buffer_chunk_destroy(msgpack_buffer_chunk_t* c)
|
|
74
74
|
if(c->mem != NULL) {
|
75
75
|
#ifndef DISABLE_RMEM
|
76
76
|
if(!msgpack_rmem_free(&s_rmem, c->mem)) {
|
77
|
-
|
77
|
+
xfree(c->mem);
|
78
78
|
}
|
79
79
|
/* no needs to update rmem_owner because chunks will not be
|
80
80
|
* free()ed (left in free_list) and thus *rmem_owner is
|
81
81
|
* always valid. */
|
82
82
|
#else
|
83
|
-
|
83
|
+
xfree(c->mem);
|
84
84
|
#endif
|
85
85
|
}
|
86
86
|
c->first = NULL;
|
@@ -95,7 +95,7 @@ void msgpack_buffer_destroy(msgpack_buffer_t* b)
|
|
95
95
|
while(c != &b->tail) {
|
96
96
|
msgpack_buffer_chunk_t* n = c->next;
|
97
97
|
_msgpack_buffer_chunk_destroy(c);
|
98
|
-
|
98
|
+
xfree(c);
|
99
99
|
c = n;
|
100
100
|
}
|
101
101
|
_msgpack_buffer_chunk_destroy(c);
|
@@ -103,7 +103,7 @@ void msgpack_buffer_destroy(msgpack_buffer_t* b)
|
|
103
103
|
c = b->free_list;
|
104
104
|
while(c != NULL) {
|
105
105
|
msgpack_buffer_chunk_t* n = c->next;
|
106
|
-
|
106
|
+
xfree(c);
|
107
107
|
c = n;
|
108
108
|
}
|
109
109
|
}
|
@@ -259,7 +259,7 @@ static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_bu
|
|
259
259
|
{
|
260
260
|
msgpack_buffer_chunk_t* reuse = b->free_list;
|
261
261
|
if(reuse == NULL) {
|
262
|
-
return
|
262
|
+
return xmalloc(sizeof(msgpack_buffer_chunk_t));
|
263
263
|
}
|
264
264
|
b->free_list = b->free_list->next;
|
265
265
|
return reuse;
|
@@ -403,7 +403,7 @@ static inline void* _msgpack_buffer_chunk_malloc(
|
|
403
403
|
|
404
404
|
// TODO alignment?
|
405
405
|
*allocated_size = required_size;
|
406
|
-
void* mem =
|
406
|
+
void* mem = xmalloc(required_size);
|
407
407
|
c->mem = mem;
|
408
408
|
return mem;
|
409
409
|
}
|
@@ -421,7 +421,7 @@ static inline void* _msgpack_buffer_chunk_realloc(
|
|
421
421
|
next_size *= 2;
|
422
422
|
}
|
423
423
|
*current_size = next_size;
|
424
|
-
mem =
|
424
|
+
mem = xrealloc(mem, next_size);
|
425
425
|
|
426
426
|
c->mem = mem;
|
427
427
|
return mem;
|
data/ext/msgpack/buffer_class.c
CHANGED
data/ext/msgpack/factory_class.c
CHANGED
data/ext/msgpack/packer.h
CHANGED
@@ -364,7 +364,7 @@ static inline void msgpack_packer_write_ext(msgpack_packer_t* pk, int ext_type,
|
|
364
364
|
msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd8, ext_type);
|
365
365
|
break;
|
366
366
|
default:
|
367
|
-
if(len <
|
367
|
+
if(len < 256) {
|
368
368
|
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
|
369
369
|
msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xc7, len);
|
370
370
|
msgpack_buffer_write_1(PACKER_BUFFER_(pk), ext_type);
|
data/ext/msgpack/packer_class.c
CHANGED
data/ext/msgpack/rmem.c
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
void msgpack_rmem_init(msgpack_rmem_t* pm)
|
22
22
|
{
|
23
23
|
memset(pm, 0, sizeof(msgpack_rmem_t));
|
24
|
-
pm->head.pages =
|
24
|
+
pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
|
25
25
|
pm->head.mask = 0xffffffff; /* all bit is 1 = available */
|
26
26
|
}
|
27
27
|
|
@@ -30,10 +30,10 @@ void msgpack_rmem_destroy(msgpack_rmem_t* pm)
|
|
30
30
|
msgpack_rmem_chunk_t* c = pm->array_first;
|
31
31
|
msgpack_rmem_chunk_t* cend = pm->array_last;
|
32
32
|
for(; c != cend; c++) {
|
33
|
-
|
33
|
+
xfree(c->pages);
|
34
34
|
}
|
35
|
-
|
36
|
-
|
35
|
+
xfree(pm->head.pages);
|
36
|
+
xfree(pm->array_first);
|
37
37
|
}
|
38
38
|
|
39
39
|
void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
|
@@ -56,7 +56,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
|
|
56
56
|
size_t capacity = c - pm->array_first;
|
57
57
|
size_t length = last - pm->array_first;
|
58
58
|
capacity = (capacity == 0) ? 8 : capacity * 2;
|
59
|
-
msgpack_rmem_chunk_t* array =
|
59
|
+
msgpack_rmem_chunk_t* array = xrealloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t));
|
60
60
|
pm->array_first = array;
|
61
61
|
pm->array_last = array + length;
|
62
62
|
pm->array_end = array + capacity;
|
@@ -71,7 +71,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
|
|
71
71
|
*c = tmp;
|
72
72
|
|
73
73
|
pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
|
74
|
-
pm->head.pages =
|
74
|
+
pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
|
75
75
|
|
76
76
|
return pm->head.pages;
|
77
77
|
}
|
@@ -81,7 +81,7 @@ void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c)
|
|
81
81
|
if(pm->array_first->mask == 0xffffffff) {
|
82
82
|
/* free and move to last */
|
83
83
|
pm->array_last--;
|
84
|
-
|
84
|
+
xfree(c->pages);
|
85
85
|
*c = *pm->array_last;
|
86
86
|
return;
|
87
87
|
}
|
data/ext/msgpack/unpacker.c
CHANGED
@@ -68,7 +68,7 @@ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
|
|
68
68
|
/*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
|
69
69
|
#else
|
70
70
|
/*uk->stack = calloc(MSGPACK_UNPACKER_STACK_CAPACITY, sizeof(msgpack_unpacker_stack_t));*/
|
71
|
-
uk->stack =
|
71
|
+
uk->stack = xmalloc(MSGPACK_UNPACKER_STACK_CAPACITY * sizeof(msgpack_unpacker_stack_t));
|
72
72
|
#endif
|
73
73
|
uk->stack_capacity = MSGPACK_UNPACKER_STACK_CAPACITY;
|
74
74
|
}
|
@@ -78,7 +78,7 @@ void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk)
|
|
78
78
|
#ifdef UNPACKER_STACK_RMEM
|
79
79
|
msgpack_rmem_free(&s_stack_rmem, uk->stack);
|
80
80
|
#else
|
81
|
-
|
81
|
+
xfree(uk->stack);
|
82
82
|
#endif
|
83
83
|
|
84
84
|
msgpack_buffer_destroy(UNPACKER_BUFFER_(uk));
|
@@ -380,7 +380,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
380
380
|
case 0xc8: // ext 16
|
381
381
|
{
|
382
382
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 3);
|
383
|
-
uint16_t length = cb->u16;
|
383
|
+
uint16_t length = _msgpack_be16(cb->u16);
|
384
384
|
int ext_type = cb->buffer[2];
|
385
385
|
if(length == 0) {
|
386
386
|
return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
|
@@ -392,7 +392,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
392
392
|
case 0xc9: // ext 32
|
393
393
|
{
|
394
394
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 5);
|
395
|
-
uint32_t length = cb->u32;
|
395
|
+
uint32_t length = _msgpack_be32(cb->u32);
|
396
396
|
int ext_type = cb->buffer[4];
|
397
397
|
if(length == 0) {
|
398
398
|
return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
|
data/lib/msgpack/version.rb
CHANGED
data/spec/packer_spec.rb
CHANGED
@@ -223,4 +223,34 @@ describe MessagePack::Packer do
|
|
223
223
|
expect(two[:packer]).to eq(:to_msgpack_ext)
|
224
224
|
end
|
225
225
|
end
|
226
|
+
|
227
|
+
describe "ext formats" do
|
228
|
+
[1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b|
|
229
|
+
it "msgpack fixext #{n} format" do
|
230
|
+
MessagePack::ExtensionValue.new(1, "a"*n).to_msgpack.should ==
|
231
|
+
[b, 1].pack('CC') + "a"*n
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
it "msgpack ext 8 format" do
|
236
|
+
MessagePack::ExtensionValue.new(1, "").to_msgpack.should ==
|
237
|
+
[0xc7, 0, 1].pack('CCC') + ""
|
238
|
+
MessagePack::ExtensionValue.new(-1, "a"*255).to_msgpack.should ==
|
239
|
+
[0xc7, 255, -1].pack('CCC') + "a"*255
|
240
|
+
end
|
241
|
+
|
242
|
+
it "msgpack ext 16 format" do
|
243
|
+
MessagePack::ExtensionValue.new(1, "a"*256).to_msgpack.should ==
|
244
|
+
[0xc8, 256, 1].pack('CnC') + "a"*256
|
245
|
+
MessagePack::ExtensionValue.new(-1, "a"*65535).to_msgpack.should ==
|
246
|
+
[0xc8, 65535, -1].pack('CnC') + "a"*65535
|
247
|
+
end
|
248
|
+
|
249
|
+
it "msgpack ext 32 format" do
|
250
|
+
MessagePack::ExtensionValue.new(1, "a"*65536).to_msgpack.should ==
|
251
|
+
[0xc9, 65536, 1].pack('CNC') + "a"*65536
|
252
|
+
MessagePack::ExtensionValue.new(-1, "a"*65538).to_msgpack.should ==
|
253
|
+
[0xc9, 65538, -1].pack('CNC') + "a"*65538
|
254
|
+
end
|
255
|
+
end
|
226
256
|
end
|
data/spec/unpacker_spec.rb
CHANGED
@@ -260,6 +260,33 @@ describe MessagePack::Unpacker do
|
|
260
260
|
MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
|
261
261
|
end
|
262
262
|
|
263
|
+
describe "ext formats" do
|
264
|
+
let(:unpacker) { MessagePack::Unpacker.new(allow_unknown_ext: true) }
|
265
|
+
|
266
|
+
[1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b|
|
267
|
+
it "msgpack fixext #{n} format" do
|
268
|
+
unpacker.feed([b, 1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(1, "a"*n)
|
269
|
+
unpacker.feed([b, -1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*n)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
it "msgpack ext 8 format" do
|
274
|
+
unpacker.feed([0xc7, 0, 1].pack('CCC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
|
275
|
+
unpacker.feed([0xc7, 255, -1].pack('CCC') + "a"*255).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*255)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "msgpack ext 16 format" do
|
279
|
+
unpacker.feed([0xc8, 0, 1].pack('CnC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
|
280
|
+
unpacker.feed([0xc8, 256, -1].pack('CnC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "msgpack ext 32 format" do
|
284
|
+
unpacker.feed([0xc9, 0, 1].pack('CNC')).unpack.should == MessagePack::ExtensionValue.new(1, "")
|
285
|
+
unpacker.feed([0xc9, 256, -1].pack('CNC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256)
|
286
|
+
unpacker.feed([0xc9, 65536, -1].pack('CNC') + "a"*65536).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*65536)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
263
290
|
class ValueOne
|
264
291
|
attr_reader :num
|
265
292
|
def initialize(num)
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|