msgpack 1.4.2-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: 28c159245a02113dad1dfaf36a07a30950e00ecedd33b148eee8aed8e00b0b6f
4
- data.tar.gz: 7318156b3b7d71165a0203f2c665fb7c28b245a6419b456c51121a3b6d6b5bbe
3
+ metadata.gz: c13610f5243e8a0bbcb5be9d2e4cec62e5f90f443a90c61501b088ebd8d958c9
4
+ data.tar.gz: 5afe456db4aa4cf41795d8bd62b66b6ce94887408edc2629ec896a69f31b9741
5
5
  SHA512:
6
- metadata.gz: 061c33efbd315663b330d246a925b44aed1c7c47651fe459f76aae5f94470415350f146119ab6983a72a40911df19d275026a3b4d660d946ea7fb025af40095b
7
- data.tar.gz: b14c4efe89bbe77f4dab95b6d9d2e6e4a38a6d1a5e083d07c06a1b944b2e6a614b33ea5c1677e083be0406b65be7aaf70c3b4ee6d82c927b567306d509487764
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,5 +1,5 @@
1
1
  module MessagePack
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  # Note for maintainers:
4
4
  # Don't miss building/releasing the JRuby version (rake buld:java)
5
5
  # See "How to build -java rubygems" in README for more details.
data/lib/msgpack.rb CHANGED
@@ -1,9 +1,8 @@
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
7
  require "msgpack/msgpack"
9
8
  end
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,6 +15,16 @@ 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
@@ -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
@@ -36,6 +36,15 @@ describe MessagePack::Unpacker do
36
36
  unpacker.each { |obj| hashes = obj }
37
37
  expect(hashes[0].keys.first).to equal(hashes[1].keys.first)
38
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
39
48
  end
40
49
 
41
50
  it 'gets IO or object which has #read to read data from it' do
@@ -635,7 +644,7 @@ describe MessagePack::Unpacker do
635
644
  MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000
636
645
  end
637
646
 
638
- it 'preserve string encoding (issue #200)' do
647
+ it 'preserves string encoding (issue #200)' do
639
648
  string = 'a'.force_encoding(Encoding::UTF_8)
640
649
  MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding
641
650
 
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.4.2
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: 2021-02-01 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
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
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.