msgpack 1.5.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +55 -0
  3. data/README.md +30 -1
  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 +54 -69
  11. data/ext/msgpack/buffer.h +16 -18
  12. data/ext/msgpack/buffer_class.c +138 -37
  13. data/ext/msgpack/buffer_class.h +1 -0
  14. data/ext/msgpack/compat.h +0 -99
  15. data/ext/msgpack/extconf.rb +25 -39
  16. data/ext/msgpack/factory_class.c +75 -86
  17. data/ext/msgpack/packer.c +12 -39
  18. data/ext/msgpack/packer.h +1 -11
  19. data/ext/msgpack/packer_class.c +73 -99
  20. data/ext/msgpack/packer_class.h +11 -0
  21. data/ext/msgpack/packer_ext_registry.c +31 -28
  22. data/ext/msgpack/packer_ext_registry.h +10 -14
  23. data/ext/msgpack/rbinit.c +1 -1
  24. data/ext/msgpack/rmem.c +3 -4
  25. data/ext/msgpack/sysdep.h +5 -2
  26. data/ext/msgpack/unpacker.c +66 -94
  27. data/ext/msgpack/unpacker.h +13 -12
  28. data/ext/msgpack/unpacker_class.c +64 -80
  29. data/ext/msgpack/unpacker_class.h +11 -0
  30. data/ext/msgpack/unpacker_ext_registry.c +4 -16
  31. data/ext/msgpack/unpacker_ext_registry.h +3 -7
  32. data/lib/msgpack/buffer.rb +9 -0
  33. data/lib/msgpack/factory.rb +90 -63
  34. data/lib/msgpack/packer.rb +10 -1
  35. data/lib/msgpack/unpacker.rb +14 -1
  36. data/lib/msgpack/version.rb +1 -1
  37. data/lib/msgpack.rb +1 -0
  38. data/msgpack.gemspec +7 -3
  39. metadata +33 -56
  40. data/.github/workflows/ci.yaml +0 -57
  41. data/.gitignore +0 -23
  42. data/.rubocop.yml +0 -36
  43. data/Gemfile +0 -9
  44. data/Rakefile +0 -70
  45. data/appveyor.yml +0 -18
  46. data/bench/pack.rb +0 -23
  47. data/bench/pack_log.rb +0 -33
  48. data/bench/pack_log_long.rb +0 -65
  49. data/bench/pack_symbols.rb +0 -28
  50. data/bench/run.sh +0 -14
  51. data/bench/run_long.sh +0 -35
  52. data/bench/run_symbols.sh +0 -26
  53. data/bench/unpack.rb +0 -21
  54. data/bench/unpack_log.rb +0 -34
  55. data/bench/unpack_log_long.rb +0 -67
  56. data/doclib/msgpack/buffer.rb +0 -193
  57. data/doclib/msgpack/core_ext.rb +0 -101
  58. data/doclib/msgpack/error.rb +0 -19
  59. data/doclib/msgpack/extension_value.rb +0 -9
  60. data/doclib/msgpack/factory.rb +0 -145
  61. data/doclib/msgpack/packer.rb +0 -209
  62. data/doclib/msgpack/time.rb +0 -22
  63. data/doclib/msgpack/timestamp.rb +0 -44
  64. data/doclib/msgpack/unpacker.rb +0 -183
  65. data/doclib/msgpack.rb +0 -87
  66. data/msgpack.org.md +0 -46
  67. data/spec/bigint_spec.rb +0 -26
  68. data/spec/cases.json +0 -1
  69. data/spec/cases.msg +0 -0
  70. data/spec/cases_compact.msg +0 -0
  71. data/spec/cases_spec.rb +0 -39
  72. data/spec/cruby/buffer_io_spec.rb +0 -255
  73. data/spec/cruby/buffer_packer.rb +0 -29
  74. data/spec/cruby/buffer_spec.rb +0 -575
  75. data/spec/cruby/buffer_unpacker.rb +0 -19
  76. data/spec/cruby/unpacker_spec.rb +0 -70
  77. data/spec/ext_value_spec.rb +0 -99
  78. data/spec/exttypes.rb +0 -51
  79. data/spec/factory_spec.rb +0 -654
  80. data/spec/format_spec.rb +0 -301
  81. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  82. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  83. data/spec/jruby/unpacker_spec.rb +0 -186
  84. data/spec/msgpack_spec.rb +0 -214
  85. data/spec/pack_spec.rb +0 -61
  86. data/spec/packer_spec.rb +0 -575
  87. data/spec/random_compat.rb +0 -24
  88. data/spec/spec_helper.rb +0 -65
  89. data/spec/timestamp_spec.rb +0 -159
  90. data/spec/unpack_spec.rb +0 -57
  91. data/spec/unpacker_spec.rb +0 -847
@@ -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 # JRuby cannot handle numerics larger than long
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 # JRuby cannot handle numerics larger than long
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