msgpack 0.7.6-java → 1.0.0-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328bb22c49965edc3b1c0c4e8562fa66b02d7bb2
4
- data.tar.gz: 42e1a0da7bdc9a66c9d4eda2f26f61a9ded7b367
3
+ metadata.gz: 562692a376709457f14a581c27339a94e4221279
4
+ data.tar.gz: 81353eb21eecadd00f74f535ec2463184d296c31
5
5
  SHA512:
6
- metadata.gz: 4cd07afd9abf94e766e2ccde4f1c9c04558f43dfc21f861d8ea8ac7728f0d7b43a4c98788a155a682cc60dd8cba8a16d1c7751d7fa4a0804812c87049c7d0478
7
- data.tar.gz: 0f829b229202a72cebb98deb41d050bfc7e88494a968f2b4cf37edb47e65eea06cb61a73a4dab566892a48ce946050866c3cbf3942468b122326722fbbe53984
6
+ metadata.gz: 0da9c7a1cb5c02e31eff7d5f15652ae13a57991a19380d92d5b75172446abe3de7816e699498f8dce8c53289a789e5e51f73f3a1251666330b364d5ea278dcfe
7
+ data.tar.gz: 06017bbfb8da463004c839791b68d0cd246435af15ad7d1edba431d2956b332d8040f9d7d9c1c7b88b31d97c91b93622c38a0dfd85069da0a719a350ba85c408
@@ -15,3 +15,4 @@ end
15
15
  require "msgpack/packer"
16
16
  require "msgpack/unpacker"
17
17
  require "msgpack/factory"
18
+ require "msgpack/symbol"
Binary file
@@ -0,0 +1,9 @@
1
+ class Symbol
2
+ def to_msgpack_ext
3
+ [to_s].pack('A*')
4
+ end
5
+
6
+ def self.from_msgpack_ext(data)
7
+ data.unpack('A*').first.to_sym
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.7.6"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -210,6 +210,66 @@ describe MessagePack::Factory do
210
210
  end
211
211
  end
212
212
 
213
+ describe 'the special treatment of symbols with ext type' do
214
+ let(:packer) { subject.packer }
215
+ let(:unpacker) { subject.unpacker }
216
+
217
+ def symbol_after_roundtrip
218
+ packed_symbol = packer.pack(:symbol).to_s
219
+ unpacker.feed(packed_symbol).unpack
220
+ end
221
+
222
+ context 'if no ext type is registered for symbols' do
223
+ it 'converts symbols to string' do
224
+ expect(symbol_after_roundtrip).to eq 'symbol'
225
+ end
226
+ end
227
+
228
+ context 'if an ext type is registered for symbols' do
229
+ context 'if using the default serializer' do
230
+ before { subject.register_type(0x00, ::Symbol) }
231
+
232
+ it 'lets symbols survive a roundtrip' do
233
+ expect(symbol_after_roundtrip).to be :symbol
234
+ end
235
+ end
236
+
237
+ context 'if using a custom serializer' do
238
+ before do
239
+ class Symbol
240
+ alias_method :to_msgpack_ext_orig, :to_msgpack_ext
241
+ def to_msgpack_ext
242
+ self.to_s.codepoints.to_a.pack('n*')
243
+ end
244
+ end
245
+
246
+ class << Symbol
247
+ alias_method :from_msgpack_ext_orig, :from_msgpack_ext
248
+ def from_msgpack_ext(data)
249
+ data.unpack('n*').map(&:chr).join.to_sym
250
+ end
251
+ end
252
+ end
253
+
254
+ before { subject.register_type(0x00, ::Symbol) }
255
+
256
+ it 'lets symbols survive a roundtrip' do
257
+ expect(symbol_after_roundtrip).to be :symbol
258
+ end
259
+
260
+ after do
261
+ class Symbol
262
+ alias_method :to_msgpack_ext, :to_msgpack_ext_orig
263
+ end
264
+
265
+ class << Symbol
266
+ alias_method :from_msgpack_ext, :from_msgpack_ext_orig
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
272
+
213
273
  describe 'DefaultFactory' do
214
274
  it 'is a factory' do
215
275
  MessagePack::DefaultFactory.should be_kind_of(MessagePack::Factory)
@@ -323,6 +323,42 @@ describe MessagePack::Packer do
323
323
  expect(two[:class]).to eq(ValueTwo)
324
324
  expect(two[:packer]).to eq(:to_msgpack_ext)
325
325
  end
326
+
327
+ context 'when registering a type for symbols' do
328
+ before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) }
329
+
330
+ it 'packs symbols in an ext type' do
331
+ expect(packer.pack(:symbol).to_s).to eq "\xc7\x06\x00symbol"
332
+ end
333
+ end
334
+ end
335
+
336
+ describe "fixnum and bignum" do
337
+ it "fixnum.to_msgpack" do
338
+ 23.to_msgpack.should == "\x17"
339
+ end
340
+
341
+ it "fixnum.to_msgpack(packer)" do
342
+ 23.to_msgpack(packer)
343
+ packer.to_s.should == "\x17"
344
+ end
345
+
346
+ it "bignum.to_msgpack" do
347
+ -4294967296.to_msgpack.should == "\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00"
348
+ end
349
+
350
+ it "bignum.to_msgpack(packer)" do
351
+ -4294967296.to_msgpack(packer)
352
+ packer.to_s.should == "\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00"
353
+ end
354
+
355
+ it "unpack(fixnum)" do
356
+ MessagePack.unpack("\x17").should == 23
357
+ end
358
+
359
+ it "unpack(bignum)" do
360
+ MessagePack.unpack("\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00").should == -4294967296
361
+ end
326
362
  end
327
363
 
328
364
  describe "ext formats" 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: 0.7.6
4
+ version: 1.0.0
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: 2016-05-10 00:00:00.000000000 Z
13
+ date: 2016-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,7 @@ files:
109
109
  - lib/msgpack/factory.rb
110
110
  - lib/msgpack/msgpack.jar
111
111
  - lib/msgpack/packer.rb
112
+ - lib/msgpack/symbol.rb
112
113
  - lib/msgpack/unpacker.rb
113
114
  - lib/msgpack/version.rb
114
115
  - spec/cases.json