msgpack 1.4.0-java → 1.4.4.pre1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/msgpack/msgpack.jar +0 -0
- data/lib/msgpack/symbol.rb +14 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +1 -2
- data/spec/factory_spec.rb +17 -0
- data/spec/msgpack_spec.rb +1 -1
- data/spec/packer_spec.rb +18 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/timestamp_spec.rb +40 -0
- data/spec/unpacker_spec.rb +17 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a983b0e034d40f10a34d82f7afc8aabfcc5f6c417522211a8e25c35818238cf2
|
4
|
+
data.tar.gz: c0bdb56faaac072ee40017d4cd7f3fd26a1e47f6c82e0becaa2cef12935f659e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1be244b5f61f116ea2c6690971041401e2005a65d49c5b71bbd971e6fb3244628dd0e1c0392cceec2f3eff5ea91c7f211da24fa6463864837c4ca787233f00bc
|
7
|
+
data.tar.gz: 36b5091b8502d01aa1e1aa97a8fdafed7107936add21487c80e0309f38d209ad15d4500bab34da3b94d9243771118e833c3a1386f78fbcf731aed913d79e56f9
|
data/lib/msgpack/msgpack.jar
CHANGED
Binary file
|
data/lib/msgpack/symbol.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
class Symbol
|
2
|
-
|
3
|
-
|
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
|
-
|
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
data/lib/msgpack/version.rb
CHANGED
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
|
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 '
|
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
|
data/spec/timestamp_spec.rb
CHANGED
@@ -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
|
data/spec/unpacker_spec.rb
CHANGED
@@ -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
|
@@ -634,6 +643,14 @@ describe MessagePack::Unpacker do
|
|
634
643
|
array = ['foo'] * 10_000
|
635
644
|
MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000
|
636
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
|
637
654
|
end
|
638
655
|
|
639
656
|
context 'extensions' do
|
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.
|
4
|
+
version: 1.4.4.pre1
|
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:
|
13
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,14 +153,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
requirements:
|
154
154
|
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version: '
|
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
|
-
version:
|
161
|
+
version: 1.3.1
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 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.
|