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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +50 -0
  3. data/README.md +48 -12
  4. data/ext/java/org/msgpack/jruby/Buffer.java +3 -3
  5. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +11 -20
  6. data/ext/java/org/msgpack/jruby/ExtensionValue.java +1 -1
  7. data/ext/java/org/msgpack/jruby/Factory.java +11 -50
  8. data/ext/java/org/msgpack/jruby/Packer.java +9 -24
  9. data/ext/java/org/msgpack/jruby/Unpacker.java +15 -32
  10. data/ext/msgpack/buffer.c +69 -56
  11. data/ext/msgpack/buffer.h +138 -44
  12. data/ext/msgpack/buffer_class.c +132 -31
  13. data/ext/msgpack/buffer_class.h +1 -0
  14. data/ext/msgpack/extconf.rb +20 -30
  15. data/ext/msgpack/factory_class.c +75 -86
  16. data/ext/msgpack/packer.c +13 -16
  17. data/ext/msgpack/packer.h +24 -21
  18. data/ext/msgpack/packer_class.c +72 -98
  19. data/ext/msgpack/packer_class.h +11 -0
  20. data/ext/msgpack/packer_ext_registry.c +31 -28
  21. data/ext/msgpack/packer_ext_registry.h +10 -14
  22. data/ext/msgpack/rbinit.c +1 -1
  23. data/ext/msgpack/rmem.c +3 -4
  24. data/ext/msgpack/sysdep.h +5 -2
  25. data/ext/msgpack/unpacker.c +201 -113
  26. data/ext/msgpack/unpacker.h +22 -15
  27. data/ext/msgpack/unpacker_class.c +87 -92
  28. data/ext/msgpack/unpacker_class.h +11 -0
  29. data/ext/msgpack/unpacker_ext_registry.c +4 -16
  30. data/ext/msgpack/unpacker_ext_registry.h +3 -7
  31. data/lib/msgpack/buffer.rb +9 -0
  32. data/lib/msgpack/factory.rb +90 -63
  33. data/lib/msgpack/packer.rb +10 -1
  34. data/lib/msgpack/unpacker.rb +14 -1
  35. data/lib/msgpack/version.rb +1 -1
  36. data/lib/msgpack.rb +1 -0
  37. data/msgpack.gemspec +8 -3
  38. metadata +21 -51
  39. data/.github/workflows/ci.yaml +0 -57
  40. data/.gitignore +0 -23
  41. data/.rubocop.yml +0 -36
  42. data/Gemfile +0 -9
  43. data/Rakefile +0 -70
  44. data/appveyor.yml +0 -18
  45. data/bench/bench.rb +0 -78
  46. data/doclib/msgpack/buffer.rb +0 -193
  47. data/doclib/msgpack/core_ext.rb +0 -101
  48. data/doclib/msgpack/error.rb +0 -19
  49. data/doclib/msgpack/extension_value.rb +0 -9
  50. data/doclib/msgpack/factory.rb +0 -145
  51. data/doclib/msgpack/packer.rb +0 -209
  52. data/doclib/msgpack/time.rb +0 -22
  53. data/doclib/msgpack/timestamp.rb +0 -44
  54. data/doclib/msgpack/unpacker.rb +0 -183
  55. data/doclib/msgpack.rb +0 -87
  56. data/msgpack.org.md +0 -46
  57. data/spec/bigint_spec.rb +0 -26
  58. data/spec/cases.json +0 -1
  59. data/spec/cases.msg +0 -0
  60. data/spec/cases_compact.msg +0 -0
  61. data/spec/cases_spec.rb +0 -39
  62. data/spec/cruby/buffer_io_spec.rb +0 -255
  63. data/spec/cruby/buffer_packer.rb +0 -29
  64. data/spec/cruby/buffer_spec.rb +0 -575
  65. data/spec/cruby/buffer_unpacker.rb +0 -19
  66. data/spec/cruby/unpacker_spec.rb +0 -70
  67. data/spec/ext_value_spec.rb +0 -99
  68. data/spec/exttypes.rb +0 -51
  69. data/spec/factory_spec.rb +0 -688
  70. data/spec/format_spec.rb +0 -301
  71. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  72. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  73. data/spec/jruby/unpacker_spec.rb +0 -186
  74. data/spec/msgpack_spec.rb +0 -214
  75. data/spec/pack_spec.rb +0 -61
  76. data/spec/packer_spec.rb +0 -575
  77. data/spec/random_compat.rb +0 -24
  78. data/spec/spec_helper.rb +0 -71
  79. data/spec/timestamp_spec.rb +0 -159
  80. data/spec/unpack_spec.rb +0 -57
  81. data/spec/unpacker_spec.rb +0 -859
@@ -1,159 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe MessagePack::Timestamp do
6
- describe 'malformed format' do
7
- it do
8
- expect do
9
- MessagePack::Timestamp.from_msgpack_ext([0xd4, 0x00].pack("C*"))
10
- end.to raise_error(MessagePack::MalformedFormatError)
11
- end
12
- end
13
-
14
- describe 'register_type with Time' do
15
- let(:factory) do
16
- factory = MessagePack::Factory.new
17
- factory.register_type(
18
- MessagePack::Timestamp::TYPE,
19
- Time,
20
- packer: MessagePack::Time::Packer,
21
- unpacker: MessagePack::Time::Unpacker
22
- )
23
- factory
24
- end
25
-
26
- let(:time) { Time.local(2019, 6, 17, 1, 2, 3, 123_456_789 / 1000.0) }
27
- it 'serializes and deserializes Time' do
28
- prefix_fixext8_with_type_id = [0xd7, -1].pack("c*")
29
-
30
- packed = factory.pack(time)
31
- expect(packed).to start_with(prefix_fixext8_with_type_id)
32
- expect(packed.size).to eq(10)
33
- unpacked = factory.unpack(packed)
34
- expect(unpacked.to_i).to eq(time.to_i)
35
- expect(unpacked.to_f).to eq(time.to_f)
36
- # expect(unpacked).to eq(time) # we can't do it because of nsec (rational vs float?)
37
- end
38
-
39
- let(:time_without_nsec) { Time.local(2019, 6, 17, 1, 2, 3, 0) }
40
- it 'serializes time without nanosec as fixext4' do
41
- prefix_fixext4_with_type_id = [0xd6, -1].pack("c*")
42
-
43
- packed = factory.pack(time_without_nsec)
44
- expect(packed).to start_with(prefix_fixext4_with_type_id)
45
- expect(packed.size).to eq(6)
46
- unpacked = factory.unpack(packed)
47
- expect(unpacked).to eq(time_without_nsec)
48
- end
49
-
50
- let(:time_after_2514) { Time.at(1 << 34) } # the max num of 34bit int means 2514-05-30 01:53:04 UTC
51
- it 'serializes time after 2038 as ext8' do
52
- prefix_ext8_with_12bytes_payload_and_type_id = [0xc7, 12, -1].pack("c*")
53
-
54
- expect(time_after_2514.to_i).to be > 0xffffffff
55
- packed = factory.pack(time_after_2514)
56
- expect(packed).to start_with(prefix_ext8_with_12bytes_payload_and_type_id)
57
- expect(packed.size).to eq(15)
58
- end
59
-
60
- it 'runs correctly (regression)' do
61
- expect(factory.unpack(factory.pack(Time.utc(2200)))).to eq(Time.utc(2200))
62
- end
63
-
64
- let(:time32_max) { Time.new(2106, 2, 7, 6, 28, 15, "+00:00") }
65
- it 'is serialized into timestamp32' do
66
- expect(factory.pack(time32_max).size).to be 6
67
- expect(factory.unpack(factory.pack(time32_max)).utc).to eq(time32_max)
68
- end
69
-
70
- let(:time64_min) { Time.new(2106, 2, 7, 6, 28, 16, "+00:00") }
71
- it 'is serialized into timestamp64' do
72
- expect(factory.pack(time64_min).size).to be 10
73
- expect(factory.unpack(factory.pack(time64_min)).utc).to eq(time64_min)
74
- end
75
-
76
- 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
77
- it 'is serialized into timestamp64' do
78
- expect(factory.pack(time64_max).size).to be 10
79
- expect(factory.unpack(factory.pack(time64_max)).utc).to eq(time64_max)
80
- end
81
-
82
- let(:time96_positive_min) { Time.new(2514, 5, 30, 1, 53, 4, "+00:00") }
83
- it 'is serialized into timestamp96' do
84
- expect(factory.pack(time96_positive_min).size).to be 15
85
- expect(factory.unpack(factory.pack(time96_positive_min)).utc).to eq(time96_positive_min)
86
- end
87
-
88
- let(:time96_min) { Time.at(-2**63).utc }
89
- it 'is serialized into timestamp96' do
90
- skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion
91
- expect(factory.pack(time96_min).size).to be 15
92
- expect(factory.unpack(factory.pack(time96_min)).utc).to eq(time96_min)
93
- end
94
-
95
- let(:time96_max) { Time.at(2**63 - 1).utc }
96
- it 'is serialized into timestamp96' do
97
- skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion
98
- expect(factory.pack(time96_max).size).to be 15
99
- expect(factory.unpack(factory.pack(time96_max)).utc).to eq(time96_max)
100
- end
101
- end
102
-
103
- describe 'register_type with MessagePack::Timestamp' do
104
- let(:factory) do
105
- factory = MessagePack::Factory.new
106
- factory.register_type(MessagePack::Timestamp::TYPE, MessagePack::Timestamp)
107
- factory
108
- end
109
-
110
- let(:timestamp) { MessagePack::Timestamp.new(Time.now.tv_sec, 123_456_789) }
111
- it 'serializes and deserializes MessagePack::Timestamp' do
112
- packed = factory.pack(timestamp)
113
- unpacked = factory.unpack(packed)
114
- expect(unpacked).to eq(timestamp)
115
- end
116
- end
117
-
118
- describe 'timestamp32' do
119
- it 'handles [1, 0]' do
120
- t = MessagePack::Timestamp.new(1, 0)
121
-
122
- payload = t.to_msgpack_ext
123
- unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
124
-
125
- expect(unpacked).to eq(t)
126
- end
127
- end
128
-
129
- describe 'timestamp64' do
130
- it 'handles [1, 1]' do
131
- t = MessagePack::Timestamp.new(1, 1)
132
-
133
- payload = t.to_msgpack_ext
134
- unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
135
-
136
- expect(unpacked).to eq(t)
137
- end
138
- end
139
-
140
- describe 'timestamp96' do
141
- it 'handles [-1, 0]' do
142
- t = MessagePack::Timestamp.new(-1, 0)
143
-
144
- payload = t.to_msgpack_ext
145
- unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
146
-
147
- expect(unpacked).to eq(t)
148
- end
149
-
150
- it 'handles [-1, 999_999_999]' do
151
- t = MessagePack::Timestamp.new(-1, 999_999_999)
152
-
153
- payload = t.to_msgpack_ext
154
- unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
155
-
156
- expect(unpacked).to eq(t)
157
- end
158
- end
159
- end
data/spec/unpack_spec.rb DELETED
@@ -1,57 +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 'MessagePack.unpack symbolize_keys' do
11
- symbolized_hash = {:a => 'b', :c => 'd'}
12
- MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
13
- MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
14
- end
15
-
16
- it 'Unpacker#read symbolize_keys' do
17
- unpacker = MessagePack::Unpacker.new(:symbolize_keys => true)
18
- symbolized_hash = {:a => 'b', :c => 'd'}
19
- unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
20
- end
21
-
22
- it "msgpack str 8 type" do
23
- MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
24
- MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
25
- MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
26
- end
27
-
28
- it "msgpack str 16 type" do
29
- MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
30
- MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
31
- MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
32
- end
33
-
34
- it "msgpack str 32 type" do
35
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
36
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
37
- MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
38
- end
39
-
40
- it "msgpack bin 8 type" do
41
- MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
42
- MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
43
- MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
44
- end
45
-
46
- it "msgpack bin 16 type" do
47
- MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
48
- MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
49
- MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
50
- end
51
-
52
- it "msgpack bin 32 type" do
53
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
54
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
55
- MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
56
- end
57
- end