msgpack 0.5.7-x86-mingw32 → 0.5.8-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog +6 -0
- data/Rakefile +1 -1
- data/doclib/msgpack.rb +34 -12
- data/doclib/msgpack/packer.rb +2 -0
- data/doclib/msgpack/unpacker.rb +5 -1
- data/ext/msgpack/extconf.rb +1 -0
- data/ext/msgpack/packer_class.c +27 -19
- data/ext/msgpack/unpacker.c +11 -1
- data/ext/msgpack/unpacker.h +8 -0
- data/ext/msgpack/unpacker_class.c +31 -20
- data/ext/msgpack/unpacker_class.h +2 -0
- data/lib/msgpack.rb +3 -6
- data/lib/msgpack/version.rb +1 -1
- data/spec/buffer_io_spec.rb +1 -1
- data/spec/unpacker_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
data.tar.gz: d63d462c8ef2528eabc912b74929c88257bf29abf05486550138e5438fa5ebdd65f6310f48c6f01074ba0ca9e0764cbb3770be3221353e9bcf88288a13d29bfd
|
4
|
-
metadata.gz: 43d088ada9f7b4d4a06542011ed8b7f48d38bc375964f4b00427e1d5892f39d75d73d54cc00b2a500c91231534b028e8e0b131174564079038324d123200062d
|
5
2
|
SHA1:
|
6
|
-
|
7
|
-
|
3
|
+
metadata.gz: 168f0afcffc21c9fc7fa34d194fbb9108ba5373c
|
4
|
+
data.tar.gz: 49c15b833c1229cf9b4ace272f2260baa5adb4bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbd82ec3dbc2349ec7727ec7457dcb1929a9095d331161fe91e7e4fef31b66e874911f5e68878ccd63d03328cc6fae5b38b9b06ebeb2b4c0ac0b0fe8336c457d
|
7
|
+
data.tar.gz: 04beab2aa8c28ae6aed008f97cfda632dba370b4e7a892c89d80d67e4f3262e81503ba425ae2aa926e085b518afd325d9e2b295bd753c6205503e062a77c62e3
|
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
data/doclib/msgpack.rb
CHANGED
@@ -3,53 +3,75 @@ module MessagePack
|
|
3
3
|
#
|
4
4
|
# Serializes an object into an IO or String.
|
5
5
|
#
|
6
|
-
# @overload dump(obj)
|
6
|
+
# @overload dump(obj, options={})
|
7
|
+
# @param obj [Object] object to be serialized
|
8
|
+
# @param options [Hash]
|
7
9
|
# @return [String] serialized data
|
8
10
|
#
|
9
|
-
# @overload dump(obj, io)
|
11
|
+
# @overload dump(obj, io, options={})
|
12
|
+
# @param obj [Object] object to be serialized
|
13
|
+
# @param io [IO]
|
14
|
+
# @param options [Hash]
|
10
15
|
# @return [IO]
|
11
16
|
#
|
12
|
-
|
17
|
+
# See Packer#initialize for supported options.
|
18
|
+
#
|
19
|
+
def self.dump(obj)
|
13
20
|
end
|
14
21
|
|
15
22
|
#
|
16
23
|
# Serializes an object into an IO or String. Alias of dump.
|
17
24
|
#
|
18
|
-
# @overload
|
25
|
+
# @overload pack(obj, options={})
|
26
|
+
# @param obj [Object] object to be serialized
|
27
|
+
# @param options [Hash]
|
19
28
|
# @return [String] serialized data
|
20
29
|
#
|
21
|
-
# @overload
|
30
|
+
# @overload pack(obj, io, options={})
|
31
|
+
# @param obj [Object] object to be serialized
|
32
|
+
# @param io [IO]
|
33
|
+
# @param options [Hash]
|
22
34
|
# @return [IO]
|
23
35
|
#
|
24
|
-
|
36
|
+
# See Packer#initialize for supported options.
|
37
|
+
#
|
38
|
+
def self.pack(obj)
|
25
39
|
end
|
26
40
|
|
27
41
|
#
|
28
42
|
# Deserializes an object from an IO or String.
|
29
43
|
#
|
30
|
-
# @overload load(string)
|
44
|
+
# @overload load(string, options={})
|
31
45
|
# @param string [String] data to deserialize
|
46
|
+
# @param options [Hash]
|
32
47
|
#
|
33
|
-
# @overload load(io)
|
48
|
+
# @overload load(io, options={})
|
34
49
|
# @param io [IO]
|
50
|
+
# @param options [Hash]
|
35
51
|
#
|
36
52
|
# @return [Object] deserialized object
|
37
53
|
#
|
38
|
-
|
54
|
+
# See Unpacker#initialize for supported options.
|
55
|
+
#
|
56
|
+
def self.load(src, options={})
|
39
57
|
end
|
40
58
|
|
41
59
|
#
|
42
60
|
# Deserializes an object from an IO or String. Alias of load.
|
43
61
|
#
|
44
|
-
# @overload unpack(string)
|
62
|
+
# @overload unpack(string, options={})
|
45
63
|
# @param string [String] data to deserialize
|
64
|
+
# @param options [Hash]
|
46
65
|
#
|
47
|
-
# @overload unpack(io)
|
66
|
+
# @overload unpack(io, options={})
|
48
67
|
# @param io [IO]
|
68
|
+
# @param options [Hash]
|
49
69
|
#
|
50
70
|
# @return [Object] deserialized object
|
51
71
|
#
|
52
|
-
|
72
|
+
# See Unpacker#initialize for supported options.
|
73
|
+
#
|
74
|
+
def self.unpack(src, options={})
|
53
75
|
end
|
54
76
|
end
|
55
77
|
|
data/doclib/msgpack/packer.rb
CHANGED
@@ -18,6 +18,8 @@ module MessagePack
|
|
18
18
|
# This packer writes serialzied objects into the IO when the internal buffer is filled.
|
19
19
|
# _io_ must respond to write(string) or append(string) method.
|
20
20
|
#
|
21
|
+
# See also Buffer#initialize for options.
|
22
|
+
#
|
21
23
|
def initialize(*args)
|
22
24
|
end
|
23
25
|
|
data/doclib/msgpack/unpacker.rb
CHANGED
@@ -17,7 +17,11 @@ module MessagePack
|
|
17
17
|
# This unpacker reads data from the _io_ to fill the internal buffer.
|
18
18
|
# _io_ must respond to readpartial(length [,string]) or read(length [,string]) method.
|
19
19
|
#
|
20
|
-
#
|
20
|
+
# Supported options:
|
21
|
+
#
|
22
|
+
# * *:symbolize_keys* deserialize keys of Hash objects as Symbol instead of String
|
23
|
+
#
|
24
|
+
# See also Buffer#initialize for other options.
|
21
25
|
#
|
22
26
|
def initialize(*args)
|
23
27
|
end
|
data/ext/msgpack/extconf.rb
CHANGED
data/ext/msgpack/packer_class.c
CHANGED
@@ -79,19 +79,17 @@ static VALUE Packer_initialize(int argc, VALUE* argv, VALUE self)
|
|
79
79
|
io = argv[0];
|
80
80
|
options = argv[1];
|
81
81
|
if(rb_type(options) != T_HASH) {
|
82
|
-
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(
|
82
|
+
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
83
83
|
}
|
84
84
|
|
85
85
|
} else {
|
86
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..
|
86
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
87
87
|
}
|
88
88
|
|
89
89
|
PACKER(self, pk);
|
90
|
-
|
91
|
-
MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
|
92
|
-
}
|
90
|
+
MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
|
93
91
|
|
94
|
-
// TODO options
|
92
|
+
// TODO MessagePack_Unpacker_initialize and options
|
95
93
|
|
96
94
|
return self;
|
97
95
|
}
|
@@ -194,20 +192,31 @@ static VALUE Packer_write_to(VALUE self, VALUE io)
|
|
194
192
|
|
195
193
|
VALUE MessagePack_pack(int argc, VALUE* argv)
|
196
194
|
{
|
197
|
-
// TODO options
|
198
|
-
|
199
195
|
VALUE v;
|
200
196
|
VALUE io = Qnil;
|
197
|
+
VALUE options = Qnil;
|
201
198
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
199
|
+
if(argc == 1) {
|
200
|
+
v = argv[0];
|
201
|
+
|
202
|
+
} else if(argc == 2) {
|
203
|
+
v = argv[0];
|
204
|
+
if(rb_type(argv[1]) == T_HASH) {
|
205
|
+
options = argv[1];
|
206
|
+
} else {
|
207
|
+
io = argv[1];
|
208
|
+
}
|
209
|
+
|
210
|
+
} else if(argc == 3) {
|
207
211
|
v = argv[0];
|
208
|
-
|
209
|
-
|
210
|
-
|
212
|
+
io = argv[1];
|
213
|
+
options = argv[2];
|
214
|
+
if(rb_type(options) != T_HASH) {
|
215
|
+
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
216
|
+
}
|
217
|
+
|
218
|
+
} else {
|
219
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", argc);
|
211
220
|
}
|
212
221
|
|
213
222
|
VALUE self = Packer_alloc(cMessagePack_Packer);
|
@@ -215,9 +224,8 @@ VALUE MessagePack_pack(int argc, VALUE* argv)
|
|
215
224
|
//msgpack_packer_reset(s_packer);
|
216
225
|
//msgpack_buffer_reset_io(PACKER_BUFFER_(s_packer));
|
217
226
|
|
218
|
-
|
219
|
-
|
220
|
-
}
|
227
|
+
MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
|
228
|
+
// TODO MessagePack_Unpacker_initialize and options
|
221
229
|
|
222
230
|
msgpack_packer_write_value(pk, v);
|
223
231
|
|
data/ext/msgpack/unpacker.c
CHANGED
@@ -607,7 +607,17 @@ int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth)
|
|
607
607
|
top->type = STACK_TYPE_MAP_VALUE;
|
608
608
|
break;
|
609
609
|
case STACK_TYPE_MAP_VALUE:
|
610
|
-
|
610
|
+
if(uk->symbolize_keys && rb_type(top->key) == T_STRING) {
|
611
|
+
/* here uses rb_intern_str instead of rb_intern so that Ruby VM can GC unused symbols */
|
612
|
+
#ifndef HAVE_RB_INTERN_STR
|
613
|
+
/* MRI 1.8 doesn't have rb_intern_str or rb_intern2 */
|
614
|
+
rb_hash_aset(top->object, ID2SYM(rb_intern(RSTRING_PTR(top->key))), uk->last_object);
|
615
|
+
#else
|
616
|
+
rb_hash_aset(top->object, ID2SYM(rb_intern_str(top->key)), uk->last_object);
|
617
|
+
#endif
|
618
|
+
} else {
|
619
|
+
rb_hash_aset(top->object, top->key, uk->last_object);
|
620
|
+
}
|
611
621
|
top->type = STACK_TYPE_MAP_KEY;
|
612
622
|
break;
|
613
623
|
}
|
data/ext/msgpack/unpacker.h
CHANGED
@@ -57,6 +57,9 @@ struct msgpack_unpacker_t {
|
|
57
57
|
size_t reading_raw_remaining;
|
58
58
|
|
59
59
|
VALUE buffer_ref;
|
60
|
+
|
61
|
+
/* options */
|
62
|
+
bool symbolize_keys;
|
60
63
|
};
|
61
64
|
|
62
65
|
#define UNPACKER_BUFFER_(uk) (&(uk)->buffer)
|
@@ -83,6 +86,11 @@ void msgpack_unpacker_mark(msgpack_unpacker_t* uk);
|
|
83
86
|
|
84
87
|
void msgpack_unpacker_reset(msgpack_unpacker_t* uk);
|
85
88
|
|
89
|
+
static inline void msgpack_unpacker_set_symbolized_keys(msgpack_unpacker_t* uk, bool enable)
|
90
|
+
{
|
91
|
+
uk->symbolize_keys = enable;
|
92
|
+
}
|
93
|
+
|
86
94
|
|
87
95
|
/* error codes */
|
88
96
|
#define PRIMITIVE_CONTAINER_START 1
|
@@ -70,6 +70,9 @@ static VALUE Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
70
70
|
VALUE v = argv[0];
|
71
71
|
if(rb_type(v) == T_HASH) {
|
72
72
|
options = v;
|
73
|
+
if(rb_type(options) != T_HASH) {
|
74
|
+
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
75
|
+
}
|
73
76
|
} else {
|
74
77
|
io = v;
|
75
78
|
}
|
@@ -78,23 +81,32 @@ static VALUE Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
78
81
|
io = argv[0];
|
79
82
|
options = argv[1];
|
80
83
|
if(rb_type(options) != T_HASH) {
|
81
|
-
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(
|
84
|
+
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
82
85
|
}
|
83
86
|
|
84
87
|
} else {
|
85
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..
|
88
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
86
89
|
}
|
87
90
|
|
88
91
|
UNPACKER(self, uk);
|
89
|
-
if(io != Qnil || options != Qnil) {
|
90
|
-
MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, options);
|
91
|
-
}
|
92
92
|
|
93
|
-
|
93
|
+
MessagePack_Unpacker_initialize(uk, io, options);
|
94
94
|
|
95
95
|
return self;
|
96
96
|
}
|
97
97
|
|
98
|
+
void MessagePack_Unpacker_initialize(msgpack_unpacker_t* uk, VALUE io, VALUE options)
|
99
|
+
{
|
100
|
+
MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, options);
|
101
|
+
|
102
|
+
if(options != Qnil) {
|
103
|
+
VALUE v;
|
104
|
+
|
105
|
+
v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys")));
|
106
|
+
msgpack_unpacker_set_symbolized_keys(uk, RTEST(v));
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
98
110
|
static void raise_unpacker_error(int r)
|
99
111
|
{
|
100
112
|
switch(r) {
|
@@ -288,19 +300,20 @@ static VALUE Unpacker_reset(VALUE self)
|
|
288
300
|
VALUE MessagePack_unpack(int argc, VALUE* argv)
|
289
301
|
{
|
290
302
|
VALUE src;
|
303
|
+
VALUE options = Qnil;
|
291
304
|
|
292
305
|
switch(argc) {
|
306
|
+
case 2:
|
307
|
+
options = argv[1];
|
308
|
+
if(rb_type(options) != T_HASH) {
|
309
|
+
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
310
|
+
}
|
311
|
+
/* pass-through */
|
293
312
|
case 1:
|
294
313
|
src = argv[0];
|
295
314
|
break;
|
296
315
|
default:
|
297
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
|
298
|
-
}
|
299
|
-
|
300
|
-
VALUE io = Qnil;
|
301
|
-
if(rb_type(src) != T_STRING) {
|
302
|
-
io = src;
|
303
|
-
src = Qnil;
|
316
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
304
317
|
}
|
305
318
|
|
306
319
|
VALUE self = Unpacker_alloc(cMessagePack_Unpacker);
|
@@ -308,16 +321,14 @@ VALUE MessagePack_unpack(int argc, VALUE* argv)
|
|
308
321
|
//msgpack_unpacker_reset(s_unpacker);
|
309
322
|
//msgpack_buffer_reset_io(UNPACKER_BUFFER_(s_unpacker));
|
310
323
|
|
311
|
-
/* prefer reference than copying */
|
324
|
+
/* prefer reference than copying; see MessagePack_Unpacker_module_init */
|
312
325
|
msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(uk), 0);
|
313
326
|
|
314
|
-
if(
|
315
|
-
|
316
|
-
}
|
317
|
-
|
318
|
-
if(src != Qnil) {
|
319
|
-
/* prefer reference than copying; see MessagePack_Unpacker_module_init */
|
327
|
+
if(rb_type(src) == T_STRING) {
|
328
|
+
MessagePack_Unpacker_initialize(uk, Qnil, options);
|
320
329
|
msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), src);
|
330
|
+
} else {
|
331
|
+
MessagePack_Unpacker_initialize(uk, src, options);
|
321
332
|
}
|
322
333
|
|
323
334
|
int r = msgpack_unpacker_read(uk, 0);
|
data/lib/msgpack.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
require File.join(here, 'msgpack', 'version')
|
1
|
+
require "msgpack/version"
|
3
2
|
begin
|
4
|
-
|
5
|
-
ver = m[1]
|
6
|
-
require File.join(here, 'msgpack', ver, 'msgpack')
|
3
|
+
require "msgpack/#{RUBY_VERSION[/\d+.\d+/]}/msgpack"
|
7
4
|
rescue LoadError
|
8
|
-
require
|
5
|
+
require "msgpack/msgpack"
|
9
6
|
end
|
data/lib/msgpack/version.rb
CHANGED
data/spec/buffer_io_spec.rb
CHANGED
data/spec/unpacker_spec.rb
CHANGED
@@ -230,6 +230,18 @@ describe Unpacker do
|
|
230
230
|
parsed.should == true
|
231
231
|
end
|
232
232
|
|
233
|
+
it 'MessagePack.unpack symbolize_keys' do
|
234
|
+
symbolized_hash = {:a => 'b', :c => 'd'}
|
235
|
+
MessagePack.load(MessagePack.pack(symbolized_hash), symbolize_keys: true).should == symbolized_hash
|
236
|
+
MessagePack.unpack(MessagePack.pack(symbolized_hash), symbolize_keys: true).should == symbolized_hash
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'Unpacker#unpack symbolize_keys' do
|
240
|
+
unpacker = Unpacker.new(:symbolize_keys => true)
|
241
|
+
symbolized_hash = {:a => 'b', :c => 'd'}
|
242
|
+
unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
|
243
|
+
end
|
244
|
+
|
233
245
|
it "msgpack str 8 type" do
|
234
246
|
MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
|
235
247
|
MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
|
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.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-14 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
type: :development
|