msgpack 1.3.3-java → 1.4.3-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd83394ab16cee94026b1022400f09a82074ddd7f9380f647f6f89d8c1613197
4
- data.tar.gz: ddf9c1a2de71f9581edb08433f61022ec5ada2e934e22587f808c419cac759aa
3
+ metadata.gz: c13610f5243e8a0bbcb5be9d2e4cec62e5f90f443a90c61501b088ebd8d958c9
4
+ data.tar.gz: 5afe456db4aa4cf41795d8bd62b66b6ce94887408edc2629ec896a69f31b9741
5
5
  SHA512:
6
- metadata.gz: '09552bad837d481738eeadeb80a047310a4568be65e625ff75157a995432ee2b6b40b0d4462eb3392293c1c5855d982169ed218a56c2380a9c9f3290a7233d2b'
7
- data.tar.gz: 1608b50ebc75284b5f698b6ae2c8afc2cb05e33e4a395d895afbe9bc747e57084d46e11f554bbcd61475972e7420e72c68f040aa369a53dfcfdc53f26652f1c2
6
+ metadata.gz: c1760ab752e904de9d80651134c92a21763bf161d64de9c7564b1e9532bb84ff0b31b5006eb78790c9c49293cf017a222806dfbc9a6c282ef242ebbb6c2d6a4b
7
+ data.tar.gz: 4d9c0f170b9aeff8e08f74aa9103c7ba2949132d3aa3772f0b6db596ed085738c8f98d78b5f6d35c09b98bb264de6c82f43ebe9b0689ca468f57cbeba85061bc
Binary file
@@ -1,9 +1,19 @@
1
1
  class Symbol
2
- def to_msgpack_ext
3
- [to_s].pack('A*')
2
+ # to_msgpack_ext is supposed to return a binary string.
3
+ # The canonical way to do it for symbols would be:
4
+ # [to_s].pack('A*')
5
+ # However in this instance we can take a shortcut
6
+ if method_defined?(:name)
7
+ alias_method :to_msgpack_ext, :name
8
+ else
9
+ alias_method :to_msgpack_ext, :to_s
4
10
  end
5
11
 
6
12
  def self.from_msgpack_ext(data)
7
- data.unpack('A*').first.to_sym
13
+ # from_msgpack_ext is supposed to parse a binary string.
14
+ # The canonical way to do it for symbols would be:
15
+ # data.unpack1('A*').to_sym
16
+ # However in this instance we can take a shortcut
17
+ data.to_sym
8
18
  end
9
- end
19
+ end
data/lib/msgpack/time.rb CHANGED
@@ -18,7 +18,7 @@ module MessagePack
18
18
  else
19
19
  lambda do |payload|
20
20
  tv = MessagePack::Timestamp.from_msgpack_ext(payload)
21
- ::Time.at(tv.sec, tv.nsec / 1000.0)
21
+ ::Time.at(tv.sec, tv.nsec / 1000.0r)
22
22
  end
23
23
  end
24
24
 
@@ -1,10 +1,6 @@
1
1
  module MessagePack
2
- VERSION = "1.3.3"
3
-
4
- # NOTE for msgpack-ruby maintainer:
5
- # Check these things to release new binaryes for new Ruby versions (especially for Windows):
6
- # * versions/supports of rake-compiler & rake-compiler-dock
7
- # https://github.com/rake-compiler/rake-compiler-dock/blob/master/History.md
8
- # * update RUBY_CC_VERSION in Rakefile
9
- # * check Ruby dependency of released mswin gem details
2
+ VERSION = "1.4.3"
3
+ # Note for maintainers:
4
+ # Don't miss building/releasing the JRuby version (rake buld:java)
5
+ # See "How to build -java rubygems" in README for more details.
10
6
  end
data/lib/msgpack.rb CHANGED
@@ -1,15 +1,10 @@
1
1
  require "msgpack/version"
2
2
 
3
3
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" # This is same with `/java/ =~ RUBY_VERSION`
4
- require "java"
5
4
  require "msgpack/msgpack.jar"
6
- org.msgpack.jruby.MessagePackLibrary.new.load(JRuby.runtime, false)
5
+ JRuby::Util.load_ext("org.msgpack.jruby.MessagePackLibrary")
7
6
  else
8
- begin
9
- require "msgpack/#{RUBY_VERSION[/\d+.\d+/]}/msgpack"
10
- rescue LoadError
11
- require "msgpack/msgpack"
12
- end
7
+ require "msgpack/msgpack"
13
8
  end
14
9
 
15
10
  require "msgpack/packer"
data/spec/factory_spec.rb CHANGED
@@ -280,6 +280,23 @@ describe MessagePack::Factory do
280
280
  unpacker.feed(packed_symbol).unpack
281
281
  end
282
282
 
283
+ context 'using the optimized symbol unpacker' do
284
+ before do
285
+ skip if IS_JRUBY # JRuby implementation doesn't support the optimized symbols unpacker for now
286
+ subject.register_type(
287
+ 0x00,
288
+ ::Symbol,
289
+ packer: :to_msgpack_ext,
290
+ unpacker: :from_msgpack_ext,
291
+ optimized_symbols_parsing: true,
292
+ )
293
+ end
294
+
295
+ it 'lets symbols survive a roundtrip' do
296
+ expect(symbol_after_roundtrip).to be :symbol
297
+ end
298
+ end
299
+
283
300
  context 'if no ext type is registered for symbols' do
284
301
  it 'converts symbols to string' do
285
302
  expect(symbol_after_roundtrip).to eq 'symbol'
data/spec/msgpack_spec.rb CHANGED
@@ -115,7 +115,7 @@ describe MessagePack do
115
115
  expect { MessagePack.pack(self) }.to raise_error(NoMethodError, /^undefined method `to_msgpack'/)
116
116
  end
117
117
 
118
- it 'rasies an error on #unpack with garbage' do
118
+ it 'raises an error on #unpack with garbage' do
119
119
  skip "but nothing was raised. why?"
120
120
  expect { MessagePack.unpack('asdka;sd') }.to raise_error(MessagePack::UnpackError)
121
121
  end
data/spec/packer_spec.rb CHANGED
@@ -488,6 +488,24 @@ describe MessagePack::Packer do
488
488
  it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
489
489
  end
490
490
 
491
+ shared_examples_for 'extension subclasses core type' do |klass|
492
+ before { stub_const('Value', Class.new(klass)) }
493
+ let(:object) { Value.new }
494
+ subject { packer.pack(object).to_s }
495
+
496
+ it "defaults to #{klass.name} packer if no extension is present" do
497
+ expect(subject).to eq(MessagePack.dump(klass.new))
498
+ end
499
+
500
+ it "uses core type extension for #{klass.name}" do
501
+ packer.register_type(0x01, Value, ->(_) { 'value_msgpacked' })
502
+ expect(subject).to eq("\xC7\x0F\x01value_msgpacked")
503
+ end
504
+ end
505
+ it_behaves_like 'extension subclasses core type', Hash
506
+ it_behaves_like 'extension subclasses core type', Array
507
+ it_behaves_like 'extension subclasses core type', String
508
+
491
509
  context 'when registering a type for symbols' do
492
510
  before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) }
493
511
 
data/spec/spec_helper.rb CHANGED
@@ -15,10 +15,37 @@ end
15
15
 
16
16
  require 'msgpack'
17
17
 
18
+ if GC.respond_to?(:verify_compaction_references)
19
+ # This method was added in Ruby 3.0.0. Calling it this way asks the GC to
20
+ # move objects around, helping to find object movement bugs.
21
+ GC.verify_compaction_references(double_heap: true, toward: :empty)
22
+ end
23
+
24
+ if GC.respond_to?(:auto_compact=)
25
+ GC.auto_compact = true
26
+ end
27
+
18
28
  def java?
19
29
  /java/ =~ RUBY_PLATFORM
20
30
  end
21
31
 
32
+ # checking if Hash#[]= (rb_hash_aset) dedupes string keys
33
+ def automatic_string_keys_deduplication?
34
+ h = {}
35
+ x = {}
36
+ r = rand.to_s
37
+ h[%W(#{r}).join('')] = :foo
38
+ x[%W(#{r}).join('')] = :foo
39
+
40
+ x.keys[0].equal?(h.keys[0])
41
+ end
42
+
43
+ def string_deduplication?
44
+ r1 = rand.to_s
45
+ r2 = r1.dup
46
+ (-r1).equal?(-r2)
47
+ end
48
+
22
49
  if java?
23
50
  RSpec.configure do |c|
24
51
  c.treat_symbols_as_metadata_keys_with_true_values = true
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
+ IS_JRUBY = Kernel.const_defined?(:JRUBY_VERSION)
6
+
5
7
  describe MessagePack::Timestamp do
6
8
  describe 'malformed format' do
7
9
  it do
@@ -60,6 +62,44 @@ describe MessagePack::Timestamp do
60
62
  it 'runs correctly (regression)' do
61
63
  expect(factory.unpack(factory.pack(Time.utc(2200)))).to eq(Time.utc(2200))
62
64
  end
65
+
66
+ let(:time32_max) { Time.new(2106, 2, 7, 6, 28, 15, "+00:00") }
67
+ it 'is serialized into timestamp32' do
68
+ expect(factory.pack(time32_max).size).to be 6
69
+ expect(factory.unpack(factory.pack(time32_max)).utc).to eq(time32_max)
70
+ end
71
+
72
+ let(:time64_min) { Time.new(2106, 2, 7, 6, 28, 16, "+00:00") }
73
+ it 'is serialized into timestamp64' do
74
+ expect(factory.pack(time64_min).size).to be 10
75
+ expect(factory.unpack(factory.pack(time64_min)).utc).to eq(time64_min)
76
+ end
77
+
78
+ let(:time64_max) { Time.at(Time.new(2514, 5, 30, 1, 53, 3, "+00:00").to_i, 999999999 / 1000.0r).utc } # TODO: use Time.at(sec, nsec, :nsec) when removing Ruby 2.4 from the list
79
+ it 'is serialized into timestamp64' do
80
+ expect(factory.pack(time64_max).size).to be 10
81
+ expect(factory.unpack(factory.pack(time64_max)).utc).to eq(time64_max)
82
+ end
83
+
84
+ let(:time96_positive_min) { Time.new(2514, 5, 30, 1, 53, 4, "+00:00") }
85
+ it 'is serialized into timestamp96' do
86
+ expect(factory.pack(time96_positive_min).size).to be 15
87
+ expect(factory.unpack(factory.pack(time96_positive_min)).utc).to eq(time96_positive_min)
88
+ end
89
+
90
+ let(:time96_min) { Time.at(-2**63).utc }
91
+ it 'is serialized into timestamp96' do
92
+ skip if IS_JRUBY # JRuby cannot handle numerics larger than long
93
+ expect(factory.pack(time96_min).size).to be 15
94
+ expect(factory.unpack(factory.pack(time96_min)).utc).to eq(time96_min)
95
+ end
96
+
97
+ let(:time96_max) { Time.at(2**63 - 1).utc }
98
+ it 'is serialized into timestamp96' do
99
+ skip if IS_JRUBY # JRuby cannot handle numerics larger than long
100
+ expect(factory.pack(time96_max).size).to be 15
101
+ expect(factory.unpack(factory.pack(time96_max)).utc).to eq(time96_max)
102
+ end
63
103
  end
64
104
 
65
105
  describe 'register_type with MessagePack::Timestamp' do
@@ -18,13 +18,35 @@ describe MessagePack::Unpacker do
18
18
  it 'gets options to specify how to unpack values' do
19
19
  u1 = MessagePack::Unpacker.new
20
20
  u1.symbolize_keys?.should == false
21
+ u1.freeze?.should == false
21
22
  u1.allow_unknown_ext?.should == false
22
23
 
23
- u2 = MessagePack::Unpacker.new(symbolize_keys: true, allow_unknown_ext: true)
24
+ u2 = MessagePack::Unpacker.new(symbolize_keys: true, freeze: true, allow_unknown_ext: true)
24
25
  u2.symbolize_keys?.should == true
26
+ u2.freeze?.should == true
25
27
  u2.allow_unknown_ext?.should == true
26
28
  end
27
29
 
30
+ if automatic_string_keys_deduplication?
31
+ it 'ensure string hash keys are deduplicated' do
32
+ sample_data = [{"foo" => 1}, {"foo" => 2}]
33
+ sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
34
+ unpacker.feed(sample_packed)
35
+ hashes = nil
36
+ unpacker.each { |obj| hashes = obj }
37
+ expect(hashes[0].keys.first).to equal(hashes[1].keys.first)
38
+ end
39
+
40
+ it 'ensure strings are not deduplicated' do
41
+ sample_data = ["foo"]
42
+ sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
43
+ unpacker.feed(sample_packed)
44
+ ary = nil
45
+ unpacker.each { |obj| ary = obj }
46
+ expect(ary.first.frozen?).to eq(false)
47
+ end
48
+ end
49
+
28
50
  it 'gets IO or object which has #read to read data from it' do
29
51
  sample_data = {"message" => "morning!", "num" => 1}
30
52
  sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
@@ -621,6 +643,14 @@ describe MessagePack::Unpacker do
621
643
  array = ['foo'] * 10_000
622
644
  MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000
623
645
  end
646
+
647
+ it 'preserves string encoding (issue #200)' do
648
+ string = 'a'.force_encoding(Encoding::UTF_8)
649
+ MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding
650
+
651
+ string *= 256
652
+ MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding
653
+ end
624
654
  end
625
655
 
626
656
  context 'extensions' do
@@ -651,6 +681,88 @@ describe MessagePack::Unpacker do
651
681
  end
652
682
  end
653
683
 
684
+ context 'freeze' do
685
+ let :struct do
686
+ {'hello' => 'world', 'nested' => ['object', {'structure' => true}]}
687
+ end
688
+
689
+ let :buffer do
690
+ MessagePack.pack(struct)
691
+ end
692
+
693
+ let :unpacker do
694
+ described_class.new(:freeze => true)
695
+ end
696
+
697
+ it 'can freeze objects when using .unpack' do
698
+ parsed_struct = MessagePack.unpack(buffer, freeze: true)
699
+ parsed_struct.should == struct
700
+
701
+ parsed_struct.should be_frozen
702
+ parsed_struct['hello'].should be_frozen
703
+ parsed_struct['nested'].should be_frozen
704
+ parsed_struct['nested'][0].should be_frozen
705
+ parsed_struct['nested'][1].should be_frozen
706
+
707
+ if string_deduplication?
708
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
709
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
710
+ parsed_struct.values[0].should be_equal('world'.freeze)
711
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
712
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
713
+ end
714
+ end
715
+
716
+ it 'can freeze objects when using #each' do
717
+ objs = []
718
+ unpacker.feed(buffer)
719
+ unpacker.each do |obj|
720
+ objs << obj
721
+ end
722
+
723
+ parsed_struct = objs.first
724
+ parsed_struct.should == struct
725
+
726
+ parsed_struct.should be_frozen
727
+ parsed_struct['hello'].should be_frozen
728
+ parsed_struct['nested'].should be_frozen
729
+ parsed_struct['nested'][0].should be_frozen
730
+ parsed_struct['nested'][1].should be_frozen
731
+
732
+ if string_deduplication?
733
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
734
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
735
+ parsed_struct.values[0].should be_equal('world'.freeze)
736
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
737
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
738
+ end
739
+ end
740
+
741
+ it 'can freeze objects when using #feed_each' do
742
+ objs = []
743
+ unpacker.feed_each(buffer) do |obj|
744
+ objs << obj
745
+ end
746
+
747
+ parsed_struct = objs.first
748
+ parsed_struct.should == struct
749
+
750
+ parsed_struct.should be_frozen
751
+ parsed_struct['hello'].should be_frozen
752
+ parsed_struct['nested'].should be_frozen
753
+ parsed_struct['nested'][0].should be_frozen
754
+ parsed_struct['nested'][1].should be_frozen
755
+
756
+ if string_deduplication?
757
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
758
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
759
+ parsed_struct.values[0].should be_equal('world'.freeze)
760
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
761
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
762
+ end
763
+ end
764
+ end
765
+
654
766
  context 'binary encoding', :encodings do
655
767
  let :buffer do
656
768
  MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.3
5
5
  platform: java
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-02-05 00:00:00.000000000 Z
13
+ date: 2022-01-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -43,17 +43,17 @@ dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '1.0'
48
+ version: '0'
49
49
  name: rake-compiler
50
50
  prerelease: false
51
51
  type: :development
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '1.0'
56
+ version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
@@ -153,14 +153,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: '0'
156
+ version: '2.4'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - - ">="
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.0.3
163
+ rubygems_version: 3.2.29
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: MessagePack, a binary-based efficient data interchange format.