msgpack 1.7.1 → 1.8.0
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.
- checksums.yaml +4 -4
- data/ChangeLog +22 -0
- data/README.md +21 -12
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +5 -9
- data/ext/java/org/msgpack/jruby/Factory.java +7 -50
- data/ext/java/org/msgpack/jruby/Packer.java +3 -20
- data/ext/java/org/msgpack/jruby/Unpacker.java +8 -24
- data/ext/msgpack/buffer.c +12 -9
- data/ext/msgpack/buffer.h +134 -28
- data/ext/msgpack/buffer_class.c +72 -1
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/extconf.rb +6 -5
- data/ext/msgpack/factory_class.c +23 -60
- data/ext/msgpack/packer.c +12 -14
- data/ext/msgpack/packer.h +24 -21
- data/ext/msgpack/packer_class.c +6 -36
- data/ext/msgpack/packer_ext_registry.c +31 -28
- data/ext/msgpack/packer_ext_registry.h +10 -14
- data/ext/msgpack/unpacker.c +196 -90
- data/ext/msgpack/unpacker.h +18 -8
- data/ext/msgpack/unpacker_class.c +32 -47
- data/ext/msgpack/unpacker_ext_registry.c +4 -16
- data/ext/msgpack/unpacker_ext_registry.h +3 -7
- data/lib/msgpack/factory.rb +49 -10
- data/lib/msgpack/packer.rb +6 -1
- data/lib/msgpack/unpacker.rb +10 -1
- data/lib/msgpack/version.rb +1 -1
- data/msgpack.gemspec +2 -0
- metadata +5 -7
data/ext/msgpack/unpacker.h
CHANGED
@@ -31,6 +31,7 @@ enum stack_type_t {
|
|
31
31
|
STACK_TYPE_ARRAY,
|
32
32
|
STACK_TYPE_MAP_KEY,
|
33
33
|
STACK_TYPE_MAP_VALUE,
|
34
|
+
STACK_TYPE_RECURSIVE,
|
34
35
|
};
|
35
36
|
|
36
37
|
typedef struct {
|
@@ -44,31 +45,34 @@ struct msgpack_unpacker_stack_t {
|
|
44
45
|
size_t depth;
|
45
46
|
size_t capacity;
|
46
47
|
msgpack_unpacker_stack_entry_t *data;
|
47
|
-
msgpack_unpacker_stack_t *parent;
|
48
48
|
};
|
49
49
|
|
50
50
|
struct msgpack_unpacker_t {
|
51
51
|
msgpack_buffer_t buffer;
|
52
|
-
msgpack_unpacker_stack_t
|
53
|
-
|
52
|
+
msgpack_unpacker_stack_t stack;
|
53
|
+
msgpack_key_cache_t key_cache;
|
54
54
|
|
55
55
|
VALUE self;
|
56
56
|
VALUE last_object;
|
57
57
|
|
58
58
|
VALUE reading_raw;
|
59
59
|
size_t reading_raw_remaining;
|
60
|
-
int reading_raw_type;
|
61
60
|
|
62
61
|
VALUE buffer_ref;
|
63
62
|
|
64
63
|
msgpack_unpacker_ext_registry_t *ext_registry;
|
65
64
|
|
65
|
+
int reading_raw_type;
|
66
|
+
unsigned int head_byte;
|
67
|
+
|
66
68
|
/* options */
|
67
|
-
bool symbolize_keys;
|
68
|
-
bool freeze;
|
69
|
-
bool allow_unknown_ext;
|
70
|
-
bool optimized_symbol_ext_type;
|
71
69
|
int symbol_ext_type;
|
70
|
+
|
71
|
+
bool use_key_cache: 1;
|
72
|
+
bool symbolize_keys: 1;
|
73
|
+
bool freeze: 1;
|
74
|
+
bool allow_unknown_ext: 1;
|
75
|
+
bool optimized_symbol_ext_type: 1;
|
72
76
|
};
|
73
77
|
|
74
78
|
#define UNPACKER_BUFFER_(uk) (&(uk)->buffer)
|
@@ -100,6 +104,11 @@ static inline void msgpack_unpacker_set_symbolized_keys(msgpack_unpacker_t* uk,
|
|
100
104
|
uk->symbolize_keys = enable;
|
101
105
|
}
|
102
106
|
|
107
|
+
static inline void msgpack_unpacker_set_key_cache(msgpack_unpacker_t* uk, bool enable)
|
108
|
+
{
|
109
|
+
uk->use_key_cache = enable;
|
110
|
+
}
|
111
|
+
|
103
112
|
static inline void msgpack_unpacker_set_freeze(msgpack_unpacker_t* uk, bool enable)
|
104
113
|
{
|
105
114
|
uk->freeze = enable;
|
@@ -119,6 +128,7 @@ static inline void msgpack_unpacker_set_allow_unknown_ext(msgpack_unpacker_t* uk
|
|
119
128
|
#define PRIMITIVE_STACK_TOO_DEEP -3
|
120
129
|
#define PRIMITIVE_UNEXPECTED_TYPE -4
|
121
130
|
#define PRIMITIVE_UNEXPECTED_EXT_TYPE -5
|
131
|
+
#define PRIMITIVE_RECURSIVE_RAISED -6
|
122
132
|
|
123
133
|
int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth);
|
124
134
|
|
@@ -34,6 +34,7 @@ static VALUE eUnknownExtTypeError;
|
|
34
34
|
static VALUE mTypeError; // obsoleted. only for backward compatibility. See #86.
|
35
35
|
|
36
36
|
static VALUE sym_symbolize_keys;
|
37
|
+
static VALUE sym_key_cache;
|
37
38
|
static VALUE sym_freeze;
|
38
39
|
static VALUE sym_allow_unknown_ext;
|
39
40
|
|
@@ -58,14 +59,17 @@ static void Unpacker_mark(void *ptr)
|
|
58
59
|
|
59
60
|
static size_t Unpacker_memsize(const void *ptr)
|
60
61
|
{
|
62
|
+
const msgpack_unpacker_t* uk = ptr;
|
63
|
+
|
61
64
|
size_t total_size = sizeof(msgpack_unpacker_t);
|
62
65
|
|
63
|
-
const msgpack_unpacker_t* uk = ptr;
|
64
66
|
if (uk->ext_registry) {
|
65
67
|
total_size += sizeof(msgpack_unpacker_ext_registry_t) / (uk->ext_registry->borrow_count + 1);
|
66
68
|
}
|
67
69
|
|
68
|
-
|
70
|
+
if (uk->stack.data) {
|
71
|
+
total_size += (uk->stack.depth + 1) * sizeof(msgpack_unpacker_stack_t);
|
72
|
+
}
|
69
73
|
|
70
74
|
return total_size + msgpack_buffer_memsize(&uk->buffer);
|
71
75
|
}
|
@@ -125,6 +129,9 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
125
129
|
if(options != Qnil) {
|
126
130
|
VALUE v;
|
127
131
|
|
132
|
+
v = rb_hash_aref(options, sym_key_cache);
|
133
|
+
msgpack_unpacker_set_key_cache(uk, RTEST(v));
|
134
|
+
|
128
135
|
v = rb_hash_aref(options, sym_symbolize_keys);
|
129
136
|
msgpack_unpacker_set_symbolized_keys(uk, RTEST(v));
|
130
137
|
|
@@ -156,20 +163,28 @@ static VALUE Unpacker_allow_unknown_ext_p(VALUE self)
|
|
156
163
|
return uk->allow_unknown_ext ? Qtrue : Qfalse;
|
157
164
|
}
|
158
165
|
|
159
|
-
NORETURN(static void raise_unpacker_error(int r))
|
166
|
+
NORETURN(static void raise_unpacker_error(msgpack_unpacker_t *uk, int r))
|
160
167
|
{
|
168
|
+
uk->stack.depth = 0;
|
161
169
|
switch(r) {
|
162
170
|
case PRIMITIVE_EOF:
|
163
171
|
rb_raise(rb_eEOFError, "end of buffer reached");
|
172
|
+
break;
|
164
173
|
case PRIMITIVE_INVALID_BYTE:
|
165
174
|
rb_raise(eMalformedFormatError, "invalid byte");
|
175
|
+
break;
|
166
176
|
case PRIMITIVE_STACK_TOO_DEEP:
|
167
177
|
rb_raise(eStackError, "stack level too deep");
|
178
|
+
break;
|
168
179
|
case PRIMITIVE_UNEXPECTED_TYPE:
|
169
180
|
rb_raise(eUnexpectedTypeError, "unexpected type");
|
181
|
+
break;
|
170
182
|
case PRIMITIVE_UNEXPECTED_EXT_TYPE:
|
171
|
-
// rb_bug("unexpected extension type");
|
172
183
|
rb_raise(eUnknownExtTypeError, "unexpected extension type");
|
184
|
+
break;
|
185
|
+
case PRIMITIVE_RECURSIVE_RAISED:
|
186
|
+
rb_exc_raise(msgpack_unpacker_get_last_object(uk));
|
187
|
+
break;
|
173
188
|
default:
|
174
189
|
rb_raise(eUnpackError, "logically unknown error %d", r);
|
175
190
|
}
|
@@ -190,7 +205,7 @@ static VALUE Unpacker_read(VALUE self)
|
|
190
205
|
|
191
206
|
int r = msgpack_unpacker_read(uk, 0);
|
192
207
|
if(r < 0) {
|
193
|
-
raise_unpacker_error(r);
|
208
|
+
raise_unpacker_error(uk, r);
|
194
209
|
}
|
195
210
|
|
196
211
|
return msgpack_unpacker_get_last_object(uk);
|
@@ -202,7 +217,7 @@ static VALUE Unpacker_skip(VALUE self)
|
|
202
217
|
|
203
218
|
int r = msgpack_unpacker_skip(uk, 0);
|
204
219
|
if(r < 0) {
|
205
|
-
raise_unpacker_error(r);
|
220
|
+
raise_unpacker_error(uk, r);
|
206
221
|
}
|
207
222
|
|
208
223
|
return Qnil;
|
@@ -214,7 +229,7 @@ static VALUE Unpacker_skip_nil(VALUE self)
|
|
214
229
|
|
215
230
|
int r = msgpack_unpacker_skip_nil(uk);
|
216
231
|
if(r < 0) {
|
217
|
-
raise_unpacker_error(r);
|
232
|
+
raise_unpacker_error(uk, r);
|
218
233
|
}
|
219
234
|
|
220
235
|
if(r) {
|
@@ -230,7 +245,7 @@ static VALUE Unpacker_read_array_header(VALUE self)
|
|
230
245
|
uint32_t size;
|
231
246
|
int r = msgpack_unpacker_read_array_header(uk, &size);
|
232
247
|
if(r < 0) {
|
233
|
-
raise_unpacker_error(r);
|
248
|
+
raise_unpacker_error(uk, r);
|
234
249
|
}
|
235
250
|
|
236
251
|
return ULONG2NUM(size); // long at least 32 bits
|
@@ -243,7 +258,7 @@ static VALUE Unpacker_read_map_header(VALUE self)
|
|
243
258
|
uint32_t size;
|
244
259
|
int r = msgpack_unpacker_read_map_header(uk, &size);
|
245
260
|
if(r < 0) {
|
246
|
-
raise_unpacker_error(
|
261
|
+
raise_unpacker_error(uk, r);
|
247
262
|
}
|
248
263
|
|
249
264
|
return ULONG2NUM(size); // long at least 32 bits
|
@@ -270,15 +285,9 @@ static VALUE Unpacker_each_impl(VALUE self)
|
|
270
285
|
if(r == PRIMITIVE_EOF) {
|
271
286
|
return Qnil;
|
272
287
|
}
|
273
|
-
raise_unpacker_error(r);
|
288
|
+
raise_unpacker_error(uk, r);
|
274
289
|
}
|
275
290
|
VALUE v = msgpack_unpacker_get_last_object(uk);
|
276
|
-
#ifdef JRUBY
|
277
|
-
/* TODO JRuby's rb_yield behaves differently from Ruby 1.9.3 or Rubinius. */
|
278
|
-
if(rb_type(v) == T_ARRAY) {
|
279
|
-
v = rb_ary_new3(1, v);
|
280
|
-
}
|
281
|
-
#endif
|
282
291
|
rb_yield(v);
|
283
292
|
}
|
284
293
|
}
|
@@ -346,43 +355,19 @@ static VALUE Unpacker_registered_types_internal(VALUE self)
|
|
346
355
|
return mapping;
|
347
356
|
}
|
348
357
|
|
349
|
-
static VALUE
|
358
|
+
static VALUE Unpacker_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE proc)
|
350
359
|
{
|
351
360
|
if (OBJ_FROZEN(self)) {
|
352
361
|
rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Unpacker");
|
353
362
|
}
|
354
363
|
|
355
|
-
|
356
|
-
|
357
|
-
int ext_type;
|
358
|
-
VALUE proc;
|
359
|
-
VALUE arg;
|
360
|
-
VALUE ext_module;
|
361
|
-
|
362
|
-
switch (argc) {
|
363
|
-
case 1:
|
364
|
-
/* register_type(0x7f) {|data| block... } */
|
365
|
-
rb_need_block();
|
366
|
-
proc = rb_block_lambda();
|
367
|
-
arg = proc;
|
368
|
-
ext_module = Qnil;
|
369
|
-
break;
|
370
|
-
case 3:
|
371
|
-
/* register_type(0x7f, Time, :from_msgpack_ext) */
|
372
|
-
ext_module = argv[1];
|
373
|
-
arg = argv[2];
|
374
|
-
proc = rb_obj_method(ext_module, arg);
|
375
|
-
break;
|
376
|
-
default:
|
377
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
|
378
|
-
}
|
379
|
-
|
380
|
-
ext_type = NUM2INT(argv[0]);
|
364
|
+
int ext_type = NUM2INT(rb_ext_type);
|
381
365
|
if(ext_type < -128 || ext_type > 127) {
|
382
366
|
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
383
367
|
}
|
384
368
|
|
385
|
-
|
369
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
370
|
+
msgpack_unpacker_ext_registry_put(self, &uk->ext_registry, ext_module, ext_type, 0, proc);
|
386
371
|
|
387
372
|
return Qnil;
|
388
373
|
}
|
@@ -393,7 +378,7 @@ static VALUE Unpacker_full_unpack(VALUE self)
|
|
393
378
|
|
394
379
|
int r = msgpack_unpacker_read(uk, 0);
|
395
380
|
if(r < 0) {
|
396
|
-
raise_unpacker_error(r);
|
381
|
+
raise_unpacker_error(uk, r);
|
397
382
|
}
|
398
383
|
|
399
384
|
/* raise if extra bytes follow */
|
@@ -415,7 +400,6 @@ VALUE MessagePack_Unpacker_new(int argc, VALUE* argv)
|
|
415
400
|
void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
416
401
|
{
|
417
402
|
msgpack_unpacker_static_init();
|
418
|
-
msgpack_unpacker_ext_registry_static_init();
|
419
403
|
|
420
404
|
mTypeError = rb_define_module_under(mMessagePack, "TypeError");
|
421
405
|
|
@@ -433,6 +417,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
433
417
|
eUnknownExtTypeError = rb_define_class_under(mMessagePack, "UnknownExtTypeError", eUnpackError);
|
434
418
|
|
435
419
|
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
420
|
+
sym_key_cache = ID2SYM(rb_intern("key_cache"));
|
436
421
|
sym_freeze = ID2SYM(rb_intern("freeze"));
|
437
422
|
sym_allow_unknown_ext = ID2SYM(rb_intern("allow_unknown_ext"));
|
438
423
|
|
@@ -456,7 +441,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
456
441
|
rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
|
457
442
|
|
458
443
|
rb_define_private_method(cMessagePack_Unpacker, "registered_types_internal", Unpacker_registered_types_internal, 0);
|
459
|
-
|
444
|
+
rb_define_private_method(cMessagePack_Unpacker, "register_type_internal", Unpacker_register_type_internal, 3);
|
460
445
|
|
461
446
|
rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0);
|
462
447
|
}
|
@@ -18,19 +18,6 @@
|
|
18
18
|
|
19
19
|
#include "unpacker_ext_registry.h"
|
20
20
|
|
21
|
-
static ID s_call;
|
22
|
-
static ID s_dup;
|
23
|
-
|
24
|
-
void msgpack_unpacker_ext_registry_static_init(void)
|
25
|
-
{
|
26
|
-
s_call = rb_intern("call");
|
27
|
-
s_dup = rb_intern("dup");
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
void msgpack_unpacker_ext_registry_static_destroy(void)
|
32
|
-
{ }
|
33
|
-
|
34
21
|
void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg)
|
35
22
|
{
|
36
23
|
if (ukrg) {
|
@@ -76,11 +63,12 @@ void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg
|
|
76
63
|
}
|
77
64
|
}
|
78
65
|
|
79
|
-
void msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t** ukrg,
|
80
|
-
VALUE ext_module, int ext_type, int flags, VALUE proc
|
66
|
+
void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg,
|
67
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc)
|
81
68
|
{
|
82
69
|
msgpack_unpacker_ext_registry_t* ext_registry = msgpack_unpacker_ext_registry_cow(*ukrg);
|
83
70
|
|
84
|
-
|
71
|
+
VALUE entry = rb_ary_new3(3, ext_module, proc, INT2FIX(flags));
|
72
|
+
RB_OBJ_WRITE(owner, &ext_registry->array[ext_type + 128], entry);
|
85
73
|
*ukrg = ext_registry;
|
86
74
|
}
|
@@ -31,10 +31,6 @@ struct msgpack_unpacker_ext_registry_t {
|
|
31
31
|
VALUE array[256];
|
32
32
|
};
|
33
33
|
|
34
|
-
void msgpack_unpacker_ext_registry_static_init(void);
|
35
|
-
|
36
|
-
void msgpack_unpacker_ext_registry_static_destroy(void);
|
37
|
-
|
38
34
|
void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg);
|
39
35
|
|
40
36
|
static inline void msgpack_unpacker_ext_registry_borrow(msgpack_unpacker_ext_registry_t* src, msgpack_unpacker_ext_registry_t** dst)
|
@@ -47,8 +43,8 @@ static inline void msgpack_unpacker_ext_registry_borrow(msgpack_unpacker_ext_reg
|
|
47
43
|
|
48
44
|
void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg);
|
49
45
|
|
50
|
-
void msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t** ukrg,
|
51
|
-
VALUE ext_module, int ext_type, int flags, VALUE proc
|
46
|
+
void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg,
|
47
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc);
|
52
48
|
|
53
49
|
static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_registry_t* ukrg,
|
54
50
|
int ext_type, int* ext_flags_result)
|
@@ -56,7 +52,7 @@ static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_re
|
|
56
52
|
if (ukrg) {
|
57
53
|
VALUE entry = ukrg->array[ext_type + 128];
|
58
54
|
if (entry != Qnil) {
|
59
|
-
*ext_flags_result = FIX2INT(rb_ary_entry(entry,
|
55
|
+
*ext_flags_result = FIX2INT(rb_ary_entry(entry, 2));
|
60
56
|
return rb_ary_entry(entry, 1);
|
61
57
|
}
|
62
58
|
}
|
data/lib/msgpack/factory.rb
CHANGED
@@ -2,11 +2,46 @@ module MessagePack
|
|
2
2
|
class Factory
|
3
3
|
# see ext for other methods
|
4
4
|
|
5
|
+
def register_type(type, klass, options = { packer: :to_msgpack_ext, unpacker: :from_msgpack_ext })
|
6
|
+
raise FrozenError, "can't modify frozen MessagePack::Factory" if frozen?
|
7
|
+
|
8
|
+
if options
|
9
|
+
options = options.dup
|
10
|
+
case packer = options[:packer]
|
11
|
+
when nil, Proc
|
12
|
+
# all good
|
13
|
+
when String, Symbol
|
14
|
+
options[:packer] = packer.to_sym.to_proc
|
15
|
+
when Method
|
16
|
+
options[:packer] = packer.to_proc
|
17
|
+
when packer.respond_to?(:call)
|
18
|
+
options[:packer] = packer.method(:call).to_proc
|
19
|
+
else
|
20
|
+
raise ::TypeError, "expected :packer argument to be a callable object, got: #{packer.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
case unpacker = options[:unpacker]
|
24
|
+
when nil, Proc
|
25
|
+
# all good
|
26
|
+
when String, Symbol
|
27
|
+
options[:unpacker] = klass.method(unpacker).to_proc
|
28
|
+
when Method
|
29
|
+
options[:unpacker] = unpacker.to_proc
|
30
|
+
when packer.respond_to?(:call)
|
31
|
+
options[:unpacker] = unpacker.method(:call).to_proc
|
32
|
+
else
|
33
|
+
raise ::TypeError, "expected :unpacker argument to be a callable object, got: #{unpacker.inspect}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
register_type_internal(type, klass, options)
|
38
|
+
end
|
39
|
+
|
5
40
|
# [ {type: id, class: Class(or nil), packer: arg, unpacker: arg}, ... ]
|
6
41
|
def registered_types(selector=:both)
|
7
42
|
packer, unpacker = registered_types_internal
|
8
|
-
# packer: Class -> [tid, proc,
|
9
|
-
# unpacker: tid -> [klass, proc,
|
43
|
+
# packer: Class -> [tid, proc, _flags]
|
44
|
+
# unpacker: tid -> [klass, proc, _flags]
|
10
45
|
|
11
46
|
list = []
|
12
47
|
|
@@ -14,27 +49,31 @@ module MessagePack
|
|
14
49
|
when :both
|
15
50
|
packer.each_pair do |klass, ary|
|
16
51
|
type = ary[0]
|
17
|
-
|
18
|
-
|
19
|
-
if unpacker.has_key?(type)
|
20
|
-
|
52
|
+
packer_proc = ary[1]
|
53
|
+
unpacker_proc = nil
|
54
|
+
if unpacker.has_key?(type)
|
55
|
+
unpacker_proc = unpacker.delete(type)[1]
|
21
56
|
end
|
22
|
-
list << {type: type, class: klass, packer:
|
57
|
+
list << {type: type, class: klass, packer: packer_proc, unpacker: unpacker_proc}
|
23
58
|
end
|
24
59
|
|
25
60
|
# unpacker definition only
|
26
61
|
unpacker.each_pair do |type, ary|
|
27
|
-
list << {type: type, class: ary[0], packer: nil, unpacker: ary[
|
62
|
+
list << {type: type, class: ary[0], packer: nil, unpacker: ary[1]}
|
28
63
|
end
|
29
64
|
|
30
65
|
when :packer
|
31
66
|
packer.each_pair do |klass, ary|
|
32
|
-
|
67
|
+
if ary[1]
|
68
|
+
list << {type: ary[0], class: klass, packer: ary[1]}
|
69
|
+
end
|
33
70
|
end
|
34
71
|
|
35
72
|
when :unpacker
|
36
73
|
unpacker.each_pair do |type, ary|
|
37
|
-
|
74
|
+
if ary[1]
|
75
|
+
list << {type: type, class: ary[0], unpacker: ary[1]}
|
76
|
+
end
|
38
77
|
end
|
39
78
|
|
40
79
|
else
|
data/lib/msgpack/packer.rb
CHANGED
@@ -6,11 +6,16 @@ module MessagePack
|
|
6
6
|
undef_method :dup
|
7
7
|
undef_method :clone
|
8
8
|
|
9
|
+
def register_type(type, klass, method_name = nil, &block)
|
10
|
+
raise ArgumentError, "expected Module/Class got: #{klass.inspect}" unless klass.is_a?(Module)
|
11
|
+
register_type_internal(type, klass, block || method_name.to_proc)
|
12
|
+
end
|
13
|
+
|
9
14
|
def registered_types
|
10
15
|
list = []
|
11
16
|
|
12
17
|
registered_types_internal.each_pair do |klass, ary|
|
13
|
-
list << {type: ary[0], class: klass, packer: ary[
|
18
|
+
list << {type: ary[0], class: klass, packer: ary[1]}
|
14
19
|
end
|
15
20
|
|
16
21
|
list.sort{|a, b| a[:type] <=> b[:type] }
|
data/lib/msgpack/unpacker.rb
CHANGED
@@ -6,11 +6,20 @@ module MessagePack
|
|
6
6
|
undef_method :dup
|
7
7
|
undef_method :clone
|
8
8
|
|
9
|
+
def register_type(type, klass = nil, method_name = nil, &block)
|
10
|
+
if klass && method_name
|
11
|
+
block = klass.method(method_name).to_proc
|
12
|
+
elsif !block_given?
|
13
|
+
raise ArgumentError, "register_type takes either 3 arguments or a block"
|
14
|
+
end
|
15
|
+
register_type_internal(type, klass, block)
|
16
|
+
end
|
17
|
+
|
9
18
|
def registered_types
|
10
19
|
list = []
|
11
20
|
|
12
21
|
registered_types_internal.each_pair do |type, ary|
|
13
|
-
list << {type: type, class: ary[0], unpacker: ary[
|
22
|
+
list << {type: type, class: ary[0], unpacker: ary[1]}
|
14
23
|
end
|
15
24
|
|
16
25
|
list.sort{|a, b| a[:type] <=> b[:type] }
|
data/lib/msgpack/version.rb
CHANGED
data/msgpack.gemspec
CHANGED
@@ -31,4 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency 'yard'
|
32
32
|
s.add_development_dependency 'json'
|
33
33
|
s.add_development_dependency 'benchmark-ips', ['~> 2.10.0']
|
34
|
+
|
35
|
+
s.metadata["changelog_uri"] = "https://github.com/msgpack/msgpack-ruby/blob/master/ChangeLog"
|
34
36
|
end
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
- Theo Hultberg
|
9
9
|
- Satoshi Tagomori
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: bundler
|
@@ -192,8 +191,8 @@ files:
|
|
192
191
|
homepage: http://msgpack.org/
|
193
192
|
licenses:
|
194
193
|
- Apache 2.0
|
195
|
-
metadata:
|
196
|
-
|
194
|
+
metadata:
|
195
|
+
changelog_uri: https://github.com/msgpack/msgpack-ruby/blob/master/ChangeLog
|
197
196
|
rdoc_options: []
|
198
197
|
require_paths:
|
199
198
|
- lib
|
@@ -208,8 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
207
|
- !ruby/object:Gem::Version
|
209
208
|
version: '0'
|
210
209
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
212
|
-
signing_key:
|
210
|
+
rubygems_version: 3.6.2
|
213
211
|
specification_version: 4
|
214
212
|
summary: MessagePack, a binary-based efficient data interchange format.
|
215
213
|
test_files: []
|