msgpack 1.2.9 → 1.4.4

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yaml +56 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop.yml +4 -1
  5. data/ChangeLog +46 -0
  6. data/Gemfile +3 -0
  7. data/README.md +242 -0
  8. data/Rakefile +1 -9
  9. data/doclib/msgpack/factory.rb +1 -0
  10. data/doclib/msgpack/time.rb +22 -0
  11. data/doclib/msgpack/timestamp.rb +44 -0
  12. data/ext/java/org/msgpack/jruby/Buffer.java +17 -16
  13. data/ext/java/org/msgpack/jruby/Decoder.java +29 -10
  14. data/ext/java/org/msgpack/jruby/Encoder.java +22 -12
  15. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +9 -9
  16. data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
  17. data/ext/java/org/msgpack/jruby/Factory.java +7 -2
  18. data/ext/java/org/msgpack/jruby/Packer.java +11 -9
  19. data/ext/java/org/msgpack/jruby/Unpacker.java +40 -27
  20. data/ext/msgpack/buffer.c +4 -16
  21. data/ext/msgpack/buffer.h +60 -5
  22. data/ext/msgpack/compat.h +1 -12
  23. data/ext/msgpack/extconf.rb +39 -7
  24. data/ext/msgpack/factory_class.c +10 -5
  25. data/ext/msgpack/packer.c +18 -5
  26. data/ext/msgpack/packer.h +0 -16
  27. data/ext/msgpack/packer_class.c +0 -9
  28. data/ext/msgpack/packer_ext_registry.c +0 -22
  29. data/ext/msgpack/unpacker.c +41 -49
  30. data/ext/msgpack/unpacker.h +8 -0
  31. data/ext/msgpack/unpacker_class.c +23 -13
  32. data/lib/msgpack/symbol.rb +14 -4
  33. data/lib/msgpack/time.rb +29 -0
  34. data/lib/msgpack/timestamp.rb +76 -0
  35. data/lib/msgpack/version.rb +4 -7
  36. data/lib/msgpack.rb +5 -8
  37. data/msgpack.gemspec +3 -7
  38. data/spec/factory_spec.rb +17 -0
  39. data/spec/msgpack_spec.rb +1 -1
  40. data/spec/packer_spec.rb +18 -0
  41. data/spec/spec_helper.rb +27 -0
  42. data/spec/timestamp_spec.rb +161 -0
  43. data/spec/unpacker_spec.rb +113 -1
  44. metadata +19 -51
  45. data/.travis.yml +0 -41
  46. data/README.rdoc +0 -209
@@ -18,13 +18,35 @@ describe MessagePack::Unpacker do
18
18
  it 'gets options to specify how to unpack values' do
19
19
  u1 = MessagePack::Unpacker.new
20
20
  u1.symbolize_keys?.should == false
21
+ u1.freeze?.should == false
21
22
  u1.allow_unknown_ext?.should == false
22
23
 
23
- u2 = MessagePack::Unpacker.new(symbolize_keys: true, allow_unknown_ext: true)
24
+ u2 = MessagePack::Unpacker.new(symbolize_keys: true, freeze: true, allow_unknown_ext: true)
24
25
  u2.symbolize_keys?.should == true
26
+ u2.freeze?.should == true
25
27
  u2.allow_unknown_ext?.should == true
26
28
  end
27
29
 
30
+ if automatic_string_keys_deduplication?
31
+ it 'ensure string hash keys are deduplicated' do
32
+ sample_data = [{"foo" => 1}, {"foo" => 2}]
33
+ sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
34
+ unpacker.feed(sample_packed)
35
+ hashes = nil
36
+ unpacker.each { |obj| hashes = obj }
37
+ expect(hashes[0].keys.first).to equal(hashes[1].keys.first)
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
48
+ end
49
+
28
50
  it 'gets IO or object which has #read to read data from it' do
29
51
  sample_data = {"message" => "morning!", "num" => 1}
30
52
  sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
@@ -621,6 +643,14 @@ describe MessagePack::Unpacker do
621
643
  array = ['foo'] * 10_000
622
644
  MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000
623
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
624
654
  end
625
655
 
626
656
  context 'extensions' do
@@ -651,6 +681,88 @@ describe MessagePack::Unpacker do
651
681
  end
652
682
  end
653
683
 
684
+ context 'freeze' do
685
+ let :struct do
686
+ {'hello' => 'world', 'nested' => ['object', {'structure' => true}]}
687
+ end
688
+
689
+ let :buffer do
690
+ MessagePack.pack(struct)
691
+ end
692
+
693
+ let :unpacker do
694
+ described_class.new(:freeze => true)
695
+ end
696
+
697
+ it 'can freeze objects when using .unpack' do
698
+ parsed_struct = MessagePack.unpack(buffer, freeze: true)
699
+ parsed_struct.should == struct
700
+
701
+ parsed_struct.should be_frozen
702
+ parsed_struct['hello'].should be_frozen
703
+ parsed_struct['nested'].should be_frozen
704
+ parsed_struct['nested'][0].should be_frozen
705
+ parsed_struct['nested'][1].should be_frozen
706
+
707
+ if string_deduplication?
708
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
709
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
710
+ parsed_struct.values[0].should be_equal('world'.freeze)
711
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
712
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
713
+ end
714
+ end
715
+
716
+ it 'can freeze objects when using #each' do
717
+ objs = []
718
+ unpacker.feed(buffer)
719
+ unpacker.each do |obj|
720
+ objs << obj
721
+ end
722
+
723
+ parsed_struct = objs.first
724
+ parsed_struct.should == struct
725
+
726
+ parsed_struct.should be_frozen
727
+ parsed_struct['hello'].should be_frozen
728
+ parsed_struct['nested'].should be_frozen
729
+ parsed_struct['nested'][0].should be_frozen
730
+ parsed_struct['nested'][1].should be_frozen
731
+
732
+ if string_deduplication?
733
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
734
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
735
+ parsed_struct.values[0].should be_equal('world'.freeze)
736
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
737
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
738
+ end
739
+ end
740
+
741
+ it 'can freeze objects when using #feed_each' do
742
+ objs = []
743
+ unpacker.feed_each(buffer) do |obj|
744
+ objs << obj
745
+ end
746
+
747
+ parsed_struct = objs.first
748
+ parsed_struct.should == struct
749
+
750
+ parsed_struct.should be_frozen
751
+ parsed_struct['hello'].should be_frozen
752
+ parsed_struct['nested'].should be_frozen
753
+ parsed_struct['nested'][0].should be_frozen
754
+ parsed_struct['nested'][1].should be_frozen
755
+
756
+ if string_deduplication?
757
+ parsed_struct.keys[0].should be_equal('hello'.freeze)
758
+ parsed_struct.keys[1].should be_equal('nested'.freeze)
759
+ parsed_struct.values[0].should be_equal('world'.freeze)
760
+ parsed_struct.values[1][0].should be_equal('object'.freeze)
761
+ parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze)
762
+ end
763
+ end
764
+ end
765
+
654
766
  context 'binary encoding', :encodings do
655
767
  let :buffer do
656
768
  MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]})
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  - Theo Hultberg
9
9
  - Satoshi Tagomori
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-03-13 00:00:00.000000000 Z
13
+ date: 2022-01-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -44,30 +44,16 @@ dependencies:
44
44
  name: rake-compiler
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1.0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '1.0'
57
- - !ruby/object:Gem::Dependency
58
- name: rake-compiler-dock
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
47
+ - - ">="
62
48
  - !ruby/object:Gem::Version
63
- version: 0.7.0
49
+ version: 1.1.9
64
50
  type: :development
65
51
  prerelease: false
66
52
  version_requirements: !ruby/object:Gem::Requirement
67
53
  requirements:
68
- - - "~>"
54
+ - - ">="
69
55
  - !ruby/object:Gem::Version
70
- version: 0.7.0
56
+ version: 1.1.9
71
57
  - !ruby/object:Gem::Dependency
72
58
  name: rspec
73
59
  requirement: !ruby/object:Gem::Requirement
@@ -122,13 +108,13 @@ extensions:
122
108
  - ext/msgpack/extconf.rb
123
109
  extra_rdoc_files: []
124
110
  files:
111
+ - ".github/workflows/ci.yaml"
125
112
  - ".gitignore"
126
113
  - ".rubocop.yml"
127
- - ".travis.yml"
128
114
  - ChangeLog
129
115
  - Gemfile
130
116
  - LICENSE
131
- - README.rdoc
117
+ - README.md
132
118
  - Rakefile
133
119
  - appveyor.yml
134
120
  - bench/pack.rb
@@ -148,6 +134,8 @@ files:
148
134
  - doclib/msgpack/extension_value.rb
149
135
  - doclib/msgpack/factory.rb
150
136
  - doclib/msgpack/packer.rb
137
+ - doclib/msgpack/time.rb
138
+ - doclib/msgpack/timestamp.rb
151
139
  - doclib/msgpack/unpacker.rb
152
140
  - ext/java/org/msgpack/jruby/Buffer.java
153
141
  - ext/java/org/msgpack/jruby/Decoder.java
@@ -192,6 +180,8 @@ files:
192
180
  - lib/msgpack/factory.rb
193
181
  - lib/msgpack/packer.rb
194
182
  - lib/msgpack/symbol.rb
183
+ - lib/msgpack/time.rb
184
+ - lib/msgpack/timestamp.rb
195
185
  - lib/msgpack/unpacker.rb
196
186
  - lib/msgpack/version.rb
197
187
  - msgpack.gemspec
@@ -217,13 +207,14 @@ files:
217
207
  - spec/packer_spec.rb
218
208
  - spec/random_compat.rb
219
209
  - spec/spec_helper.rb
210
+ - spec/timestamp_spec.rb
220
211
  - spec/unpack_spec.rb
221
212
  - spec/unpacker_spec.rb
222
213
  homepage: http://msgpack.org/
223
214
  licenses:
224
215
  - Apache 2.0
225
216
  metadata: {}
226
- post_install_message:
217
+ post_install_message:
227
218
  rdoc_options: []
228
219
  require_paths:
229
220
  - lib
@@ -231,38 +222,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
222
  requirements:
232
223
  - - ">="
233
224
  - !ruby/object:Gem::Version
234
- version: '0'
225
+ version: '2.4'
235
226
  required_rubygems_version: !ruby/object:Gem::Requirement
236
227
  requirements:
237
228
  - - ">="
238
229
  - !ruby/object:Gem::Version
239
230
  version: '0'
240
231
  requirements: []
241
- rubygems_version: 3.0.1
242
- signing_key:
232
+ rubygems_version: 3.3.3
233
+ signing_key:
243
234
  specification_version: 4
244
235
  summary: MessagePack, a binary-based efficient data interchange format.
245
- test_files:
246
- - spec/cases.json
247
- - spec/cases.msg
248
- - spec/cases_compact.msg
249
- - spec/cases_spec.rb
250
- - spec/cruby/buffer_io_spec.rb
251
- - spec/cruby/buffer_packer.rb
252
- - spec/cruby/buffer_spec.rb
253
- - spec/cruby/buffer_unpacker.rb
254
- - spec/cruby/unpacker_spec.rb
255
- - spec/ext_value_spec.rb
256
- - spec/exttypes.rb
257
- - spec/factory_spec.rb
258
- - spec/format_spec.rb
259
- - spec/jruby/benchmarks/shootout_bm.rb
260
- - spec/jruby/benchmarks/symbolize_keys_bm.rb
261
- - spec/jruby/unpacker_spec.rb
262
- - spec/msgpack_spec.rb
263
- - spec/pack_spec.rb
264
- - spec/packer_spec.rb
265
- - spec/random_compat.rb
266
- - spec/spec_helper.rb
267
- - spec/unpack_spec.rb
268
- - spec/unpacker_spec.rb
236
+ test_files: []
data/.travis.yml DELETED
@@ -1,41 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- branches:
6
- only:
7
- - master
8
-
9
- gemfile:
10
- - Gemfile
11
-
12
- before_install:
13
- # This is only for Ruby 2.5.0, Bundler 1.16.1 and rubygems 2.7.3
14
- # See https://github.com/travis-ci/travis-ci/issues/8969
15
- - "[ \"x2.7.3\" = \"x\"$(gem --version) ] && gem update --system --no-document || echo \"no need to update rubygem\""
16
-
17
- # http://rubies.travis-ci.org/
18
- matrix:
19
- include:
20
- - rvm: 2.3.8
21
- os: linux
22
- - rvm: 2.4.5
23
- os: linux
24
- - rvm: 2.5.3
25
- os: linux
26
- - rvm: 2.6.0
27
- os: linux
28
- - rvm: 2.6.0
29
- os: osx
30
- - rvm: ruby-head
31
- os: linux
32
- - rvm: jruby-9.1.9.0
33
- os: linux
34
- - rvm: jruby-head
35
- os: linux
36
- - rvm: jruby-19mode
37
- os: linux
38
- allow_failures:
39
- - rvm: ruby-head
40
- - rvm: jruby-head
41
- - rvm: jruby-19mode
data/README.rdoc DELETED
@@ -1,209 +0,0 @@
1
-
2
- = MessagePack
3
-
4
- MessagePack[http://msgpack.org] is an efficient binary serialization format.
5
- It lets you exchange data among multiple languages like JSON but it's faster and smaller.
6
- For example, small integers (like flags or error code) are encoded into a single byte,
7
- and typical short strings only require an extra byte in addition to the strings themselves.
8
-
9
- If you ever wished to use JSON for convenience (storing an image with metadata) but could
10
- not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.
11
-
12
- require 'msgpack'
13
- msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
14
- MessagePack.unpack(msg) #=> [1,2,3]
15
-
16
- Use RubyGems to install:
17
-
18
- gem install msgpack
19
-
20
- or build msgpack-ruby and install:
21
-
22
- bundle
23
- rake
24
- gem install --local pkg/msgpack
25
-
26
-
27
- = Use cases
28
-
29
- * Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl)
30
- * Store objects efficiently serialized by msgpack on memcached or Redis
31
- * In fact Redis supports msgpack in EVAL-scripts[http://redis.io/commands/eval]
32
- * Upload data in efficient format from mobile devices such as smartphones
33
- * MessagePack works on iPhone/iPad and Android. See also Objective-C[https://github.com/msgpack/msgpack-objectivec] and Java[https://github.com/msgpack/msgpack-java] implementations
34
- * Design a portable protocol to communicate with embedded devices
35
- * Check also Fluentd[http://fluentd.org/] which is a log collector which uses msgpack for the log format (they say it uses JSON but actually it's msgpack, which is compatible with JSON)
36
- * Exchange objects between software components written in different languages
37
- * You'll need a flexible but efficient format so that components exchange objects while keeping compatibility
38
-
39
- = Portability
40
-
41
- MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
42
-
43
- And it works with MRI (CRuby) and Rubinius.
44
- Patches to improve portability is highly welcomed.
45
-
46
-
47
- = Serializing objects
48
-
49
- Use *MessagePack.pack* or *to_msgpack*:
50
-
51
- require 'msgpack'
52
- msg = MessagePack.pack(obj) # or
53
- msg = obj.to_msgpack
54
-
55
- == Streaming serialization
56
-
57
- Packer provides advanced API to serialize objects in streaming style:
58
-
59
- # serialize a 2-element array [e1, e2]
60
- pk = MessagePack::Packer.new(io)
61
- pk.write_array_header(2).write(e1).write(e2).flush
62
-
63
- See {API reference}[http://ruby.msgpack.org/MessagePack/Packer.html] for details.
64
-
65
- = Deserializing objects
66
-
67
- Use *MessagePack.unpack*:
68
-
69
- require 'msgpack'
70
- obj = MessagePack.unpack(msg)
71
-
72
- == Streaming deserialization
73
-
74
- Unpacker provides advanced API to deserialize objects in streaming style:
75
-
76
- # deserialize objects from an IO
77
- u = MessagePack::Unpacker.new(io)
78
- u.each do |obj|
79
- # ...
80
- end
81
-
82
- or event-driven style which works well with EventMachine:
83
-
84
- # event-driven deserialization
85
- def on_read(data)
86
- @u ||= MessagePack::Unpacker.new
87
- @u.feed_each(data) {|obj|
88
- # ...
89
- }
90
- end
91
-
92
- See {API reference}[http://ruby.msgpack.org/MessagePack/Unpacker.html] for details.
93
-
94
- = Serializing and deserializing symbols
95
-
96
- By default, symbols are serialized as strings:
97
-
98
- packed = :symbol.to_msgpack # => "\xA6symbol"
99
- MessagePack.unpack(packed) # => "symbol"
100
-
101
- This can be customized by registering an extension type for them:
102
-
103
- MessagePack::DefaultFactory.register_type(0x00, Symbol)
104
-
105
- # symbols now survive round trips
106
- packed = :symbol.to_msgpack # => "\xc7\x06\x00symbol"
107
- MessagePack.unpack(packed) # => :symbol
108
-
109
- The extension type for symbols is configurable like any other extension type.
110
- For example, to customize how symbols are packed you can just redefine
111
- Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from
112
- being serialized altogether by throwing an exception:
113
-
114
- class Symbol
115
- def to_msgpack_ext
116
- raise "Serialization of symbols prohibited"
117
- end
118
- end
119
-
120
- MessagePack::DefaultFactory.register_type(0x00, Symbol)
121
-
122
- [1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited
123
-
124
- = Extension Types
125
-
126
- Packer and Unpacker support {Extension types of MessagePack}[https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type].
127
-
128
- # register how to serialize custom class at first
129
- pk = MessagePack::Packer.new(io)
130
- pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass)
131
- pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available
132
-
133
- # almost same API for unpacker
134
- uk = MessagePack::Unpacker.new()
135
- uk.register_type(0x01, MyClass1, :from_msgpack_ext)
136
- uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }
137
-
138
- MessagePack::Factory is to create packer and unpacker which have same extension types.
139
-
140
- factory = MessagePack::Factory.new
141
- factory.register_type(0x01, MyClass1) # same with next line
142
- factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
143
- pk = factory.packer(options_for_packer)
144
- uk = factory.unpacker(options_for_unpacker)
145
-
146
- For *MessagePack.pack* and *MessagePack.unpack*, default packer/unpacker refer *MessagePack::DefaultFactory*. Call *MessagePack::DefaultFactory.register_type* to enable types process globally.
147
-
148
- MessagePack::DefaultFactory.register_type(0x03, MyClass3)
149
- MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance
150
-
151
- = Buffer API
152
-
153
- MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
154
-
155
- This {MessagePack::Buffer}[http://ruby.msgpack.org/MessagePack/Buffer.html] is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB),
156
- and has zero-copy capability which significantly affects performance to handle large binary data.
157
-
158
- = How to build and run tests
159
-
160
- Before building msgpack, you need to install bundler and dependencies.
161
-
162
- gem install bundler
163
- bundle install
164
-
165
- Then, you can run the tasks as follows:
166
-
167
- * Build
168
-
169
- bundle exec rake build
170
-
171
- * Run tests
172
-
173
- bundle exec rake spec
174
-
175
- * Generating docs
176
-
177
- bundle exec rake doc
178
-
179
- == How to build -java rubygems
180
-
181
- To build -java gems for JRuby, run:
182
-
183
- rake build:java
184
-
185
- If this directory has Gemfile.lock (generated with MRI), remove it beforehand.
186
-
187
- == How to build -mingw32 rubygems
188
-
189
- MessagePack mingw32/64 rubygems build process uses {rake-compiler-dock}[https://github.com/rake-compiler/rake-compiler-dock]. Run:
190
-
191
- rake build:windows
192
-
193
- Once this step successes, target gems exist in pkg/msgpack-*-{x86,x64}-mingw32.gem.
194
-
195
- == Updating documents
196
-
197
- Online documents (http://ruby.msgpack.org) is generated from gh-pages branch.
198
- Following commands update documents in gh-pages branch:
199
-
200
- bundle exec rake doc
201
- git checkout gh-pages
202
- cp doc/* ./ -a
203
-
204
- = Copyright
205
-
206
- Author:: Sadayuki Furuhashi <frsyuki@gmail.com>
207
- Copyright:: Copyright (c) 2008-2015 Sadayuki Furuhashi
208
- License:: Apache License, Version 2.0
209
-