msgpack 1.5.6 → 1.8.0
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/ChangeLog +50 -0
- data/README.md +48 -12
- data/ext/java/org/msgpack/jruby/Buffer.java +3 -3
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +11 -20
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +1 -1
- data/ext/java/org/msgpack/jruby/Factory.java +11 -50
- data/ext/java/org/msgpack/jruby/Packer.java +9 -24
- data/ext/java/org/msgpack/jruby/Unpacker.java +15 -32
- data/ext/msgpack/buffer.c +69 -56
- data/ext/msgpack/buffer.h +138 -44
- data/ext/msgpack/buffer_class.c +132 -31
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/extconf.rb +20 -30
- data/ext/msgpack/factory_class.c +75 -86
- data/ext/msgpack/packer.c +13 -16
- data/ext/msgpack/packer.h +24 -21
- data/ext/msgpack/packer_class.c +72 -98
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +31 -28
- data/ext/msgpack/packer_ext_registry.h +10 -14
- data/ext/msgpack/rbinit.c +1 -1
- data/ext/msgpack/rmem.c +3 -4
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +201 -113
- data/ext/msgpack/unpacker.h +22 -15
- data/ext/msgpack/unpacker_class.c +87 -92
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +4 -16
- data/ext/msgpack/unpacker_ext_registry.h +3 -7
- data/lib/msgpack/buffer.rb +9 -0
- data/lib/msgpack/factory.rb +90 -63
- data/lib/msgpack/packer.rb +10 -1
- data/lib/msgpack/unpacker.rb +14 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +1 -0
- data/msgpack.gemspec +8 -3
- metadata +21 -51
- data/.github/workflows/ci.yaml +0 -57
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/Gemfile +0 -9
- data/Rakefile +0 -70
- data/appveyor.yml +0 -18
- data/bench/bench.rb +0 -78
- data/doclib/msgpack/buffer.rb +0 -193
- data/doclib/msgpack/core_ext.rb +0 -101
- data/doclib/msgpack/error.rb +0 -19
- data/doclib/msgpack/extension_value.rb +0 -9
- data/doclib/msgpack/factory.rb +0 -145
- data/doclib/msgpack/packer.rb +0 -209
- data/doclib/msgpack/time.rb +0 -22
- data/doclib/msgpack/timestamp.rb +0 -44
- data/doclib/msgpack/unpacker.rb +0 -183
- data/doclib/msgpack.rb +0 -87
- data/msgpack.org.md +0 -46
- data/spec/bigint_spec.rb +0 -26
- data/spec/cases.json +0 -1
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +0 -39
- data/spec/cruby/buffer_io_spec.rb +0 -255
- data/spec/cruby/buffer_packer.rb +0 -29
- data/spec/cruby/buffer_spec.rb +0 -575
- data/spec/cruby/buffer_unpacker.rb +0 -19
- data/spec/cruby/unpacker_spec.rb +0 -70
- data/spec/ext_value_spec.rb +0 -99
- data/spec/exttypes.rb +0 -51
- data/spec/factory_spec.rb +0 -688
- data/spec/format_spec.rb +0 -301
- data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
- data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
- data/spec/jruby/unpacker_spec.rb +0 -186
- data/spec/msgpack_spec.rb +0 -214
- data/spec/pack_spec.rb +0 -61
- data/spec/packer_spec.rb +0 -575
- data/spec/random_compat.rb +0 -24
- data/spec/spec_helper.rb +0 -71
- data/spec/timestamp_spec.rb +0 -159
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -859
data/spec/msgpack_spec.rb
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
def utf8enc(str)
|
6
|
-
str.encode('UTF-8')
|
7
|
-
end
|
8
|
-
|
9
|
-
def asciienc(str)
|
10
|
-
str.encode('ASCII-8BIT')
|
11
|
-
end
|
12
|
-
|
13
|
-
describe MessagePack do
|
14
|
-
tests = {
|
15
|
-
'constant values' => [
|
16
|
-
['true', true, "\xC3"],
|
17
|
-
['false', false, "\xC2"],
|
18
|
-
['nil', nil, "\xC0"]
|
19
|
-
],
|
20
|
-
'numbers' => [
|
21
|
-
['zero', 0, "\x00"],
|
22
|
-
['127', 127, "\x7F"],
|
23
|
-
['128', 128, "\xCC\x80"],
|
24
|
-
['256', 256, "\xCD\x01\x00"],
|
25
|
-
['-1', -1, "\xFF"],
|
26
|
-
['-33', -33, "\xD0\xDF"],
|
27
|
-
['-129', -129, "\xD1\xFF\x7F"],
|
28
|
-
['small integers', 42, "*"],
|
29
|
-
['medium integers', 333, "\xCD\x01M"],
|
30
|
-
['large integers', 2**31 - 1, "\xCE\x7F\xFF\xFF\xFF"],
|
31
|
-
['huge integers', 2**64 - 1, "\xCF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"],
|
32
|
-
['negative integers', -1, "\xFF"],
|
33
|
-
['1.0', 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"],
|
34
|
-
['small floats', 3.14, "\xCB@\t\x1E\xB8Q\xEB\x85\x1F"],
|
35
|
-
['big floats', Math::PI * 1_000_000_000_000_000_000, "\xCBC\xC5\xCC\x96\xEF\xD1\x19%"],
|
36
|
-
['negative floats', -2.1, "\xCB\xC0\x00\xCC\xCC\xCC\xCC\xCC\xCD"]
|
37
|
-
],
|
38
|
-
'strings' => [
|
39
|
-
['tiny strings', utf8enc('hello world'), "\xABhello world"],
|
40
|
-
['short strings', utf8enc('hello' * 5), "\xB9hellohellohellohellohello"],
|
41
|
-
['empty strings', utf8enc(''), "\xA0"]
|
42
|
-
],
|
43
|
-
'binary strings' => [
|
44
|
-
['tiny strings', asciienc('hello world'), "\xC4\vhello world"],
|
45
|
-
['short strings', asciienc('hello' * 5), "\xC4\x19hellohellohellohellohello"],
|
46
|
-
['empty strings', asciienc(''), "\xC4\x00"]
|
47
|
-
],
|
48
|
-
'arrays' => [
|
49
|
-
['empty arrays', [], "\x90"],
|
50
|
-
['arrays with strings', [utf8enc("hello"), utf8enc("world")], "\x92\xA5hello\xA5world"],
|
51
|
-
['arrays with mixed values', [utf8enc("hello"), utf8enc("world"), 42], "\x93\xA5hello\xA5world*"],
|
52
|
-
['arrays of arrays', [[[[1, 2], 3], 4]], "\x91\x92\x92\x92\x01\x02\x03\x04"],
|
53
|
-
['empty arrays', [], "\x90"]
|
54
|
-
],
|
55
|
-
'hashes' => [
|
56
|
-
['empty hashes', {}, "\x80"],
|
57
|
-
['hashes', {utf8enc('foo') => utf8enc('bar')}, "\x81\xA3foo\xA3bar"],
|
58
|
-
['hashes with mixed keys and values', {utf8enc('foo') => utf8enc('bar'), 3 => utf8enc('three'), utf8enc('four') => 4, utf8enc('x') => [utf8enc('y')], utf8enc('a') => utf8enc('b')}, "\x85\xA3foo\xA3bar\x03\xA5three\xA4four\x04\xA1x\x91\xA1y\xA1a\xA1b"],
|
59
|
-
['hashes of hashes', {{utf8enc('x') => {utf8enc('y') => utf8enc('z')}} => utf8enc('s')}, "\x81\x81\xA1x\x81\xA1y\xA1z\xA1s"],
|
60
|
-
['hashes with nils', {utf8enc('foo') => nil}, "\x81\xA3foo\xC0"]
|
61
|
-
]
|
62
|
-
}
|
63
|
-
|
64
|
-
tests.each do |ctx, its|
|
65
|
-
context("with #{ctx}") do
|
66
|
-
its.each do |desc, unpacked, packed|
|
67
|
-
it("encodes #{desc}") do
|
68
|
-
MessagePack.pack(unpacked).should == packed
|
69
|
-
end
|
70
|
-
|
71
|
-
it "decodes #{desc}" do
|
72
|
-
MessagePack.unpack(packed).should == unpacked
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'using other names for .pack and .unpack' do
|
79
|
-
it 'can unpack with .load' do
|
80
|
-
MessagePack.load("\xABhello world").should == 'hello world'
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can pack with .dump' do
|
84
|
-
MessagePack.dump(utf8enc('hello world')).should == "\xABhello world"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'with symbols' do
|
89
|
-
it 'encodes symbols as strings' do
|
90
|
-
MessagePack.pack(:symbol).should == "\xA6symbol"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'with different external encoding', :encodings do
|
95
|
-
before do
|
96
|
-
@default_external = Encoding.default_external
|
97
|
-
@default_internal = Encoding.default_internal
|
98
|
-
Encoding.default_external = Encoding::UTF_8
|
99
|
-
Encoding.default_internal = Encoding::ISO_8859_1
|
100
|
-
end
|
101
|
-
|
102
|
-
after do
|
103
|
-
Encoding.default_external = @default_external
|
104
|
-
Encoding.default_internal = @default_internal
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'transcodes strings when encoding' do
|
108
|
-
input = "sk\xE5l".force_encoding(Encoding::ISO_8859_1)
|
109
|
-
MessagePack.pack(input).should == "\xA5sk\xC3\xA5l"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'with other things' do
|
114
|
-
it 'raises an error on #pack with an unsupported type' do
|
115
|
-
expect { MessagePack.pack(self) }.to raise_error(NoMethodError, /^undefined method `to_msgpack'/)
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'raises an error on #unpack with garbage' do
|
119
|
-
skip "but nothing was raised. why?"
|
120
|
-
expect { MessagePack.unpack('asdka;sd') }.to raise_error(MessagePack::UnpackError)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'extensions' do
|
125
|
-
it 'can unpack hashes with symbolized keys' do
|
126
|
-
packed = MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]})
|
127
|
-
unpacked = MessagePack.unpack(packed, :symbolize_keys => true)
|
128
|
-
unpacked.should == {:hello => 'world', :nested => ['object', {:structure => true}]}
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'does not symbolize keys even if other options are present' do
|
132
|
-
packed = MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]})
|
133
|
-
unpacked = MessagePack.unpack(packed, :other_option => false)
|
134
|
-
unpacked.should == {'hello' => 'world', 'nested' => ['object', {'structure' => true}]}
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'can unpack strings with a specified encoding', :encodings do
|
138
|
-
packed = MessagePack.pack({utf8enc('hello') => utf8enc('world')})
|
139
|
-
unpacked = MessagePack.unpack(packed)
|
140
|
-
unpacked['hello'].encoding.should == Encoding::UTF_8
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'can pack strings with a specified encoding', :encodings do
|
144
|
-
packed = MessagePack.pack({'hello' => "w\xE5rld".force_encoding(Encoding::ISO_8859_1)})
|
145
|
-
packed.index("w\xC3\xA5rld").should_not be_nil
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'in compatibility mode' do
|
150
|
-
it 'does not use the bin types' do
|
151
|
-
packed = MessagePack.pack('hello'.force_encoding(Encoding::BINARY), compatibility_mode: true)
|
152
|
-
packed.should eq("\xA5hello")
|
153
|
-
packed = MessagePack.pack(('hello' * 100).force_encoding(Encoding::BINARY), compatibility_mode: true)
|
154
|
-
packed.should start_with("\xDA\x01\xF4")
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'does not use the str8 type' do
|
158
|
-
packed = MessagePack.pack('x' * 32, compatibility_mode: true)
|
159
|
-
packed.should start_with("\xDA\x00\x20")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when a Bignum has a small value' do
|
164
|
-
tests['numbers'].take(10).each do |desc, unpacked, packed|
|
165
|
-
it("encodes #{desc} to the smallest representation") do
|
166
|
-
bignum = (1 << 64).coerce(unpacked)[0]
|
167
|
-
MessagePack.pack(bignum).should eq(packed)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when the source is na IO-like object' do
|
173
|
-
require 'tempfile'
|
174
|
-
require 'stringio'
|
175
|
-
|
176
|
-
it 'work with IO destination object as 2nd argument of MessagePack.pack' do
|
177
|
-
Tempfile.create("pack-test") do |io|
|
178
|
-
return_value = MessagePack.pack(utf8enc('hello world'), io)
|
179
|
-
return_value.should be_nil
|
180
|
-
|
181
|
-
io.rewind
|
182
|
-
io.read.force_encoding(Encoding::ASCII_8BIT).should eq("\xABhello world".force_encoding(Encoding::ASCII_8BIT))
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'work with IO-like StringIO destination object as 2nd argument of MessagePack.pack' do
|
187
|
-
io = StringIO.new
|
188
|
-
return_value = MessagePack.pack(utf8enc('hello world'), io)
|
189
|
-
return_value.should be_nil
|
190
|
-
|
191
|
-
io.rewind
|
192
|
-
io.read.force_encoding(Encoding::ASCII_8BIT).should eq("\xABhello world".force_encoding(Encoding::ASCII_8BIT))
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'work with IO source object as source of MessagePack.unpack' do
|
196
|
-
Tempfile.create("unpack-test") do |io|
|
197
|
-
MessagePack.pack(utf8enc('hello world'), io)
|
198
|
-
io.rewind
|
199
|
-
|
200
|
-
return_value = MessagePack.unpack(io)
|
201
|
-
return_value.should eq(utf8enc('hello world'))
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'work with IO-like StringIO object of MessagePack.unpack' do
|
206
|
-
io = StringIO.new
|
207
|
-
MessagePack.pack(utf8enc('hello world'), io)
|
208
|
-
io.rewind
|
209
|
-
|
210
|
-
return_value = MessagePack.unpack(io)
|
211
|
-
return_value.should eq(utf8enc('hello world'))
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
data/spec/pack_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
if defined?(Encoding)
|
6
|
-
Encoding.default_external = 'ASCII-8BIT'
|
7
|
-
end
|
8
|
-
|
9
|
-
describe MessagePack do
|
10
|
-
it 'to_msgpack returns String' do
|
11
|
-
nil.to_msgpack.class.should == String
|
12
|
-
true.to_msgpack.class.should == String
|
13
|
-
false.to_msgpack.class.should == String
|
14
|
-
1.to_msgpack.class.should == String
|
15
|
-
1.0.to_msgpack.class.should == String
|
16
|
-
"".to_msgpack.class.should == String
|
17
|
-
Hash.new.to_msgpack.class.should == String
|
18
|
-
Array.new.to_msgpack.class.should == String
|
19
|
-
end
|
20
|
-
|
21
|
-
class CustomPack01
|
22
|
-
def to_msgpack(pk=nil)
|
23
|
-
return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer
|
24
|
-
pk.write_array_header(2)
|
25
|
-
pk.write(1)
|
26
|
-
pk.write(2)
|
27
|
-
return pk
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class CustomPack02
|
32
|
-
def to_msgpack(pk=nil)
|
33
|
-
[1,2].to_msgpack(pk)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'calls custom to_msgpack method' do
|
38
|
-
MessagePack.pack(CustomPack01.new).should == [1,2].to_msgpack
|
39
|
-
MessagePack.pack(CustomPack02.new).should == [1,2].to_msgpack
|
40
|
-
CustomPack01.new.to_msgpack.should == [1,2].to_msgpack
|
41
|
-
CustomPack02.new.to_msgpack.should == [1,2].to_msgpack
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'calls custom to_msgpack method with io' do
|
45
|
-
s01 = StringIO.new
|
46
|
-
MessagePack.pack(CustomPack01.new, s01)
|
47
|
-
s01.string.should == [1,2].to_msgpack
|
48
|
-
|
49
|
-
s02 = StringIO.new
|
50
|
-
MessagePack.pack(CustomPack02.new, s02)
|
51
|
-
s02.string.should == [1,2].to_msgpack
|
52
|
-
|
53
|
-
s03 = StringIO.new
|
54
|
-
CustomPack01.new.to_msgpack(s03)
|
55
|
-
s03.string.should == [1,2].to_msgpack
|
56
|
-
|
57
|
-
s04 = StringIO.new
|
58
|
-
CustomPack02.new.to_msgpack(s04)
|
59
|
-
s04.string.should == [1,2].to_msgpack
|
60
|
-
end
|
61
|
-
end
|