msgpack 1.3.3 → 1.6.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yaml +57 -0
  3. data/.rubocop.yml +2 -2
  4. data/ChangeLog +74 -0
  5. data/Gemfile +1 -1
  6. data/README.md +266 -0
  7. data/Rakefile +1 -9
  8. data/bench/bench.rb +78 -0
  9. data/bin/console +8 -0
  10. data/doclib/msgpack/factory.rb +47 -3
  11. data/doclib/msgpack/packer.rb +5 -4
  12. data/doclib/msgpack/unpacker.rb +2 -2
  13. data/ext/java/org/msgpack/jruby/Buffer.java +23 -16
  14. data/ext/java/org/msgpack/jruby/Decoder.java +46 -23
  15. data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
  16. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +37 -49
  17. data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
  18. data/ext/java/org/msgpack/jruby/Factory.java +47 -7
  19. data/ext/java/org/msgpack/jruby/Packer.java +29 -17
  20. data/ext/java/org/msgpack/jruby/Unpacker.java +72 -37
  21. data/ext/msgpack/buffer.c +42 -68
  22. data/ext/msgpack/buffer.h +59 -14
  23. data/ext/msgpack/buffer_class.c +90 -52
  24. data/ext/msgpack/compat.h +1 -111
  25. data/ext/msgpack/extconf.rb +45 -19
  26. data/ext/msgpack/factory_class.c +133 -43
  27. data/ext/msgpack/packer.c +60 -36
  28. data/ext/msgpack/packer.h +27 -25
  29. data/ext/msgpack/packer_class.c +84 -77
  30. data/ext/msgpack/packer_class.h +11 -0
  31. data/ext/msgpack/packer_ext_registry.c +24 -32
  32. data/ext/msgpack/packer_ext_registry.h +40 -33
  33. data/ext/msgpack/sysdep.h +5 -2
  34. data/ext/msgpack/unpacker.c +132 -115
  35. data/ext/msgpack/unpacker.h +23 -10
  36. data/ext/msgpack/unpacker_class.c +83 -78
  37. data/ext/msgpack/unpacker_class.h +11 -0
  38. data/ext/msgpack/unpacker_ext_registry.c +42 -18
  39. data/ext/msgpack/unpacker_ext_registry.h +23 -16
  40. data/lib/msgpack/bigint.rb +69 -0
  41. data/lib/msgpack/factory.rb +103 -0
  42. data/lib/msgpack/symbol.rb +21 -4
  43. data/lib/msgpack/time.rb +1 -1
  44. data/lib/msgpack/version.rb +4 -8
  45. data/lib/msgpack.rb +6 -12
  46. data/msgpack.gemspec +4 -6
  47. data/spec/bigint_spec.rb +26 -0
  48. data/spec/cruby/buffer_spec.rb +17 -0
  49. data/spec/factory_spec.rb +351 -12
  50. data/spec/msgpack_spec.rb +1 -1
  51. data/spec/packer_spec.rb +18 -0
  52. data/spec/spec_helper.rb +37 -3
  53. data/spec/timestamp_spec.rb +38 -0
  54. data/spec/unpacker_spec.rb +157 -4
  55. metadata +31 -61
  56. data/.travis.yml +0 -43
  57. data/README.rdoc +0 -225
  58. data/bench/pack.rb +0 -23
  59. data/bench/pack_log.rb +0 -33
  60. data/bench/pack_log_long.rb +0 -65
  61. data/bench/pack_symbols.rb +0 -28
  62. data/bench/run.sh +0 -14
  63. data/bench/run_long.sh +0 -35
  64. data/bench/run_symbols.sh +0 -26
  65. data/bench/unpack.rb +0 -21
  66. data/bench/unpack_log.rb +0 -34
  67. data/bench/unpack_log_long.rb +0 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40d206a80a2ab99957b78f2d054417dc273933da4accf5f39a25ff4b16ec30ce
4
- data.tar.gz: e39c06187017d057a44e71d3690662455934c2c1acafc667d49e91aaf626fbd9
3
+ metadata.gz: bb08f890b2d9a36312600e284933cd0de93a00a6b949507bfc3d7c5c7eab1638
4
+ data.tar.gz: 11e536f8bde329edbc966e5e1050134350024f89f1cb911878f86fd59ff1fc79
5
5
  SHA512:
6
- metadata.gz: d20c8da71f90435f264c0e1c9c90e4a5c8c09c014d33076149e6e5faa3b849ac5192d2f086b917f09eb199bcfd8cc748093d6f59e3f5fcb7c228199f549c23c5
7
- data.tar.gz: dd5c662d5abbf45901d59a7400f2b92a6c296b2298035fecc55a31f82b19b4e9206ca3b0a7cab090d9cc9768bea015b74ad9bf5a997a763eb6ba3387b6a7fc30
6
+ metadata.gz: 9491cdf494d1826cce7f5e420d73a65ce88c029e060338d9c28fb1e20e4d01dc71fdb46b91859d025bbcc8f5a0471100b171cb9b3bac5fed6f0f0715fd76abb2
7
+ data.tar.gz: 8d0b4db4f93ebf98063f275c0629648ab9316c7cc3cd81738f7f083c6ed4c47fc647c2fc5df1308089b96c36d7e13944028e75bae7e5897b5bb357701c0bcfd9
@@ -0,0 +1,57 @@
1
+ name: ci
2
+
3
+ on:
4
+ pull_request:
5
+ branches: '*'
6
+ push:
7
+ branches:
8
+ - master
9
+ - main
10
+ - 'release-*'
11
+
12
+ jobs:
13
+ mri:
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os: [ubuntu, macos, windows]
18
+ ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
19
+ runs-on: ${{ matrix.os }}-latest
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true # 'bundle install' and cache
26
+ - run: bundle exec rake
27
+
28
+ other:
29
+ strategy:
30
+ fail-fast: false
31
+ matrix:
32
+ os: [ubuntu]
33
+ ruby: ['jruby-9.2.19.0', 'jruby-9.3.3.0', 'truffleruby']
34
+ runs-on: ${{ matrix.os }}-latest
35
+ steps:
36
+ - uses: actions/checkout@v2
37
+ - uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ bundler-cache: true # 'bundle install' and cache
41
+ - run: bundle exec rake spec
42
+
43
+ head-versions:
44
+ continue-on-error: true
45
+ strategy:
46
+ fail-fast: false
47
+ matrix:
48
+ os: [ubuntu]
49
+ ruby: ['ruby-head', 'jruby-head']
50
+ runs-on: ${{ matrix.os }}-latest
51
+ steps:
52
+ - uses: actions/checkout@v2
53
+ - uses: ruby/setup-ruby@v1
54
+ with:
55
+ ruby-version: ${{ matrix.ruby }}
56
+ bundler-cache: true # 'bundle install' and cache
57
+ - run: bundle exec rake spec || echo "failed, but ignore it"
data/.rubocop.yml CHANGED
@@ -6,7 +6,7 @@
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: 2.3
9
+ TargetRubyVersion: 2.4
10
10
 
11
11
  # Offense count: 3
12
12
  Lint/AmbiguousOperator:
@@ -18,7 +18,7 @@ Lint/AssignmentInCondition:
18
18
  Enabled: false
19
19
 
20
20
  # Offense count: 1
21
- Lint/Eval:
21
+ Security/Eval:
22
22
  Enabled: false
23
23
 
24
24
  # Offense count: 3
data/ChangeLog CHANGED
@@ -1,3 +1,77 @@
1
+ 2022-09-30 1.6.0:
2
+
3
+ * Fix a potential use-after-free bug in Buffer_free when accessing a packer or unpacker buffer.
4
+ * `old-style-definition` compilation warnings.
5
+ * Restore zero-copy buffer feed when provided a Ruby string. This was accidentally broken in 1.5.4.
6
+ * Provide implementations for `ObjectSpace.memsize`. Message pack objects now properly report their size to Ruby.
7
+ * Fix an endianess bug on Windows platform.
8
+
9
+ 2022-08-23 1.5.6:
10
+
11
+ * No actual code change, just re-release the `java` version properly.
12
+
13
+ 2022-08-22 1.5.5:
14
+
15
+ * Fix a segfault when GC triggers inside a recursive extension.
16
+
17
+ 2022-07-25 1.5.4:
18
+
19
+ * Fix a segfault when deserializing empty symbol (`:""`).
20
+ * Improve compilation flags to not strip debug symbols.
21
+
22
+ 2022-05-30 version 1.5.3:
23
+
24
+ * Fix deduplication of empty strings when using the `freeze: true` option.
25
+ * Use `rb_hash_new_capa` when available (Ruby 3.2) for improved performance when parsing large hashes.
26
+
27
+ 2022-05-27 version 1.5.2:
28
+
29
+ * Fix bug about unpacking ext type objects with the recursive option
30
+
31
+ 2022-04-07 version 1.5.1:
32
+
33
+ * Fix bug about packing/unpacking ext type objects with the recursive option
34
+
35
+ 2022-04-06 version 1.5.0:
36
+
37
+ * Add recursive option on Factory#register_type to operate Packer/Unpacker manually
38
+ * Add oversized_integer_extension option on Factory#register_type to pack/unpack bigint using ext types
39
+ * Add Factory#pool method and Factory::Pool class to provide pooled Packer and Unpacker instances
40
+
41
+ 2022-02-15 version 1.4.5:
42
+
43
+ * Fix to create UTF-8 Symbol keys when symbolize_keys: true
44
+ * Fix to assume Symbols as US-ASCII or UTF-8
45
+ * Optimize Packer/Unpacker initialization
46
+ * Optimize extension class lookup
47
+ * Rename Packer#clear as Packer#reset (#clear is still available as an alias)
48
+
49
+ 2022-01-22 version 1.4.4:
50
+
51
+ * Specify the build option --platform=8 for older Java platforms
52
+
53
+ 2022-01-20 version 1.4.3:
54
+
55
+ * Optimize serialization/deserialization of Symbols
56
+ * Support registering ext types for objects of subclasses of primitive types (like Hash)
57
+ * Add optimized_symbols_parsing option to Factory#register_type on MRI implementation
58
+ * Optimize to deduplicate Hash keys on JRuby
59
+ * Support JRuby 9.3 (and drop 9.1)
60
+
61
+ 2021-02-01 version 1.4.2:
62
+
63
+ * Add the required Ruby version (>= 2.4) to avoid compilation errors on older Ruby runtimes
64
+ * Drop the support of old Ruby versions explicitly (1.8, 1.9, 2.0, 2.1, 2.2, 2.3)
65
+
66
+ 2021-01-27 version 1.4.1:
67
+
68
+ * Bugfix about the wrong string encoding longer than 256 bytes (#200)
69
+
70
+ 2021-01-27 version 1.4.0:
71
+
72
+ * Introduce the optimization to use frozen/deduped keys for map objects
73
+ * Stop releasing fat gem (pre-built binaries) for mswin32 arch environments
74
+
1
75
  2020-02-05 version 1.3.3:
2
76
 
3
77
  * Hotfix release for Windows environments: 1.3.2 missed including binaries
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
  ## enable this line to run benchmarks
6
6
  # gem "viiite"
7
7
 
8
- gem "rubocop"
8
+ gem "rubocop", "~> 0.82.0"
9
9
  gem "simplecov"
data/README.md ADDED
@@ -0,0 +1,266 @@
1
+ # MessagePack
2
+
3
+ [MessagePack](http://msgpack.org) is an efficient binary serialization format.
4
+ It lets you exchange data among multiple languages like JSON but it's faster and smaller.
5
+ For example, small integers (like flags or error code) are encoded into a single byte,
6
+ and typical short strings only require an extra byte in addition to the strings themselves.
7
+
8
+ If you ever wished to use JSON for convenience (storing an image with metadata) but could
9
+ not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.
10
+
11
+ require 'msgpack'
12
+ msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
13
+ MessagePack.unpack(msg) #=> [1,2,3]
14
+
15
+ Use RubyGems to install:
16
+
17
+ gem install msgpack
18
+
19
+ or build msgpack-ruby and install:
20
+
21
+ bundle
22
+ rake
23
+ gem install --local pkg/msgpack
24
+
25
+
26
+ ## Use cases
27
+
28
+ * Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl)
29
+ * Store objects efficiently serialized by msgpack on memcached or Redis
30
+ * In fact Redis supports msgpack in [EVAL-scripts](http://redis.io/commands/eval)
31
+ * Upload data in efficient format from mobile devices such as smartphones
32
+ * 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
33
+ * Design a portable protocol to communicate with embedded devices
34
+ * 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)
35
+ * Exchange objects between software components written in different languages
36
+ * You'll need a flexible but efficient format so that components exchange objects while keeping compatibility
37
+
38
+ ## Portability
39
+
40
+ MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
41
+
42
+ And it works with MRI (CRuby) and Rubinius.
43
+ Patches to improve portability are highly welcomed.
44
+
45
+
46
+ ## Serializing objects
47
+
48
+ Use `MessagePack.pack` or `to_msgpack`:
49
+
50
+ ```ruby
51
+ require 'msgpack'
52
+ msg = MessagePack.pack(obj) # or
53
+ msg = obj.to_msgpack
54
+ File.binwrite('mydata.msgpack', msg)
55
+ ```
56
+
57
+ ### Streaming serialization
58
+
59
+ Packer provides advanced API to serialize objects in streaming style:
60
+
61
+ ```ruby
62
+ # serialize a 2-element array [e1, e2]
63
+ pk = MessagePack::Packer.new(io)
64
+ pk.write_array_header(2).write(e1).write(e2).flush
65
+ ```
66
+
67
+ See [API reference](http://ruby.msgpack.org/MessagePack/Packer.html) for details.
68
+
69
+ ## Deserializing objects
70
+
71
+ Use `MessagePack.unpack`:
72
+
73
+ ```ruby
74
+ require 'msgpack'
75
+ msg = File.binread('mydata.msgpack')
76
+ obj = MessagePack.unpack(msg)
77
+ ```
78
+
79
+ ### Streaming deserialization
80
+
81
+ Unpacker provides advanced API to deserialize objects in streaming style:
82
+
83
+ ```ruby
84
+ # deserialize objects from an IO
85
+ u = MessagePack::Unpacker.new(io)
86
+ u.each do |obj|
87
+ # ...
88
+ end
89
+ ```
90
+
91
+ or event-driven style which works well with EventMachine:
92
+
93
+ ```ruby
94
+ # event-driven deserialization
95
+ def on_read(data)
96
+ @u ||= MessagePack::Unpacker.new
97
+ @u.feed_each(data) {|obj|
98
+ # ...
99
+ }
100
+ end
101
+ ```
102
+
103
+ See [API reference](http://ruby.msgpack.org/MessagePack/Unpacker.html) for details.
104
+
105
+ ## Serializing and deserializing symbols
106
+
107
+ By default, symbols are serialized as strings:
108
+
109
+ ```ruby
110
+ packed = :symbol.to_msgpack # => "\xA6symbol"
111
+ MessagePack.unpack(packed) # => "symbol"
112
+ ```
113
+
114
+ This can be customized by registering an extension type for them:
115
+
116
+ ```ruby
117
+ MessagePack::DefaultFactory.register_type(0x00, Symbol)
118
+
119
+ # symbols now survive round trips
120
+ packed = :symbol.to_msgpack # => "\xc7\x06\x00symbol"
121
+ MessagePack.unpack(packed) # => :symbol
122
+ ```
123
+
124
+ The extension type for symbols is configurable like any other extension type.
125
+ For example, to customize how symbols are packed you can just redefine
126
+ Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from
127
+ being serialized altogether by throwing an exception:
128
+
129
+ ```ruby
130
+ class Symbol
131
+ def to_msgpack_ext
132
+ raise "Serialization of symbols prohibited"
133
+ end
134
+ end
135
+
136
+ MessagePack::DefaultFactory.register_type(0x00, Symbol)
137
+
138
+ [1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited
139
+ ```
140
+
141
+ ## Serializing and deserializing Time instances
142
+
143
+ There are the timestamp extension type in MessagePack,
144
+ but it is not registered by default.
145
+
146
+ To map Ruby's Time to MessagePack's timestamp for the default factory:
147
+
148
+ ```ruby
149
+ MessagePack::DefaultFactory.register_type(
150
+ MessagePack::Timestamp::TYPE, # or just -1
151
+ Time,
152
+ packer: MessagePack::Time::Packer,
153
+ unpacker: MessagePack::Time::Unpacker
154
+ )
155
+ ```
156
+
157
+ See [API reference](http://ruby.msgpack.org/) for details.
158
+
159
+ ## Extension Types
160
+
161
+ Packer and Unpacker support [Extension types of MessagePack](https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type).
162
+
163
+ ```ruby
164
+ # register how to serialize custom class at first
165
+ pk = MessagePack::Packer.new(io)
166
+ pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass)
167
+ pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available
168
+
169
+ # almost same API for unpacker
170
+ uk = MessagePack::Unpacker.new()
171
+ uk.register_type(0x01, MyClass1, :from_msgpack_ext)
172
+ uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }
173
+ ```
174
+
175
+ `MessagePack::Factory` is to create packer and unpacker which have same extension types.
176
+
177
+ ```ruby
178
+ factory = MessagePack::Factory.new
179
+ factory.register_type(0x01, MyClass1) # same with next line
180
+ factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
181
+ pk = factory.packer(options_for_packer)
182
+ uk = factory.unpacker(options_for_unpacker)
183
+ ```
184
+
185
+ For `MessagePack.pack` and `MessagePack.unpack`, default packer/unpacker refer `MessagePack::DefaultFactory`. Call `MessagePack::DefaultFactory.register_type` to enable types process globally.
186
+
187
+ ```ruby
188
+ MessagePack::DefaultFactory.register_type(0x03, MyClass3)
189
+ MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance
190
+ ```
191
+
192
+ Alternatively, extension types can call the packer or unpacker recursively to generate the extension data:
193
+
194
+ ```ruby
195
+ Point = Struct.new(:x, :y)
196
+ factory = MessagePack::Factory.new
197
+ factory.register_type(
198
+ 0x01,
199
+ Point,
200
+ packer: ->(point, packer) {
201
+ packer.write(point.x)
202
+ packer.write(point.y)
203
+ },
204
+ unpacker: ->(unpacker) {
205
+ x = unpacker.read
206
+ y = unpacker.read
207
+ Point.new(x, y)
208
+ },
209
+ recursive: true,
210
+ )
211
+ factory.load(factory.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34>
212
+ ```
213
+
214
+ ## Buffer API
215
+
216
+ MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
217
+
218
+ 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),
219
+ and has zero-copy capability which significantly affects performance to handle large binary data.
220
+
221
+ ## How to build and run tests
222
+
223
+ Before building msgpack, you need to install bundler and dependencies.
224
+
225
+ gem install bundler
226
+ bundle install
227
+
228
+ Then, you can run the tasks as follows:
229
+
230
+ ### Build
231
+
232
+ bundle exec rake build
233
+
234
+ ### Run tests
235
+
236
+ bundle exec rake spec
237
+
238
+ ### Generating docs
239
+
240
+ bundle exec rake doc
241
+
242
+ ## How to build -java rubygems
243
+
244
+ To build -java gems for JRuby, run:
245
+
246
+ rake build:java
247
+
248
+ If this directory has Gemfile.lock (generated with MRI), remove it beforehand.
249
+
250
+ ## Updating documents
251
+
252
+ Online documents (http://ruby.msgpack.org) is generated from gh-pages branch.
253
+ Following commands update documents in gh-pages branch:
254
+
255
+ bundle exec rake doc
256
+ git checkout gh-pages
257
+ cp doc/* ./ -a
258
+
259
+ ## Copyright
260
+
261
+ * Author
262
+ * Sadayuki Furuhashi <frsyuki@gmail.com>
263
+ * Copyright
264
+ * Copyright (c) 2008-2015 Sadayuki Furuhashi
265
+ * License
266
+ * Apache License, Version 2.0
data/Rakefile CHANGED
@@ -34,8 +34,7 @@ if RUBY_PLATFORM =~ /java/
34
34
  jars = ["#{jruby_home}/lib/jruby.jar"]
35
35
  ext.classpath = jars.map { |x| File.expand_path(x) }.join(':')
36
36
  ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
37
- ext.source_version = '1.6'
38
- ext.target_version = '1.6'
37
+ ext.release = '8'
39
38
  end
40
39
  else
41
40
  require 'rake/extensiontask'
@@ -64,13 +63,6 @@ end
64
63
  namespace :build do
65
64
  desc 'Build gem for JRuby after cleaning'
66
65
  task :java => [:clean, :spec, :build]
67
-
68
- desc 'Build gems for Windows per rake-compiler-dock'
69
- task :windows do
70
- require 'rake_compiler_dock'
71
- # See RUBY_CC_VERSION in https://github.com/rake-compiler/rake-compiler-dock/blob/master/Dockerfile
72
- RakeCompilerDock.sh 'bundle && gem i json && rake cross native gem RUBY_CC_VERSION=2.2.2:2.3.0:2.4.0:2.5.0:2.6.0:2.7.0'
73
- end
74
66
  end
75
67
 
76
68
  CLEAN.include('lib/msgpack/msgpack.*')
data/bench/bench.rb ADDED
@@ -0,0 +1,78 @@
1
+ # % bundle install
2
+ # % bundle exec ruby bench/bench.rb
3
+
4
+ require 'msgpack'
5
+
6
+ require 'benchmark/ips'
7
+
8
+ object_plain = {
9
+ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
10
+ }
11
+
12
+ data_plain = MessagePack.pack(object_plain)
13
+
14
+ object_structured = {
15
+ 'remote_host' => '127.0.0.1',
16
+ 'remote_user' => '-',
17
+ 'date' => '10/Oct/2000:13:55:36 -0700',
18
+ 'request' => 'GET /apache_pb.gif HTTP/1.0',
19
+ 'method' => 'GET',
20
+ 'path' => '/apache_pb.gif',
21
+ 'protocol' => 'HTTP/1.0',
22
+ 'status' => 200,
23
+ 'bytes' => 2326,
24
+ 'referer' => 'http://www.example.com/start.html',
25
+ 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
26
+ }
27
+
28
+ data_structured = MessagePack.pack(object_structured)
29
+
30
+ class Extended
31
+ def to_msgpack_ext
32
+ MessagePack.pack({})
33
+ end
34
+
35
+ def self.from_msgpack_ext(data)
36
+ MessagePack.unpack(data)
37
+ Extended.new
38
+ end
39
+ end
40
+
41
+ object_extended = {
42
+ 'extended' => Extended.new
43
+ }
44
+
45
+ extended_packer = MessagePack::Packer.new
46
+ extended_packer.register_type(0x00, Extended, :to_msgpack_ext)
47
+ data_extended = extended_packer.pack(object_extended).to_s
48
+
49
+ Benchmark.ips do |x|
50
+ x.report('pack-plain') do
51
+ MessagePack.pack(object_plain)
52
+ end
53
+
54
+ x.report('pack-structured') do
55
+ MessagePack.pack(object_structured)
56
+ end
57
+
58
+ x.report('pack-extended') do
59
+ packer = MessagePack::Packer.new
60
+ packer.register_type(0x00, Extended, :to_msgpack_ext)
61
+ packer.pack(object_extended).to_s
62
+ end
63
+
64
+ x.report('unpack-plain') do
65
+ MessagePack.unpack(data_plain)
66
+ end
67
+
68
+ x.report('unpack-structured') do
69
+ MessagePack.unpack(data_structured)
70
+ end
71
+
72
+ x.report('unpack-extended') do
73
+ unpacker = MessagePack::Unpacker.new
74
+ unpacker.register_type(0x00, Extended, :from_msgpack_ext)
75
+ unpacker.feed data_extended
76
+ unpacker.read
77
+ end
78
+ end
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "msgpack"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
@@ -31,7 +31,7 @@ module MessagePack
31
31
  #
32
32
  # See Packer#initialize for supported options.
33
33
  #
34
- def dump(obj, options={})
34
+ def dump(obj, options=nil)
35
35
  end
36
36
  alias pack dump
37
37
 
@@ -57,13 +57,13 @@ module MessagePack
57
57
  #
58
58
  # See Unpacker#initialize for supported options.
59
59
  #
60
- def load(data, options={})
60
+ def load(data, options=nil)
61
61
  end
62
62
  alias unpack load
63
63
 
64
64
  #
65
65
  # Register a type and Class to be registered for packer and/or unpacker.
66
- # If options are not speicified, factory will use :to_msgpack_ext for packer, and
66
+ # If options are not specified, factory will use :to_msgpack_ext for packer, and
67
67
  # :from_msgpack_ext for unpacker.
68
68
  #
69
69
  # @param type [Fixnum] type id of registered Class (0-127)
@@ -75,6 +75,8 @@ module MessagePack
75
75
  #
76
76
  # * *:packer* specify symbol or proc object for packer
77
77
  # * *:unpacker* specify symbol or proc object for unpacker
78
+ # * *:optimized_symbols_parsing* specify true to use the optimized symbols parsing (not supported on JRuby now)
79
+ # * *recursive* specify true to receive the packer or unpacker as argument to generate the extension body manually.
78
80
  #
79
81
  def register_type(type, klass, options={})
80
82
  end
@@ -97,5 +99,47 @@ module MessagePack
97
99
  #
98
100
  def type_registered?(klass_or_type, selector=:both)
99
101
  end
102
+
103
+ #
104
+ # Creates a MessagePack::PooledFactory instance of the given size.
105
+ #
106
+ # PooledFactory keeps Packer and Unpacker instance in a pool for improved performance.
107
+ # Note that the size defines how many instances are kept in cache, not the maximum of instances
108
+ # that can be created. If the pool limit is reached, a new instance is created anyway.
109
+ #
110
+ # @param size [Fixnum] specify how many Packer and Unpacker to keep in cache (default 1)
111
+ # @param options [Hash] Combined options for Packer and Unpacker. See Packer#initialize and Unpacker#initialize
112
+ # for supported options.
113
+ def pool(size=1, **options)
114
+ end
115
+
116
+ class Pool
117
+ #
118
+ # Deserializes an object from the string or io and returns it.
119
+ #
120
+ # If there're not enough data to deserialize one object, this method raises EOFError.
121
+ # If data format is invalid, this method raises MessagePack::MalformedFormatError.
122
+ # If the object nests too deeply, this method raises MessagePack::StackError.
123
+ #
124
+ # @param data [String]
125
+ # @return [Object] deserialized object
126
+ #
127
+ # See Unpacker#initialize for supported options.
128
+ #
129
+ def load(data)
130
+ end
131
+
132
+ #
133
+ # Serialize the passed value
134
+ #
135
+ # If it could not serialize the object, it raises
136
+ # NoMethodError: undefined method `to_msgpack' for #<the_object>.
137
+ #
138
+ # @param obj [Object] object to serialize
139
+ # @return [String] serialized object
140
+ #
141
+ def dump(object)
142
+ end
143
+ end
100
144
  end
101
145
  end
@@ -14,7 +14,7 @@ module MessagePack
14
14
  # @overload initialize(io, options={})
15
15
  # @param io [IO]
16
16
  # @param options [Hash]
17
- # This packer writes serialzied objects into the IO when the internal buffer is filled.
17
+ # This packer writes serialized objects into the IO when the internal buffer is filled.
18
18
  # _io_ must respond to write(string) or append(string) method.
19
19
  #
20
20
  # Supported options:
@@ -33,12 +33,12 @@ module MessagePack
33
33
  #
34
34
  # @overload register_type(type, klass, &block)
35
35
  # @param type [Fixnum] type id (0-127) user defined type id for specified Class
36
- # @param klass [Class] Class to be serialized with speicifed type id
36
+ # @param klass [Class] Class to be serialized with specified type id
37
37
  # @yieldparam object [Object] object to be serialized
38
38
  #
39
39
  # @overload register_type(type, klass, method_name)
40
40
  # @param type [Fixnum] type id (0-127) user defined type id for specified Class
41
- # @param klass [Class] Class to be serialized with speicifed type id
41
+ # @param klass [Class] Class to be serialized with specified type id
42
42
  # @param method_name [Symbol] method which returns bytes of serialized representation
43
43
  #
44
44
  # @return nil
@@ -155,8 +155,9 @@ module MessagePack
155
155
  #
156
156
  # @return nil
157
157
  #
158
- def clear
158
+ def reset
159
159
  end
160
+ alias clear reset
160
161
 
161
162
  #
162
163
  # Returns size of the internal buffer. Same as buffer.size.
@@ -36,7 +36,7 @@ module MessagePack
36
36
  #
37
37
  # @overload register_type(type, klass, class_method_name)
38
38
  # @param type [Fixnum] type id (0-127) user defined type id for specified Class
39
- # @param klass [Class] Class to be serialized with speicifed type id
39
+ # @param klass [Class] Class to be serialized with specified type id
40
40
  # @param class_method_name [Symbol] class method which returns an instance object
41
41
  #
42
42
  # @return nil
@@ -149,7 +149,7 @@ module MessagePack
149
149
  #
150
150
  # It repeats until the io or internal buffer does not include any complete objects.
151
151
  #
152
- # If the an IO is set, it repeats to read data from the IO when the buffer
152
+ # If an IO is set, it repeats to read data from the IO when the buffer
153
153
  # becomes empty until the IO raises EOFError.
154
154
  #
155
155
  # This method could raise same errors with _read_ excepting EOFError.