msgpack 0.7.4 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +27 -14
  5. data/ChangeLog +89 -1
  6. data/Gemfile +6 -1
  7. data/README.rdoc +55 -1
  8. data/Rakefile +5 -1
  9. data/bench/pack_symbols.rb +28 -0
  10. data/bench/run_symbols.sh +26 -0
  11. data/doclib/msgpack.rb +2 -2
  12. data/doclib/msgpack/core_ext.rb +20 -20
  13. data/doclib/msgpack/factory.rb +33 -0
  14. data/doclib/msgpack/packer.rb +20 -0
  15. data/doclib/msgpack/time.rb +22 -0
  16. data/doclib/msgpack/timestamp.rb +44 -0
  17. data/ext/java/org/msgpack/jruby/Buffer.java +4 -0
  18. data/ext/java/org/msgpack/jruby/Encoder.java +48 -18
  19. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +67 -38
  20. data/ext/java/org/msgpack/jruby/Factory.java +20 -8
  21. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +0 -92
  22. data/ext/java/org/msgpack/jruby/Packer.java +114 -11
  23. data/ext/java/org/msgpack/jruby/Unpacker.java +15 -8
  24. data/ext/msgpack/buffer.h +14 -0
  25. data/ext/msgpack/buffer_class.c +1 -1
  26. data/ext/msgpack/compat.h +10 -0
  27. data/ext/msgpack/factory_class.c +24 -17
  28. data/ext/msgpack/factory_class.h +0 -2
  29. data/ext/msgpack/packer.c +5 -4
  30. data/ext/msgpack/packer.h +13 -1
  31. data/ext/msgpack/packer_class.c +130 -43
  32. data/ext/msgpack/packer_class.h +0 -2
  33. data/ext/msgpack/packer_ext_registry.c +2 -2
  34. data/ext/msgpack/packer_ext_registry.h +64 -25
  35. data/ext/msgpack/rbinit.c +0 -2
  36. data/ext/msgpack/unpacker.c +3 -3
  37. data/ext/msgpack/unpacker_class.c +25 -56
  38. data/ext/msgpack/unpacker_class.h +0 -2
  39. data/ext/msgpack/unpacker_ext_registry.c +2 -2
  40. data/ext/msgpack/unpacker_ext_registry.h +3 -3
  41. data/lib/msgpack.rb +36 -0
  42. data/lib/msgpack/core_ext.rb +139 -0
  43. data/lib/msgpack/factory.rb +21 -0
  44. data/lib/msgpack/symbol.rb +9 -0
  45. data/lib/msgpack/time.rb +29 -0
  46. data/lib/msgpack/timestamp.rb +76 -0
  47. data/lib/msgpack/version.rb +8 -1
  48. data/msgpack.gemspec +6 -7
  49. data/spec/cruby/buffer_spec.rb +6 -1
  50. data/spec/factory_spec.rb +134 -0
  51. data/spec/msgpack_spec.rb +52 -0
  52. data/spec/packer_spec.rb +200 -0
  53. data/spec/timestamp_spec.rb +121 -0
  54. data/spec/unpacker_spec.rb +29 -0
  55. metadata +29 -23
  56. data/ext/msgpack/core_ext.c +0 -144
  57. data/ext/msgpack/core_ext.h +0 -26
@@ -28,7 +28,5 @@ VALUE MessagePack_Packer_alloc(VALUE klass);
28
28
 
29
29
  VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self);
30
30
 
31
- VALUE MessagePack_pack(int argc, VALUE* argv);
32
-
33
31
  #endif
34
32
 
@@ -64,7 +64,7 @@ __rb_hash_clear_clear_i(key, value, dummy)
64
64
  #endif
65
65
 
66
66
  VALUE msgpack_packer_ext_registry_put(msgpack_packer_ext_registry_t* pkrg,
67
- VALUE ext_class, int ext_type, VALUE proc, VALUE arg)
67
+ VALUE ext_module, int ext_type, VALUE proc, VALUE arg)
68
68
  {
69
69
  VALUE e = rb_ary_new3(3, INT2FIX(ext_type), proc, arg);
70
70
  /* clear lookup cache not to miss added type */
@@ -75,5 +75,5 @@ VALUE msgpack_packer_ext_registry_put(msgpack_packer_ext_registry_t* pkrg,
75
75
  rb_hash_foreach(pkrg->cache, __rb_hash_clear_clear_i, 0);
76
76
  }
77
77
  #endif
78
- return rb_hash_aset(pkrg->hash, ext_class, e);
78
+ return rb_hash_aset(pkrg->hash, ext_module, e);
79
79
  }
@@ -15,8 +15,8 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- #ifndef MSGPACK_RUBY_UNPACKER_PACKER_EXT_REGISTRY_H__
19
- #define MSGPACK_RUBY_UNPACKER_PACKER_EXT_REGISTRY_H__
18
+ #ifndef MSGPACK_RUBY_PACKER_EXT_REGISTRY_H__
19
+ #define MSGPACK_RUBY_PACKER_EXT_REGISTRY_H__
20
20
 
21
21
  #include "compat.h"
22
22
  #include "ruby.h"
@@ -26,10 +26,7 @@ typedef struct msgpack_packer_ext_registry_t msgpack_packer_ext_registry_t;
26
26
 
27
27
  struct msgpack_packer_ext_registry_t {
28
28
  VALUE hash;
29
- /*
30
- * lookup cache for subclasses of registered classes
31
- */
32
- VALUE cache;
29
+ VALUE cache; // lookup cache for ext types inherited from a super class
33
30
  };
34
31
 
35
32
  void msgpack_packer_ext_registry_static_init();
@@ -47,9 +44,9 @@ void msgpack_packer_ext_registry_dup(msgpack_packer_ext_registry_t* src,
47
44
  msgpack_packer_ext_registry_t* dst);
48
45
 
49
46
  VALUE msgpack_packer_ext_registry_put(msgpack_packer_ext_registry_t* pkrg,
50
- VALUE ext_class, int ext_type, VALUE proc, VALUE arg);
47
+ VALUE ext_module, int ext_type, VALUE proc, VALUE arg);
51
48
 
52
- static int msgpack_packer_ext_find_inherited(VALUE key, VALUE value, VALUE arg)
49
+ static int msgpack_packer_ext_find_superclass(VALUE key, VALUE value, VALUE arg)
53
50
  {
54
51
  VALUE *args = (VALUE *) arg;
55
52
  if(key == Qundef) {
@@ -62,34 +59,76 @@ static int msgpack_packer_ext_find_inherited(VALUE key, VALUE value, VALUE arg)
62
59
  return ST_CONTINUE;
63
60
  }
64
61
 
62
+ static inline VALUE msgpack_packer_ext_registry_fetch(msgpack_packer_ext_registry_t* pkrg,
63
+ VALUE lookup_class, int* ext_type_result)
64
+ {
65
+ // fetch lookup_class from hash, which is a hash to register classes
66
+ VALUE type = rb_hash_lookup(pkrg->hash, lookup_class);
67
+ if(type != Qnil) {
68
+ *ext_type_result = FIX2INT(rb_ary_entry(type, 0));
69
+ return rb_ary_entry(type, 1);
70
+ }
71
+
72
+ // fetch lookup_class from cache, which stores results of searching ancestors from pkrg->hash
73
+ VALUE type_inht = rb_hash_lookup(pkrg->cache, lookup_class);
74
+ if(type_inht != Qnil) {
75
+ *ext_type_result = FIX2INT(rb_ary_entry(type_inht, 0));
76
+ return rb_ary_entry(type_inht, 1);
77
+ }
78
+
79
+ return Qnil;
80
+ }
65
81
 
66
82
  static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_registry_t* pkrg,
67
- VALUE ext_class, int* ext_type_result)
83
+ VALUE instance, int* ext_type_result)
68
84
  {
69
- VALUE e = rb_hash_lookup(pkrg->hash, ext_class);
70
- if(e != Qnil) {
71
- *ext_type_result = FIX2INT(rb_ary_entry(e, 0));
72
- return rb_ary_entry(e, 1);
85
+ VALUE lookup_class;
86
+ VALUE type;
87
+
88
+ /*
89
+ * 1. check whether singleton_class of this instance is registered (or resolved in past) or not.
90
+ *
91
+ * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen
92
+ * String have no singleton class and raise a TypeError when trying to get
93
+ * it. See implementation of #singleton_class in ruby's source code:
94
+ * VALUE rb_singleton_class(VALUE obj);
95
+ *
96
+ * Since all but symbols are already filtered out when reaching this code
97
+ * only symbols are checked here.
98
+ */
99
+ if (!SYMBOL_P(instance)) {
100
+ lookup_class = rb_singleton_class(instance);
101
+
102
+ type = msgpack_packer_ext_registry_fetch(pkrg, lookup_class, ext_type_result);
103
+
104
+ if(type != Qnil) {
105
+ return type;
106
+ }
73
107
  }
74
108
 
75
- VALUE c = rb_hash_lookup(pkrg->cache, ext_class);
76
- if(c != Qnil) {
77
- *ext_type_result = FIX2INT(rb_ary_entry(c, 0));
78
- return rb_ary_entry(c, 1);
109
+ /*
110
+ * 2. check the class of instance is registered (or resolved in past) or not.
111
+ */
112
+ type = msgpack_packer_ext_registry_fetch(pkrg, rb_obj_class(instance), ext_type_result);
113
+
114
+ if(type != Qnil) {
115
+ return type;
79
116
  }
80
117
 
81
118
  /*
82
- * check all keys whether it is super class of ext_class, or not
119
+ * 3. check all keys whether it is an ancestor of lookup_class, or not
83
120
  */
84
121
  VALUE args[2];
85
- args[0] = ext_class;
122
+ args[0] = lookup_class;
86
123
  args[1] = Qnil;
87
- rb_hash_foreach(pkrg->hash, msgpack_packer_ext_find_inherited, (VALUE) args);
88
-
89
- VALUE hit = args[1];
90
- if(hit != Qnil) {
91
- rb_hash_aset(pkrg->cache, ext_class, hit);
92
- return hit;
124
+ rb_hash_foreach(pkrg->hash, msgpack_packer_ext_find_superclass, (VALUE) args);
125
+
126
+ VALUE superclass = args[1];
127
+ if(superclass != Qnil) {
128
+ VALUE superclass_type = rb_hash_lookup(pkrg->hash, superclass);
129
+ rb_hash_aset(pkrg->cache, lookup_class, superclass_type);
130
+ *ext_type_result = FIX2INT(rb_ary_entry(superclass_type, 0));
131
+ return rb_ary_entry(superclass_type, 1);
93
132
  }
94
133
 
95
134
  return Qnil;
data/ext/msgpack/rbinit.c CHANGED
@@ -21,7 +21,6 @@
21
21
  #include "unpacker_class.h"
22
22
  #include "factory_class.h"
23
23
  #include "extension_value_class.h"
24
- #include "core_ext.h"
25
24
 
26
25
  void Init_msgpack(void)
27
26
  {
@@ -32,6 +31,5 @@ void Init_msgpack(void)
32
31
  MessagePack_Unpacker_module_init(mMessagePack);
33
32
  MessagePack_Factory_module_init(mMessagePack);
34
33
  MessagePack_ExtensionValue_module_init(mMessagePack);
35
- MessagePack_core_ext_module_init();
36
34
  }
37
35
 
@@ -369,7 +369,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
369
369
  {
370
370
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
371
371
  uint8_t length = cb->u8;
372
- int ext_type = cb->buffer[1];
372
+ int ext_type = (signed char) cb->buffer[1];
373
373
  if(length == 0) {
374
374
  return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
375
375
  }
@@ -381,7 +381,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
381
381
  {
382
382
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 3);
383
383
  uint16_t length = _msgpack_be16(cb->u16);
384
- int ext_type = cb->buffer[2];
384
+ int ext_type = (signed char) cb->buffer[2];
385
385
  if(length == 0) {
386
386
  return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
387
387
  }
@@ -393,7 +393,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
393
393
  {
394
394
  READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 5);
395
395
  uint32_t length = _msgpack_be32(cb->u32);
396
- int ext_type = cb->buffer[4];
396
+ int ext_type = (signed char) cb->buffer[4];
397
397
  if(length == 0) {
398
398
  return object_complete_ext(uk, ext_type, rb_str_buf_new(0));
399
399
  }
@@ -58,14 +58,10 @@ static void Unpacker_mark(msgpack_unpacker_t* uk)
58
58
 
59
59
  VALUE MessagePack_Unpacker_alloc(VALUE klass)
60
60
  {
61
- msgpack_unpacker_t* uk = ALLOC_N(msgpack_unpacker_t, 1);
61
+ msgpack_unpacker_t* uk = ZALLOC_N(msgpack_unpacker_t, 1);
62
62
  _msgpack_unpacker_init(uk);
63
63
 
64
64
  VALUE self = Data_Wrap_Struct(klass, Unpacker_mark, Unpacker_free, uk);
65
-
66
- msgpack_unpacker_ext_registry_init(&uk->ext_registry);
67
- uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
68
-
69
65
  return self;
70
66
  }
71
67
 
@@ -81,9 +77,6 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
81
77
  VALUE v = argv[0];
82
78
  if(rb_type(v) == T_HASH) {
83
79
  options = v;
84
- if(rb_type(options) != T_HASH) {
85
- rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
86
- }
87
80
  } else {
88
81
  io = v;
89
82
  }
@@ -101,6 +94,9 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
101
94
 
102
95
  UNPACKER(self, uk);
103
96
 
97
+ msgpack_unpacker_ext_registry_init(&uk->ext_registry);
98
+ uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
99
+
104
100
  MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options);
105
101
 
106
102
  if(options != Qnil) {
@@ -257,6 +253,17 @@ static VALUE Unpacker_feed(VALUE self, VALUE data)
257
253
  return self;
258
254
  }
259
255
 
256
+ static VALUE Unpacker_feed_reference(VALUE self, VALUE data)
257
+ {
258
+ UNPACKER(self, uk);
259
+
260
+ StringValue(data);
261
+
262
+ msgpack_buffer_append_string_reference(UNPACKER_BUFFER_(uk), data);
263
+
264
+ return self;
265
+ }
266
+
260
267
  static VALUE Unpacker_each_impl(VALUE self)
261
268
  {
262
269
  UNPACKER(self, uk);
@@ -313,8 +320,7 @@ static VALUE Unpacker_feed_each(VALUE self, VALUE data)
313
320
  }
314
321
  #endif
315
322
 
316
- // TODO optimize
317
- Unpacker_feed(self, data);
323
+ Unpacker_feed_reference(self, data);
318
324
  return Unpacker_each(self);
319
325
  }
320
326
 
@@ -348,7 +354,7 @@ static VALUE Unpacker_register_type(int argc, VALUE* argv, VALUE self)
348
354
  int ext_type;
349
355
  VALUE proc;
350
356
  VALUE arg;
351
- VALUE ext_class;
357
+ VALUE ext_module;
352
358
 
353
359
  switch (argc) {
354
360
  case 1:
@@ -361,50 +367,32 @@ static VALUE Unpacker_register_type(int argc, VALUE* argv, VALUE self)
361
367
  proc = rb_block_proc();
362
368
  #endif
363
369
  arg = proc;
364
- ext_class = Qnil;
370
+ ext_module = Qnil;
365
371
  break;
366
372
  case 3:
367
373
  /* register_type(0x7f, Time, :from_msgpack_ext) */
368
- ext_class = argv[1];
374
+ ext_module = argv[1];
369
375
  arg = argv[2];
370
- proc = rb_obj_method(ext_class, arg);
376
+ proc = rb_obj_method(ext_module, arg);
371
377
  break;
372
378
  default:
373
379
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
374
380
  }
375
381
 
376
- ext_type = rb_num2int(argv[0]);
382
+ ext_type = NUM2INT(argv[0]);
377
383
  if(ext_type < -128 || ext_type > 127) {
378
384
  rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
379
385
  }
380
386
 
381
- msgpack_unpacker_ext_registry_put(&uk->ext_registry, ext_class, ext_type, proc, arg);
387
+ msgpack_unpacker_ext_registry_put(&uk->ext_registry, ext_module, ext_type, proc, arg);
382
388
 
383
389
  return Qnil;
384
390
  }
385
391
 
386
- VALUE MessagePack_unpack(int argc, VALUE* argv)
392
+ static VALUE Unpacker_full_unpack(VALUE self)
387
393
  {
388
- VALUE src;
389
- VALUE self;
390
-
391
- if (argc < 0 || argc > 2) {
392
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
393
- }
394
- src = argv[0];
395
-
396
- if(rb_type(src) == T_STRING) {
397
- self = MessagePack_Factory_unpacker(argc - 1, argv + 1, cMessagePack_DefaultFactory);
398
- UNPACKER(self, uk);
399
- msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), src);
400
- } else {
401
- self = MessagePack_Factory_unpacker(argc, argv, cMessagePack_DefaultFactory);
402
- }
403
394
  UNPACKER(self, uk);
404
395
 
405
- /* prefer reference than copying; see MessagePack_Unpacker_module_init */
406
- msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(uk), 0);
407
-
408
396
  int r = msgpack_unpacker_read(uk, 0);
409
397
  if(r < 0) {
410
398
  raise_unpacker_error(r);
@@ -416,27 +404,9 @@ VALUE MessagePack_unpack(int argc, VALUE* argv)
416
404
  rb_raise(eMalformedFormatError, "%zd extra bytes after the deserialized object", extra);
417
405
  }
418
406
 
419
- #ifdef RB_GC_GUARD
420
- /* This prevents compilers from optimizing out the `self` variable
421
- * from stack. Otherwise GC free()s it. */
422
- RB_GC_GUARD(self);
423
- #endif
424
-
425
407
  return msgpack_unpacker_get_last_object(uk);
426
408
  }
427
409
 
428
- static VALUE MessagePack_load_module_method(int argc, VALUE* argv, VALUE mod)
429
- {
430
- UNUSED(mod);
431
- return MessagePack_unpack(argc, argv);
432
- }
433
-
434
- static VALUE MessagePack_unpack_module_method(int argc, VALUE* argv, VALUE mod)
435
- {
436
- UNUSED(mod);
437
- return MessagePack_unpack(argc, argv);
438
- }
439
-
440
410
  VALUE MessagePack_Unpacker_new(int argc, VALUE* argv)
441
411
  {
442
412
  VALUE self = MessagePack_Unpacker_alloc(cMessagePack_Unpacker);
@@ -478,6 +448,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
478
448
  rb_define_method(cMessagePack_Unpacker, "read_map_header", Unpacker_read_map_header, 0);
479
449
  //rb_define_method(cMessagePack_Unpacker, "peek_next_type", Unpacker_peek_next_type, 0); // TODO
480
450
  rb_define_method(cMessagePack_Unpacker, "feed", Unpacker_feed, 1);
451
+ rb_define_method(cMessagePack_Unpacker, "feed_reference", Unpacker_feed_reference, 1);
481
452
  rb_define_method(cMessagePack_Unpacker, "each", Unpacker_each, 0);
482
453
  rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1);
483
454
  rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
@@ -491,8 +462,6 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
491
462
  /* prefer reference than copying */
492
463
  //msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
493
464
 
494
- /* MessagePack.unpack(x) */
495
- rb_define_module_function(mMessagePack, "load", MessagePack_load_module_method, -1);
496
- rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack_module_method, -1);
465
+ rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0);
497
466
  }
498
467
 
@@ -28,7 +28,5 @@ VALUE MessagePack_Unpacker_alloc(VALUE klass);
28
28
 
29
29
  VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self);
30
30
 
31
- VALUE MessagePack_unpack(int argc, VALUE* argv);
32
-
33
31
  #endif
34
32
 
@@ -53,9 +53,9 @@ void msgpack_unpacker_ext_registry_dup(msgpack_unpacker_ext_registry_t* src,
53
53
  }
54
54
 
55
55
  VALUE msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t* ukrg,
56
- VALUE ext_class, int ext_type, VALUE proc, VALUE arg)
56
+ VALUE ext_module, int ext_type, VALUE proc, VALUE arg)
57
57
  {
58
- VALUE e = rb_ary_new3(3, ext_class, proc, arg);
58
+ VALUE e = rb_ary_new3(3, ext_module, proc, arg);
59
59
  VALUE before = ukrg->array[ext_type + 128];
60
60
  ukrg->array[ext_type + 128] = e;
61
61
  return before;
@@ -15,8 +15,8 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- #ifndef MSGPACK_RUBY_PACKER_PACKER_EXT_REGISTRY_H__
19
- #define MSGPACK_RUBY_PACKER_PACKER_EXT_REGISTRY_H__
18
+ #ifndef MSGPACK_RUBY_UNPACKER_EXT_REGISTRY_H__
19
+ #define MSGPACK_RUBY_UNPACKER_EXT_REGISTRY_H__
20
20
 
21
21
  #include "compat.h"
22
22
  #include "ruby.h"
@@ -44,7 +44,7 @@ void msgpack_unpacker_ext_registry_dup(msgpack_unpacker_ext_registry_t* src,
44
44
  msgpack_unpacker_ext_registry_t* dst);
45
45
 
46
46
  VALUE msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t* ukrg,
47
- VALUE ext_class, int ext_type, VALUE proc, VALUE arg);
47
+ VALUE ext_module, int ext_type, VALUE proc, VALUE arg);
48
48
 
49
49
  static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_registry_t* ukrg,
50
50
  int ext_type)
data/lib/msgpack.rb CHANGED
@@ -15,3 +15,39 @@ end
15
15
  require "msgpack/packer"
16
16
  require "msgpack/unpacker"
17
17
  require "msgpack/factory"
18
+ require "msgpack/symbol"
19
+ require "msgpack/core_ext"
20
+ require "msgpack/timestamp"
21
+ require "msgpack/time"
22
+
23
+ module MessagePack
24
+ DefaultFactory = MessagePack::Factory.new
25
+ DEFAULT_EMPTY_PARAMS = {}.freeze
26
+
27
+ def load(src, param = nil)
28
+ unpacker = nil
29
+
30
+ if src.is_a? String
31
+ unpacker = DefaultFactory.unpacker param || DEFAULT_EMPTY_PARAMS
32
+ unpacker.feed_reference src
33
+ else
34
+ unpacker = DefaultFactory.unpacker src, param || DEFAULT_EMPTY_PARAMS
35
+ end
36
+
37
+ unpacker.full_unpack
38
+ end
39
+ alias :unpack :load
40
+
41
+ module_function :load
42
+ module_function :unpack
43
+
44
+ def pack(v, *rest)
45
+ packer = DefaultFactory.packer(*rest)
46
+ packer.write v
47
+ packer.full_pack
48
+ end
49
+ alias :dump :pack
50
+
51
+ module_function :pack
52
+ module_function :dump
53
+ end