msgpack 0.7.0dev1-x64-mingw32 → 0.7.0-x64-mingw32
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/.gitignore +1 -0
 - data/.travis.yml +2 -0
 - data/ChangeLog +8 -0
 - data/README.rdoc +36 -2
 - data/ext/java/org/msgpack/jruby/Decoder.java +55 -16
 - data/ext/java/org/msgpack/jruby/Encoder.java +31 -8
 - data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +159 -0
 - data/ext/java/org/msgpack/jruby/Factory.java +117 -0
 - data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +23 -6
 - data/ext/java/org/msgpack/jruby/Packer.java +65 -6
 - data/ext/java/org/msgpack/jruby/Unpacker.java +104 -22
 - data/ext/msgpack/packer_class.c +7 -0
 - data/ext/msgpack/packer_ext_registry.c +0 -8
 - data/ext/msgpack/packer_ext_registry.h +0 -3
 - data/ext/msgpack/unpacker_class.c +14 -0
 - data/ext/msgpack/unpacker_ext_registry.c +0 -6
 - data/ext/msgpack/unpacker_ext_registry.h +0 -3
 - data/lib/msgpack/version.rb +1 -1
 - data/msgpack.gemspec +5 -3
 - data/spec/cruby/unpacker_spec.rb +0 -247
 - data/spec/factory_spec.rb +0 -3
 - data/spec/jruby/{msgpack/unpacker_spec.rb → unpacker_spec.rb} +30 -159
 - data/spec/msgpack_spec.rb +1 -1
 - data/spec/packer_spec.rb +135 -4
 - data/spec/unpacker_spec.rb +465 -6
 - metadata +9 -6
 - data/spec/cruby/packer_spec.rb +0 -138
 
    
        data/ext/msgpack/packer_class.c
    CHANGED
    
    | 
         @@ -109,6 +109,12 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self) 
     | 
|
| 
       109 
109 
     | 
    
         
             
                return self;
         
     | 
| 
       110 
110 
     | 
    
         
             
            }
         
     | 
| 
       111 
111 
     | 
    
         | 
| 
      
 112 
     | 
    
         
            +
            static VALUE Packer_compatibility_mode_p(VALUE self)
         
     | 
| 
      
 113 
     | 
    
         
            +
            {
         
     | 
| 
      
 114 
     | 
    
         
            +
                PACKER(self, pk);
         
     | 
| 
      
 115 
     | 
    
         
            +
                return pk->compatibility_mode ? Qtrue : Qfalse;
         
     | 
| 
      
 116 
     | 
    
         
            +
            }
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
       112 
118 
     | 
    
         
             
            static VALUE Packer_buffer(VALUE self)
         
     | 
| 
       113 
119 
     | 
    
         
             
            {
         
     | 
| 
       114 
120 
     | 
    
         
             
                PACKER(self, pk);
         
     | 
| 
         @@ -330,6 +336,7 @@ void MessagePack_Packer_module_init(VALUE mMessagePack) 
     | 
|
| 
       330 
336 
     | 
    
         
             
                rb_define_alloc_func(cMessagePack_Packer, MessagePack_Packer_alloc);
         
     | 
| 
       331 
337 
     | 
    
         | 
| 
       332 
338 
     | 
    
         
             
                rb_define_method(cMessagePack_Packer, "initialize", MessagePack_Packer_initialize, -1);
         
     | 
| 
      
 339 
     | 
    
         
            +
                rb_define_method(cMessagePack_Packer, "compatibility_mode?", Packer_compatibility_mode_p, 0);
         
     | 
| 
       333 
340 
     | 
    
         
             
                rb_define_method(cMessagePack_Packer, "buffer", Packer_buffer, 0);
         
     | 
| 
       334 
341 
     | 
    
         
             
                rb_define_method(cMessagePack_Packer, "write", Packer_write, 1);
         
     | 
| 
       335 
342 
     | 
    
         
             
                rb_define_alias(cMessagePack_Packer, "pack", "write");
         
     | 
| 
         @@ -77,11 +77,3 @@ VALUE msgpack_packer_ext_registry_put(msgpack_packer_ext_registry_t* pkrg, 
     | 
|
| 
       77 
77 
     | 
    
         
             
            #endif
         
     | 
| 
       78 
78 
     | 
    
         
             
                return rb_hash_aset(pkrg->hash, ext_class, e);
         
     | 
| 
       79 
79 
     | 
    
         
             
            }
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
            VALUE msgpack_packer_ext_registry_call(msgpack_packer_ext_registry_t* pkrg,
         
     | 
| 
       82 
     | 
    
         
            -
                    VALUE proc, VALUE ext_value)
         
     | 
| 
       83 
     | 
    
         
            -
            {
         
     | 
| 
       84 
     | 
    
         
            -
                VALUE string = rb_funcall(proc, s_call, 1, ext_value);
         
     | 
| 
       85 
     | 
    
         
            -
                StringValue(string);
         
     | 
| 
       86 
     | 
    
         
            -
                return string;
         
     | 
| 
       87 
     | 
    
         
            -
            }
         
     | 
| 
         @@ -116,6 +116,18 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self) 
     | 
|
| 
       116 
116 
     | 
    
         
             
                return self;
         
     | 
| 
       117 
117 
     | 
    
         
             
            }
         
     | 
| 
       118 
118 
     | 
    
         | 
| 
      
 119 
     | 
    
         
            +
            static VALUE Unpacker_symbolized_keys_p(VALUE self)
         
     | 
| 
      
 120 
     | 
    
         
            +
            {
         
     | 
| 
      
 121 
     | 
    
         
            +
                UNPACKER(self, uk);
         
     | 
| 
      
 122 
     | 
    
         
            +
                return uk->symbolize_keys ? Qtrue : Qfalse;
         
     | 
| 
      
 123 
     | 
    
         
            +
            }
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
            static VALUE Unpacker_allow_unknown_ext_p(VALUE self)
         
     | 
| 
      
 126 
     | 
    
         
            +
            {
         
     | 
| 
      
 127 
     | 
    
         
            +
                UNPACKER(self, uk);
         
     | 
| 
      
 128 
     | 
    
         
            +
                return uk->allow_unknown_ext ? Qtrue : Qfalse;
         
     | 
| 
      
 129 
     | 
    
         
            +
            }
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
       119 
131 
     | 
    
         
             
            static void raise_unpacker_error(int r)
         
     | 
| 
       120 
132 
     | 
    
         
             
            {
         
     | 
| 
       121 
133 
     | 
    
         
             
                switch(r) {
         
     | 
| 
         @@ -455,6 +467,8 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack) 
     | 
|
| 
       455 
467 
     | 
    
         
             
                rb_define_alloc_func(cMessagePack_Unpacker, MessagePack_Unpacker_alloc);
         
     | 
| 
       456 
468 
     | 
    
         | 
| 
       457 
469 
     | 
    
         
             
                rb_define_method(cMessagePack_Unpacker, "initialize", MessagePack_Unpacker_initialize, -1);
         
     | 
| 
      
 470 
     | 
    
         
            +
                rb_define_method(cMessagePack_Unpacker, "symbolize_keys?", Unpacker_symbolized_keys_p, 0);
         
     | 
| 
      
 471 
     | 
    
         
            +
                rb_define_method(cMessagePack_Unpacker, "allow_unknown_ext?", Unpacker_allow_unknown_ext_p, 0);
         
     | 
| 
       458 
472 
     | 
    
         
             
                rb_define_method(cMessagePack_Unpacker, "buffer", Unpacker_buffer, 0);
         
     | 
| 
       459 
473 
     | 
    
         
             
                rb_define_method(cMessagePack_Unpacker, "read", Unpacker_read, 0);
         
     | 
| 
       460 
474 
     | 
    
         
             
                rb_define_alias(cMessagePack_Unpacker, "unpack", "read");
         
     | 
| 
         @@ -60,9 +60,3 @@ VALUE msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t* ukrg, 
     | 
|
| 
       60 
60 
     | 
    
         
             
                ukrg->array[ext_type + 128] = e;
         
     | 
| 
       61 
61 
     | 
    
         
             
                return before;
         
     | 
| 
       62 
62 
     | 
    
         
             
            }
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
            VALUE msgpack_unpacker_ext_registry_call(msgpack_unpacker_ext_registry_t* ukrg,
         
     | 
| 
       65 
     | 
    
         
            -
                    VALUE proc, VALUE ext_data)
         
     | 
| 
       66 
     | 
    
         
            -
            {
         
     | 
| 
       67 
     | 
    
         
            -
                return rb_funcall(proc, s_call, 1, ext_data);
         
     | 
| 
       68 
     | 
    
         
            -
            }
         
     | 
    
        data/lib/msgpack/version.rb
    CHANGED
    
    
    
        data/msgpack.gemspec
    CHANGED
    
    | 
         @@ -6,8 +6,8 @@ Gem::Specification.new do |s| 
     | 
|
| 
       6 
6 
     | 
    
         
             
              s.version = MessagePack::VERSION
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.summary = "MessagePack, a binary-based efficient data interchange format."
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.description = %q{MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.}
         
     | 
| 
       9 
     | 
    
         
            -
              s.authors = ["Sadayuki Furuhashi", "Theo Hultberg"]
         
     | 
| 
       10 
     | 
    
         
            -
              s.email = ["frsyuki@gmail.com", "theo@iconara.net"]
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.authors = ["Sadayuki Furuhashi", "Theo Hultberg", "Satoshi Tagomori"]
         
     | 
| 
      
 10 
     | 
    
         
            +
              s.email = ["frsyuki@gmail.com", "theo@iconara.net", "tagomoris@gmail.com"]
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.license = "Apache 2.0"
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.homepage = "http://msgpack.org/"
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.rubyforge_project = "msgpack"
         
     | 
| 
         @@ -25,7 +25,9 @@ Gem::Specification.new do |s| 
     | 
|
| 
       25 
25 
     | 
    
         
             
              s.add_development_dependency 'bundler', ['~> 1.0']
         
     | 
| 
       26 
26 
     | 
    
         
             
              s.add_development_dependency 'rake', ['~> 0.9.2']
         
     | 
| 
       27 
27 
     | 
    
         
             
              s.add_development_dependency 'rake-compiler', ['~> 0.9.4']
         
     | 
| 
       28 
     | 
    
         
            -
               
     | 
| 
      
 28 
     | 
    
         
            +
              if /java/ !~ RUBY_PLATFORM
         
     | 
| 
      
 29 
     | 
    
         
            +
                s.add_development_dependency 'rake-compiler-dock', ['~> 0.4.3']
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
       29 
31 
     | 
    
         
             
              s.add_development_dependency 'rspec', ['~> 3.3']
         
     | 
| 
       30 
32 
     | 
    
         
             
              s.add_development_dependency 'yard', ['~> 0.8.2']
         
     | 
| 
       31 
33 
     | 
    
         
             
              s.add_development_dependency 'json'
         
     | 
    
        data/spec/cruby/unpacker_spec.rb
    CHANGED
    
    | 
         @@ -10,60 +10,6 @@ describe Unpacker do 
     | 
|
| 
       10 
10 
     | 
    
         
             
                Packer.new
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              # TODO initialize
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              it 'read_array_header succeeds' do
         
     | 
| 
       16 
     | 
    
         
            -
                unpacker.feed("\x91")
         
     | 
| 
       17 
     | 
    
         
            -
                unpacker.read_array_header.should == 1
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              it 'read_array_header fails' do
         
     | 
| 
       21 
     | 
    
         
            -
                unpacker.feed("\x81")
         
     | 
| 
       22 
     | 
    
         
            -
                lambda {
         
     | 
| 
       23 
     | 
    
         
            -
                  unpacker.read_array_header
         
     | 
| 
       24 
     | 
    
         
            -
                }.should raise_error(MessagePack::TypeError)  # TypeError is included in UnexpectedTypeError
         
     | 
| 
       25 
     | 
    
         
            -
                lambda {
         
     | 
| 
       26 
     | 
    
         
            -
                  unpacker.read_array_header
         
     | 
| 
       27 
     | 
    
         
            -
                }.should raise_error(MessagePack::UnexpectedTypeError)
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
              it 'read_map_header converts an map to key-value sequence' do
         
     | 
| 
       31 
     | 
    
         
            -
                packer.write_array_header(2)
         
     | 
| 
       32 
     | 
    
         
            -
                packer.write("e")
         
     | 
| 
       33 
     | 
    
         
            -
                packer.write(1)
         
     | 
| 
       34 
     | 
    
         
            -
                unpacker = Unpacker.new
         
     | 
| 
       35 
     | 
    
         
            -
                unpacker.feed(packer.to_s)
         
     | 
| 
       36 
     | 
    
         
            -
                unpacker.read_array_header.should == 2
         
     | 
| 
       37 
     | 
    
         
            -
                unpacker.read.should == "e"
         
     | 
| 
       38 
     | 
    
         
            -
                unpacker.read.should == 1
         
     | 
| 
       39 
     | 
    
         
            -
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
              it 'read_map_header succeeds' do
         
     | 
| 
       42 
     | 
    
         
            -
                unpacker.feed("\x81")
         
     | 
| 
       43 
     | 
    
         
            -
                unpacker.read_map_header.should == 1
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              it 'read_map_header converts an map to key-value sequence' do
         
     | 
| 
       47 
     | 
    
         
            -
                packer.write_map_header(1)
         
     | 
| 
       48 
     | 
    
         
            -
                packer.write("k")
         
     | 
| 
       49 
     | 
    
         
            -
                packer.write("v")
         
     | 
| 
       50 
     | 
    
         
            -
                unpacker = Unpacker.new
         
     | 
| 
       51 
     | 
    
         
            -
                unpacker.feed(packer.to_s)
         
     | 
| 
       52 
     | 
    
         
            -
                unpacker.read_map_header.should == 1
         
     | 
| 
       53 
     | 
    
         
            -
                unpacker.read.should == "k"
         
     | 
| 
       54 
     | 
    
         
            -
                unpacker.read.should == "v"
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              it 'read_map_header fails' do
         
     | 
| 
       58 
     | 
    
         
            -
                unpacker.feed("\x91")
         
     | 
| 
       59 
     | 
    
         
            -
                lambda {
         
     | 
| 
       60 
     | 
    
         
            -
                  unpacker.read_map_header
         
     | 
| 
       61 
     | 
    
         
            -
                }.should raise_error(MessagePack::TypeError)  # TypeError is included in UnexpectedTypeError
         
     | 
| 
       62 
     | 
    
         
            -
                lambda {
         
     | 
| 
       63 
     | 
    
         
            -
                  unpacker.read_map_header
         
     | 
| 
       64 
     | 
    
         
            -
                }.should raise_error(MessagePack::UnexpectedTypeError)
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
13 
     | 
    
         
             
              it 'skip_nil succeeds' do
         
     | 
| 
       68 
14 
     | 
    
         
             
                unpacker.feed("\xc0")
         
     | 
| 
       69 
15 
     | 
    
         
             
                unpacker.skip_nil.should == true
         
     | 
| 
         @@ -91,12 +37,6 @@ describe Unpacker do 
     | 
|
| 
       91 
37 
     | 
    
         
             
                unpacker.read.should == 5
         
     | 
| 
       92 
38 
     | 
    
         
             
              end
         
     | 
| 
       93 
39 
     | 
    
         | 
| 
       94 
     | 
    
         
            -
              it 'read raises EOFError' do
         
     | 
| 
       95 
     | 
    
         
            -
                lambda {
         
     | 
| 
       96 
     | 
    
         
            -
                  unpacker.read
         
     | 
| 
       97 
     | 
    
         
            -
                }.should raise_error(EOFError)
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
40 
     | 
    
         
             
              it 'skip raises EOFError' do
         
     | 
| 
       101 
41 
     | 
    
         
             
                lambda {
         
     | 
| 
       102 
42 
     | 
    
         
             
                  unpacker.skip
         
     | 
| 
         @@ -109,88 +49,6 @@ describe Unpacker do 
     | 
|
| 
       109 
49 
     | 
    
         
             
                }.should raise_error(EOFError)
         
     | 
| 
       110 
50 
     | 
    
         
             
              end
         
     | 
| 
       111 
51 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
              let :sample_object do
         
     | 
| 
       113 
     | 
    
         
            -
                [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5]
         
     | 
| 
       114 
     | 
    
         
            -
              end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
              it 'feed and each continue internal state' do
         
     | 
| 
       117 
     | 
    
         
            -
                raw = sample_object.to_msgpack.to_s * 4
         
     | 
| 
       118 
     | 
    
         
            -
                objects = []
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                raw.split(//).each do |b|
         
     | 
| 
       121 
     | 
    
         
            -
                  unpacker.feed(b)
         
     | 
| 
       122 
     | 
    
         
            -
                  unpacker.each {|c|
         
     | 
| 
       123 
     | 
    
         
            -
                    objects << c
         
     | 
| 
       124 
     | 
    
         
            -
                  }
         
     | 
| 
       125 
     | 
    
         
            -
                end
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                objects.should == [sample_object] * 4
         
     | 
| 
       128 
     | 
    
         
            -
              end
         
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
              it 'feed_each continues internal state' do
         
     | 
| 
       131 
     | 
    
         
            -
                raw = sample_object.to_msgpack.to_s * 4
         
     | 
| 
       132 
     | 
    
         
            -
                objects = []
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                raw.split(//).each do |b|
         
     | 
| 
       135 
     | 
    
         
            -
                  unpacker.feed_each(b) {|c|
         
     | 
| 
       136 
     | 
    
         
            -
                    objects << c
         
     | 
| 
       137 
     | 
    
         
            -
                  }
         
     | 
| 
       138 
     | 
    
         
            -
                end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
                objects.should == [sample_object] * 4
         
     | 
| 
       141 
     | 
    
         
            -
              end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
              it 'feed_each enumerator' do
         
     | 
| 
       144 
     | 
    
         
            -
                raw = sample_object.to_msgpack.to_s * 4
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
                unpacker.feed_each(raw).to_a.should == [sample_object] * 4
         
     | 
| 
       147 
     | 
    
         
            -
              end
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
              it 'reset clears internal buffer' do
         
     | 
| 
       150 
     | 
    
         
            -
                # 1-element array
         
     | 
| 
       151 
     | 
    
         
            -
                unpacker.feed("\x91")
         
     | 
| 
       152 
     | 
    
         
            -
                unpacker.reset
         
     | 
| 
       153 
     | 
    
         
            -
                unpacker.feed("\x01")
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                unpacker.each.map {|x| x }.should == [1]
         
     | 
| 
       156 
     | 
    
         
            -
              end
         
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
              it 'reset clears internal state' do
         
     | 
| 
       159 
     | 
    
         
            -
                # 1-element array
         
     | 
| 
       160 
     | 
    
         
            -
                unpacker.feed("\x91")
         
     | 
| 
       161 
     | 
    
         
            -
                unpacker.each.map {|x| x }.should == []
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
                unpacker.reset
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
                unpacker.feed("\x01")
         
     | 
| 
       166 
     | 
    
         
            -
                unpacker.each.map {|x| x }.should == [1]
         
     | 
| 
       167 
     | 
    
         
            -
              end
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
              it 'frozen short strings' do
         
     | 
| 
       170 
     | 
    
         
            -
                raw = sample_object.to_msgpack.to_s.force_encoding('UTF-8')
         
     | 
| 
       171 
     | 
    
         
            -
                lambda {
         
     | 
| 
       172 
     | 
    
         
            -
                  unpacker.feed_each(raw.freeze) { }
         
     | 
| 
       173 
     | 
    
         
            -
                }.should_not raise_error
         
     | 
| 
       174 
     | 
    
         
            -
              end
         
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
              it 'frozen long strings' do
         
     | 
| 
       177 
     | 
    
         
            -
                raw = (sample_object.to_msgpack.to_s * 10240).force_encoding('UTF-8')
         
     | 
| 
       178 
     | 
    
         
            -
                lambda {
         
     | 
| 
       179 
     | 
    
         
            -
                  unpacker.feed_each(raw.freeze) { }
         
     | 
| 
       180 
     | 
    
         
            -
                }.should_not raise_error
         
     | 
| 
       181 
     | 
    
         
            -
              end
         
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
              it 'read raises level stack too deep error' do
         
     | 
| 
       184 
     | 
    
         
            -
                512.times { packer.write_array_header(1) }
         
     | 
| 
       185 
     | 
    
         
            -
                packer.write(nil)
         
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
                unpacker = Unpacker.new
         
     | 
| 
       188 
     | 
    
         
            -
                unpacker.feed(packer.to_s)
         
     | 
| 
       189 
     | 
    
         
            -
                lambda {
         
     | 
| 
       190 
     | 
    
         
            -
                  unpacker.read
         
     | 
| 
       191 
     | 
    
         
            -
                }.should raise_error(MessagePack::StackError)
         
     | 
| 
       192 
     | 
    
         
            -
              end
         
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
52 
     | 
    
         
             
              it 'skip raises level stack too deep error' do
         
     | 
| 
       195 
53 
     | 
    
         
             
                512.times { packer.write_array_header(1) }
         
     | 
| 
       196 
54 
     | 
    
         
             
                packer.write(nil)
         
     | 
| 
         @@ -202,116 +60,11 @@ describe Unpacker do 
     | 
|
| 
       202 
60 
     | 
    
         
             
                }.should raise_error(MessagePack::StackError)
         
     | 
| 
       203 
61 
     | 
    
         
             
              end
         
     | 
| 
       204 
62 
     | 
    
         | 
| 
       205 
     | 
    
         
            -
              it 'read raises invalid byte error' do
         
     | 
| 
       206 
     | 
    
         
            -
                unpacker.feed("\xc1")
         
     | 
| 
       207 
     | 
    
         
            -
                lambda {
         
     | 
| 
       208 
     | 
    
         
            -
                  unpacker.read
         
     | 
| 
       209 
     | 
    
         
            -
                }.should raise_error(MessagePack::MalformedFormatError)
         
     | 
| 
       210 
     | 
    
         
            -
              end
         
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
63 
     | 
    
         
             
              it 'skip raises invalid byte error' do
         
     | 
| 
       213 
64 
     | 
    
         
             
                unpacker.feed("\xc1")
         
     | 
| 
       214 
65 
     | 
    
         
             
                lambda {
         
     | 
| 
       215 
66 
     | 
    
         
             
                  unpacker.skip
         
     | 
| 
       216 
67 
     | 
    
         
             
                }.should raise_error(MessagePack::MalformedFormatError)
         
     | 
| 
       217 
68 
     | 
    
         
             
              end
         
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
              it "gc mark" do
         
     | 
| 
       220 
     | 
    
         
            -
                raw = sample_object.to_msgpack.to_s * 4
         
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
       222 
     | 
    
         
            -
                n = 0
         
     | 
| 
       223 
     | 
    
         
            -
                raw.split(//).each do |b|
         
     | 
| 
       224 
     | 
    
         
            -
                  GC.start
         
     | 
| 
       225 
     | 
    
         
            -
                  unpacker.feed_each(b) {|o|
         
     | 
| 
       226 
     | 
    
         
            -
                    GC.start
         
     | 
| 
       227 
     | 
    
         
            -
                    o.should == sample_object
         
     | 
| 
       228 
     | 
    
         
            -
                    n += 1
         
     | 
| 
       229 
     | 
    
         
            -
                  }
         
     | 
| 
       230 
     | 
    
         
            -
                  GC.start
         
     | 
| 
       231 
     | 
    
         
            -
                end
         
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
                n.should == 4
         
     | 
| 
       234 
     | 
    
         
            -
              end
         
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
              it "buffer" do
         
     | 
| 
       237 
     | 
    
         
            -
                orig = "a"*32*1024*4
         
     | 
| 
       238 
     | 
    
         
            -
                raw = orig.to_msgpack.to_s
         
     | 
| 
       239 
     | 
    
         
            -
             
     | 
| 
       240 
     | 
    
         
            -
                n = 655
         
     | 
| 
       241 
     | 
    
         
            -
                times = raw.size / n
         
     | 
| 
       242 
     | 
    
         
            -
                times += 1 unless raw.size % n == 0
         
     | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
     | 
    
         
            -
                off = 0
         
     | 
| 
       245 
     | 
    
         
            -
                parsed = false
         
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
                times.times do
         
     | 
| 
       248 
     | 
    
         
            -
                  parsed.should == false
         
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
                  seg = raw[off, n]
         
     | 
| 
       251 
     | 
    
         
            -
                  off += seg.length
         
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
       253 
     | 
    
         
            -
                  unpacker.feed_each(seg) {|obj|
         
     | 
| 
       254 
     | 
    
         
            -
                    parsed.should == false
         
     | 
| 
       255 
     | 
    
         
            -
                    obj.should == orig
         
     | 
| 
       256 
     | 
    
         
            -
                    parsed = true
         
     | 
| 
       257 
     | 
    
         
            -
                  }
         
     | 
| 
       258 
     | 
    
         
            -
                end
         
     | 
| 
       259 
     | 
    
         
            -
             
     | 
| 
       260 
     | 
    
         
            -
                parsed.should == true
         
     | 
| 
       261 
     | 
    
         
            -
              end
         
     | 
| 
       262 
     | 
    
         
            -
             
     | 
| 
       263 
     | 
    
         
            -
              it 'MessagePack.unpack symbolize_keys' do
         
     | 
| 
       264 
     | 
    
         
            -
                symbolized_hash = {:a => 'b', :c => 'd'}
         
     | 
| 
       265 
     | 
    
         
            -
                MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
         
     | 
| 
       266 
     | 
    
         
            -
                MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
         
     | 
| 
       267 
     | 
    
         
            -
              end
         
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
              it 'Unpacker#unpack symbolize_keys' do
         
     | 
| 
       270 
     | 
    
         
            -
                unpacker = Unpacker.new(:symbolize_keys => true)
         
     | 
| 
       271 
     | 
    
         
            -
                symbolized_hash = {:a => 'b', :c => 'd'}
         
     | 
| 
       272 
     | 
    
         
            -
                unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
         
     | 
| 
       273 
     | 
    
         
            -
              end
         
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
              it "msgpack str 8 type" do
         
     | 
| 
       276 
     | 
    
         
            -
                MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
         
     | 
| 
       277 
     | 
    
         
            -
                MessagePack.unpack([0xd9, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
         
     | 
| 
       278 
     | 
    
         
            -
                MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       279 
     | 
    
         
            -
                MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       280 
     | 
    
         
            -
              end
         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
              it "msgpack str 16 type" do
         
     | 
| 
       283 
     | 
    
         
            -
                MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
         
     | 
| 
       284 
     | 
    
         
            -
                MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
         
     | 
| 
       285 
     | 
    
         
            -
                MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       286 
     | 
    
         
            -
                MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       287 
     | 
    
         
            -
              end
         
     | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
       289 
     | 
    
         
            -
              it "msgpack str 32 type" do
         
     | 
| 
       290 
     | 
    
         
            -
                MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
         
     | 
| 
       291 
     | 
    
         
            -
                MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8
         
     | 
| 
       292 
     | 
    
         
            -
                MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       293 
     | 
    
         
            -
                MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       294 
     | 
    
         
            -
              end
         
     | 
| 
       295 
     | 
    
         
            -
             
     | 
| 
       296 
     | 
    
         
            -
              it "msgpack bin 8 type" do
         
     | 
| 
       297 
     | 
    
         
            -
                MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
         
     | 
| 
       298 
     | 
    
         
            -
                MessagePack.unpack([0xc4, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
         
     | 
| 
       299 
     | 
    
         
            -
                MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       300 
     | 
    
         
            -
                MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       301 
     | 
    
         
            -
              end
         
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
              it "msgpack bin 16 type" do
         
     | 
| 
       304 
     | 
    
         
            -
                MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
         
     | 
| 
       305 
     | 
    
         
            -
                MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT
         
     | 
| 
       306 
     | 
    
         
            -
                MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       307 
     | 
    
         
            -
                MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       308 
     | 
    
         
            -
              end
         
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
              it "msgpack bin 32 type" do
         
     | 
| 
       311 
     | 
    
         
            -
                MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
         
     | 
| 
       312 
     | 
    
         
            -
                MessagePack.unpack([0xc6, 0x0, 0x00, 0x00, 0x000].pack('C*')).encoding.should == Encoding::ASCII_8BIT
         
     | 
| 
       313 
     | 
    
         
            -
                MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
         
     | 
| 
       314 
     | 
    
         
            -
                MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
         
     | 
| 
       315 
     | 
    
         
            -
              end
         
     | 
| 
       316 
69 
     | 
    
         
             
            end
         
     | 
| 
       317 
70 
     | 
    
         | 
    
        data/spec/factory_spec.rb
    CHANGED
    
    | 
         @@ -1,8 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: ascii-8bit
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            eval("return") if java?
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
4 
     | 
    
         
             
            describe MessagePack::Factory do
         
     | 
| 
       7 
5 
     | 
    
         
             
              subject do
         
     | 
| 
       8 
6 
     | 
    
         
             
                described_class.new
         
     | 
| 
         @@ -220,7 +218,6 @@ describe MessagePack::Factory do 
     | 
|
| 
       220 
218 
     | 
    
         
             
                require_relative 'exttypes'
         
     | 
| 
       221 
219 
     | 
    
         | 
| 
       222 
220 
     | 
    
         
             
                it 'should be referred by MessagePack.pack and MessagePack.unpack' do
         
     | 
| 
       223 
     | 
    
         
            -
                  skip("not supported yet in JRuby implementation") if java?
         
     | 
| 
       224 
221 
     | 
    
         
             
                  MessagePack::DefaultFactory.register_type(DummyTimeStamp1::TYPE, DummyTimeStamp1)
         
     | 
| 
       225 
222 
     | 
    
         
             
                  MessagePack::DefaultFactory.register_type(DummyTimeStamp2::TYPE, DummyTimeStamp2, packer: :serialize, unpacker: :deserialize)
         
     | 
| 
       226 
223 
     | 
    
         | 
| 
         @@ -2,43 +2,35 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'stringio'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'tempfile'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       6 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            describe  
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                when Array
         
     | 
| 
       12 
     | 
    
         
            -
                  struct.each { |v| flatten(v, results) }
         
     | 
| 
       13 
     | 
    
         
            -
                when Hash
         
     | 
| 
       14 
     | 
    
         
            -
                  struct.each { |k, v| flatten(v, flatten(k, results)) }
         
     | 
| 
       15 
     | 
    
         
            -
                else
         
     | 
| 
       16 
     | 
    
         
            -
                  results << struct
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
                results
         
     | 
| 
      
 8 
     | 
    
         
            +
            describe MessagePack::Unpacker do
         
     | 
| 
      
 9 
     | 
    
         
            +
              let :unpacker do
         
     | 
| 
      
 10 
     | 
    
         
            +
                MessagePack::Unpacker.new
         
     | 
| 
       19 
11 
     | 
    
         
             
              end
         
     | 
| 
       20 
12 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
               
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
              let :packer do
         
     | 
| 
      
 14 
     | 
    
         
            +
                MessagePack::Packer.new
         
     | 
| 
       23 
15 
     | 
    
         
             
              end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       25 
17 
     | 
    
         
             
              let :buffer1 do
         
     | 
| 
       26 
18 
     | 
    
         
             
                MessagePack.pack(:foo => 'bar')
         
     | 
| 
       27 
19 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       29 
21 
     | 
    
         
             
              let :buffer2 do
         
     | 
| 
       30 
22 
     | 
    
         
             
                MessagePack.pack(:hello => {:world => [1, 2, 3]})
         
     | 
| 
       31 
23 
     | 
    
         
             
              end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       33 
25 
     | 
    
         
             
              let :buffer3 do
         
     | 
| 
       34 
26 
     | 
    
         
             
                MessagePack.pack(:x => 'y')
         
     | 
| 
       35 
27 
     | 
    
         
             
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       37 
29 
     | 
    
         
             
              describe '#execute/#execute_limit/#finished?' do
         
     | 
| 
       38 
30 
     | 
    
         
             
                let :buffer do
         
     | 
| 
       39 
31 
     | 
    
         
             
                  buffer1 + buffer2 + buffer3
         
     | 
| 
       40 
32 
     | 
    
         
             
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       42 
34 
     | 
    
         
             
                it 'extracts an object from the buffer' do
         
     | 
| 
       43 
35 
     | 
    
         
             
                  subject.execute(buffer, 0)
         
     | 
| 
       44 
36 
     | 
    
         
             
                  subject.data.should == {'foo' => 'bar'}
         
     | 
| 
         @@ -53,7 +45,7 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       53 
45 
     | 
    
         
             
                  subject.execute_limit(buffer, buffer1.length, buffer2.length)
         
     | 
| 
       54 
46 
     | 
    
         
             
                  subject.data.should == {'hello' => {'world' => [1, 2, 3]}}
         
     | 
| 
       55 
47 
     | 
    
         
             
                end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       57 
49 
     | 
    
         
             
                it 'extracts nothing if the limit cuts an object in half' do
         
     | 
| 
       58 
50 
     | 
    
         
             
                  subject.execute_limit(buffer, buffer1.length, 3)
         
     | 
| 
       59 
51 
     | 
    
         
             
                  subject.data.should be_nil
         
     | 
| 
         @@ -63,63 +55,17 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       63 
55 
     | 
    
         
             
                  subject.execute(buffer, 0).should == buffer1.length
         
     | 
| 
       64 
56 
     | 
    
         
             
                  subject.execute(buffer, buffer1.length).should == buffer1.length + buffer2.length
         
     | 
| 
       65 
57 
     | 
    
         
             
                end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       67 
59 
     | 
    
         
             
                it 'is finished if #data returns an object' do
         
     | 
| 
       68 
60 
     | 
    
         
             
                  subject.execute_limit(buffer, buffer1.length, buffer2.length)
         
     | 
| 
       69 
61 
     | 
    
         
             
                  subject.should be_finished
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       71 
63 
     | 
    
         
             
                  subject.execute_limit(buffer, buffer1.length, 3)
         
     | 
| 
       72 
64 
     | 
    
         
             
                  subject.should_not be_finished
         
     | 
| 
       73 
65 
     | 
    
         
             
                end
         
     | 
| 
       74 
66 
     | 
    
         
             
              end
         
     | 
| 
       75 
67 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
              describe '#read' do
         
     | 
| 
       77 
     | 
    
         
            -
                context 'with a buffer' do
         
     | 
| 
       78 
     | 
    
         
            -
                  it 'reads objects' do
         
     | 
| 
       79 
     | 
    
         
            -
                    objects = []
         
     | 
| 
       80 
     | 
    
         
            -
                    subject.feed(buffer1)
         
     | 
| 
       81 
     | 
    
         
            -
                    subject.feed(buffer2)
         
     | 
| 
       82 
     | 
    
         
            -
                    subject.feed(buffer3)
         
     | 
| 
       83 
     | 
    
         
            -
                    objects << subject.read
         
     | 
| 
       84 
     | 
    
         
            -
                    objects << subject.read
         
     | 
| 
       85 
     | 
    
         
            -
                    objects << subject.read
         
     | 
| 
       86 
     | 
    
         
            -
                    objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       87 
     | 
    
         
            -
                  end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                  it 'reads map header' do
         
     | 
| 
       90 
     | 
    
         
            -
                    subject.feed({}.to_msgpack)
         
     | 
| 
       91 
     | 
    
         
            -
                    subject.read_map_header.should == 0
         
     | 
| 
       92 
     | 
    
         
            -
                  end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                  it 'reads array header' do
         
     | 
| 
       95 
     | 
    
         
            -
                    subject.feed([].to_msgpack)
         
     | 
| 
       96 
     | 
    
         
            -
                    subject.read_array_header.should == 0
         
     | 
| 
       97 
     | 
    
         
            -
                  end
         
     | 
| 
       98 
     | 
    
         
            -
                end
         
     | 
| 
       99 
     | 
    
         
            -
              end
         
     | 
| 
       100 
     | 
    
         
            -
              
         
     | 
| 
       101 
68 
     | 
    
         
             
              describe '#each' do
         
     | 
| 
       102 
     | 
    
         
            -
                context 'with a buffer' do
         
     | 
| 
       103 
     | 
    
         
            -
                  it 'yields each object in the buffer' do
         
     | 
| 
       104 
     | 
    
         
            -
                    objects = []
         
     | 
| 
       105 
     | 
    
         
            -
                    subject.feed(buffer1)
         
     | 
| 
       106 
     | 
    
         
            -
                    subject.feed(buffer2)
         
     | 
| 
       107 
     | 
    
         
            -
                    subject.feed(buffer3)
         
     | 
| 
       108 
     | 
    
         
            -
                    subject.each do |obj|
         
     | 
| 
       109 
     | 
    
         
            -
                      objects << obj
         
     | 
| 
       110 
     | 
    
         
            -
                    end
         
     | 
| 
       111 
     | 
    
         
            -
                    objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       112 
     | 
    
         
            -
                  end
         
     | 
| 
       113 
     | 
    
         
            -
                  
         
     | 
| 
       114 
     | 
    
         
            -
                  it 'returns an enumerator when no block is given' do
         
     | 
| 
       115 
     | 
    
         
            -
                    subject.feed(buffer1)
         
     | 
| 
       116 
     | 
    
         
            -
                    subject.feed(buffer2)
         
     | 
| 
       117 
     | 
    
         
            -
                    subject.feed(buffer3)
         
     | 
| 
       118 
     | 
    
         
            -
                    enum = subject.each
         
     | 
| 
       119 
     | 
    
         
            -
                    enum.map { |obj| obj.keys.first }.should == %w[foo hello x]
         
     | 
| 
       120 
     | 
    
         
            -
                  end
         
     | 
| 
       121 
     | 
    
         
            -
                end
         
     | 
| 
       122 
     | 
    
         
            -
                
         
     | 
| 
       123 
69 
     | 
    
         
             
                context 'with a StringIO stream' do
         
     | 
| 
       124 
70 
     | 
    
         
             
                  it 'yields each object in the stream' do
         
     | 
| 
       125 
71 
     | 
    
         
             
                    objects = []
         
     | 
| 
         @@ -130,7 +76,7 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       130 
76 
     | 
    
         
             
                    objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       131 
77 
     | 
    
         
             
                  end
         
     | 
| 
       132 
78 
     | 
    
         
             
                end
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       134 
80 
     | 
    
         
             
                context 'with a File stream' do
         
     | 
| 
       135 
81 
     | 
    
         
             
                  it 'yields each object in the stream' do
         
     | 
| 
       136 
82 
     | 
    
         
             
                    objects = []
         
     | 
| 
         @@ -146,40 +92,8 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       146 
92 
     | 
    
         
             
                    objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       147 
93 
     | 
    
         
             
                  end
         
     | 
| 
       148 
94 
     | 
    
         
             
                end
         
     | 
| 
       149 
     | 
    
         
            -
                
         
     | 
| 
       150 
     | 
    
         
            -
                context 'with a stream passed to the constructor' do
         
     | 
| 
       151 
     | 
    
         
            -
                  it 'yields each object in the stream' do
         
     | 
| 
       152 
     | 
    
         
            -
                    objects = []
         
     | 
| 
       153 
     | 
    
         
            -
                    unpacker = described_class.new(StringIO.new(buffer1 + buffer2 + buffer3))
         
     | 
| 
       154 
     | 
    
         
            -
                    unpacker.each do |obj|
         
     | 
| 
       155 
     | 
    
         
            -
                      objects << obj
         
     | 
| 
       156 
     | 
    
         
            -
                    end
         
     | 
| 
       157 
     | 
    
         
            -
                    objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       158 
     | 
    
         
            -
                  end
         
     | 
| 
       159 
     | 
    
         
            -
                end
         
     | 
| 
       160 
95 
     | 
    
         
             
              end
         
     | 
| 
       161 
     | 
    
         
            -
              
         
     | 
| 
       162 
     | 
    
         
            -
              describe '#feed_each' do
         
     | 
| 
       163 
     | 
    
         
            -
                it 'feeds the buffer then runs #each' do
         
     | 
| 
       164 
     | 
    
         
            -
                  objects = []
         
     | 
| 
       165 
     | 
    
         
            -
                  subject.feed_each(buffer1 + buffer2 + buffer3) do |obj|
         
     | 
| 
       166 
     | 
    
         
            -
                    objects << obj
         
     | 
| 
       167 
     | 
    
         
            -
                  end
         
     | 
| 
       168 
     | 
    
         
            -
                  objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       169 
     | 
    
         
            -
                end
         
     | 
| 
       170 
96 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                it 'handles chunked data' do
         
     | 
| 
       172 
     | 
    
         
            -
                  objects = []
         
     | 
| 
       173 
     | 
    
         
            -
                  buffer = buffer1 + buffer2 + buffer3
         
     | 
| 
       174 
     | 
    
         
            -
                  buffer.chars.each do |ch|
         
     | 
| 
       175 
     | 
    
         
            -
                    subject.feed_each(ch) do |obj|
         
     | 
| 
       176 
     | 
    
         
            -
                      objects << obj
         
     | 
| 
       177 
     | 
    
         
            -
                    end
         
     | 
| 
       178 
     | 
    
         
            -
                  end
         
     | 
| 
       179 
     | 
    
         
            -
                  objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}]
         
     | 
| 
       180 
     | 
    
         
            -
                end
         
     | 
| 
       181 
     | 
    
         
            -
              end
         
     | 
| 
       182 
     | 
    
         
            -
              
         
     | 
| 
       183 
97 
     | 
    
         
             
              describe '#fill' do
         
     | 
| 
       184 
98 
     | 
    
         
             
                it 'is a no-op' do
         
     | 
| 
       185 
99 
     | 
    
         
             
                  subject.stream = StringIO.new(buffer1 + buffer2 + buffer3)
         
     | 
| 
         @@ -187,22 +101,17 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       187 
101 
     | 
    
         
             
                  subject.each { |obj| }
         
     | 
| 
       188 
102 
     | 
    
         
             
                end
         
     | 
| 
       189 
103 
     | 
    
         
             
              end
         
     | 
| 
       190 
     | 
    
         
            -
              
         
     | 
| 
       191 
     | 
    
         
            -
              describe '#reset' do
         
     | 
| 
       192 
     | 
    
         
            -
                context 'with a buffer' do
         
     | 
| 
       193 
     | 
    
         
            -
                  it 'is unclear what it is supposed to do'
         
     | 
| 
       194 
     | 
    
         
            -
                end
         
     | 
| 
       195 
     | 
    
         
            -
                
         
     | 
| 
       196 
     | 
    
         
            -
                context 'with a stream' do
         
     | 
| 
       197 
     | 
    
         
            -
                  it 'is unclear what it is supposed to do'
         
     | 
| 
       198 
     | 
    
         
            -
                end
         
     | 
| 
       199 
     | 
    
         
            -
              end
         
     | 
| 
       200 
104 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
               
     | 
| 
       202 
     | 
    
         
            -
                 
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
                   
     | 
| 
      
 105 
     | 
    
         
            +
              def flatten(struct, results = [])
         
     | 
| 
      
 106 
     | 
    
         
            +
                case struct
         
     | 
| 
      
 107 
     | 
    
         
            +
                when Array
         
     | 
| 
      
 108 
     | 
    
         
            +
                  struct.each { |v| flatten(v, results) }
         
     | 
| 
      
 109 
     | 
    
         
            +
                when Hash
         
     | 
| 
      
 110 
     | 
    
         
            +
                  struct.each { |k, v| flatten(v, flatten(k, results)) }
         
     | 
| 
      
 111 
     | 
    
         
            +
                else
         
     | 
| 
      
 112 
     | 
    
         
            +
                  results << struct
         
     | 
| 
       205 
113 
     | 
    
         
             
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
                results
         
     | 
| 
       206 
115 
     | 
    
         
             
              end
         
     | 
| 
       207 
116 
     | 
    
         | 
| 
       208 
117 
     | 
    
         
             
              context 'encoding', :encodings do
         
     | 
| 
         @@ -229,15 +138,15 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       229 
138 
     | 
    
         
             
                  Encoding.default_external = Encoding::ISO_8859_1
         
     | 
| 
       230 
139 
     | 
    
         
             
                end
         
     | 
| 
       231 
140 
     | 
    
         | 
| 
       232 
     | 
    
         
            -
                it 'produces results with  
     | 
| 
      
 141 
     | 
    
         
            +
                it 'produces results with encoding as binary or string(utf8)' do
         
     | 
| 
       233 
142 
     | 
    
         
             
                  unpacker.execute(buffer, 0)
         
     | 
| 
       234 
143 
     | 
    
         
             
                  strings = flatten(unpacker.data).grep(String)
         
     | 
| 
       235 
     | 
    
         
            -
                  strings.map(&:encoding).uniq.should == [Encoding 
     | 
| 
      
 144 
     | 
    
         
            +
                  strings.map(&:encoding).uniq.sort{|a,b| a.to_s <=> b.to_s}.should == [Encoding::ASCII_8BIT, Encoding::UTF_8]
         
     | 
| 
       236 
145 
     | 
    
         
             
                end
         
     | 
| 
       237 
146 
     | 
    
         | 
| 
       238 
147 
     | 
    
         
             
                it 'recodes to internal encoding' do
         
     | 
| 
       239 
148 
     | 
    
         
             
                  unpacker.execute(buffer, 0)
         
     | 
| 
       240 
     | 
    
         
            -
                  unpacker.data['nested'][1].keys.should == ["sk\xC3\xA5l".force_encoding(Encoding 
     | 
| 
      
 149 
     | 
    
         
            +
                  unpacker.data['nested'][1].keys.should == ["sk\xC3\xA5l".force_encoding(Encoding::UTF_8)]
         
     | 
| 
       241 
150 
     | 
    
         
             
                end
         
     | 
| 
       242 
151 
     | 
    
         
             
              end
         
     | 
| 
       243 
152 
     | 
    
         | 
| 
         @@ -255,23 +164,6 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       255 
164 
     | 
    
         
             
                    unpacker.execute(buffer, 0)
         
     | 
| 
       256 
165 
     | 
    
         
             
                    unpacker.data.should == {:hello => 'world', :nested => ['object', {:structure => true}]}
         
     | 
| 
       257 
166 
     | 
    
         
             
                  end
         
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
                  it 'can symbolize keys when using #each' do
         
     | 
| 
       260 
     | 
    
         
            -
                    objs = []
         
     | 
| 
       261 
     | 
    
         
            -
                    unpacker.feed(buffer)
         
     | 
| 
       262 
     | 
    
         
            -
                    unpacker.each do |obj|
         
     | 
| 
       263 
     | 
    
         
            -
                      objs << obj
         
     | 
| 
       264 
     | 
    
         
            -
                    end
         
     | 
| 
       265 
     | 
    
         
            -
                    objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}]
         
     | 
| 
       266 
     | 
    
         
            -
                  end
         
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
                  it 'can symbolize keys when using #feed_each' do
         
     | 
| 
       269 
     | 
    
         
            -
                    objs = []
         
     | 
| 
       270 
     | 
    
         
            -
                    unpacker.feed_each(buffer) do |obj|
         
     | 
| 
       271 
     | 
    
         
            -
                      objs << obj
         
     | 
| 
       272 
     | 
    
         
            -
                    end
         
     | 
| 
       273 
     | 
    
         
            -
                    objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}]
         
     | 
| 
       274 
     | 
    
         
            -
                  end
         
     | 
| 
       275 
167 
     | 
    
         
             
                end
         
     | 
| 
       276 
168 
     | 
    
         | 
| 
       277 
169 
     | 
    
         
             
                context 'encoding', :encodings do
         
     | 
| 
         @@ -280,35 +172,14 @@ describe ::MessagePack::Unpacker do 
     | 
|
| 
       280 
172 
     | 
    
         
             
                  end
         
     | 
| 
       281 
173 
     | 
    
         | 
| 
       282 
174 
     | 
    
         
             
                  let :unpacker do
         
     | 
| 
       283 
     | 
    
         
            -
                    described_class.new( 
     | 
| 
      
 175 
     | 
    
         
            +
                    described_class.new()
         
     | 
| 
       284 
176 
     | 
    
         
             
                  end
         
     | 
| 
       285 
177 
     | 
    
         | 
| 
       286 
     | 
    
         
            -
                  it ' 
     | 
| 
      
 178 
     | 
    
         
            +
                  it 'decode binary as ascii-8bit string when using #execute' do
         
     | 
| 
       287 
179 
     | 
    
         
             
                    unpacker.execute(buffer, 0)
         
     | 
| 
       288 
180 
     | 
    
         
             
                    strings = flatten(unpacker.data).grep(String)
         
     | 
| 
       289 
181 
     | 
    
         
             
                    strings.should == %w[hello world nested object structure]
         
     | 
| 
       290 
     | 
    
         
            -
                    strings.map(&:encoding).uniq.should == [Encoding:: 
     | 
| 
       291 
     | 
    
         
            -
                  end
         
     | 
| 
       292 
     | 
    
         
            -
             
     | 
| 
       293 
     | 
    
         
            -
                  it 'can hardcode encoding when using #each' do
         
     | 
| 
       294 
     | 
    
         
            -
                    objs = []
         
     | 
| 
       295 
     | 
    
         
            -
                    unpacker.feed(buffer)
         
     | 
| 
       296 
     | 
    
         
            -
                    unpacker.each do |obj|
         
     | 
| 
       297 
     | 
    
         
            -
                      objs << obj
         
     | 
| 
       298 
     | 
    
         
            -
                    end
         
     | 
| 
       299 
     | 
    
         
            -
                    strings = flatten(objs).grep(String)
         
     | 
| 
       300 
     | 
    
         
            -
                    strings.should == %w[hello world nested object structure]
         
     | 
| 
       301 
     | 
    
         
            -
                    strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
         
     | 
| 
       302 
     | 
    
         
            -
                  end
         
     | 
| 
       303 
     | 
    
         
            -
             
     | 
| 
       304 
     | 
    
         
            -
                  it 'can hardcode encoding when using #feed_each' do
         
     | 
| 
       305 
     | 
    
         
            -
                    objs = []
         
     | 
| 
       306 
     | 
    
         
            -
                    unpacker.feed_each(buffer) do |obj|
         
     | 
| 
       307 
     | 
    
         
            -
                      objs << obj
         
     | 
| 
       308 
     | 
    
         
            -
                    end
         
     | 
| 
       309 
     | 
    
         
            -
                    strings = flatten(objs).grep(String)
         
     | 
| 
       310 
     | 
    
         
            -
                    strings.should == %w[hello world nested object structure]
         
     | 
| 
       311 
     | 
    
         
            -
                    strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
         
     | 
| 
      
 182 
     | 
    
         
            +
                    strings.map(&:encoding).uniq.should == [Encoding::ASCII_8BIT]
         
     | 
| 
       312 
183 
     | 
    
         
             
                  end
         
     | 
| 
       313 
184 
     | 
    
         
             
                end
         
     | 
| 
       314 
185 
     | 
    
         
             
              end
         
     |