msgpack 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +14 -0
  3. data/README.md +27 -0
  4. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +4 -9
  5. data/ext/java/org/msgpack/jruby/Factory.java +1 -1
  6. data/ext/java/org/msgpack/jruby/Packer.java +3 -0
  7. data/ext/java/org/msgpack/jruby/Unpacker.java +3 -0
  8. data/ext/msgpack/buffer.c +9 -12
  9. data/ext/msgpack/buffer.h +2 -10
  10. data/ext/msgpack/buffer_class.c +4 -4
  11. data/ext/msgpack/extconf.rb +3 -15
  12. data/ext/msgpack/factory_class.c +1 -1
  13. data/ext/msgpack/packer.c +1 -0
  14. data/ext/msgpack/packer_class.c +9 -19
  15. data/ext/msgpack/rbinit.c +1 -1
  16. data/ext/msgpack/rmem.c +3 -4
  17. data/ext/msgpack/unpacker.c +8 -20
  18. data/ext/msgpack/unpacker.h +0 -4
  19. data/ext/msgpack/unpacker_class.c +11 -21
  20. data/lib/msgpack/buffer.rb +9 -0
  21. data/lib/msgpack/factory.rb +41 -53
  22. data/lib/msgpack/packer.rb +4 -0
  23. data/lib/msgpack/unpacker.rb +4 -0
  24. data/lib/msgpack/version.rb +1 -1
  25. data/lib/msgpack.rb +1 -0
  26. data/msgpack.gemspec +6 -3
  27. metadata +19 -48
  28. data/.github/workflows/ci.yaml +0 -57
  29. data/.gitignore +0 -23
  30. data/.rubocop.yml +0 -36
  31. data/Gemfile +0 -9
  32. data/Rakefile +0 -70
  33. data/appveyor.yml +0 -18
  34. data/bench/bench.rb +0 -78
  35. data/bin/console +0 -8
  36. data/doclib/msgpack/buffer.rb +0 -193
  37. data/doclib/msgpack/core_ext.rb +0 -101
  38. data/doclib/msgpack/error.rb +0 -19
  39. data/doclib/msgpack/extension_value.rb +0 -9
  40. data/doclib/msgpack/factory.rb +0 -145
  41. data/doclib/msgpack/packer.rb +0 -209
  42. data/doclib/msgpack/time.rb +0 -22
  43. data/doclib/msgpack/timestamp.rb +0 -44
  44. data/doclib/msgpack/unpacker.rb +0 -183
  45. data/doclib/msgpack.rb +0 -87
  46. data/msgpack.org.md +0 -46
  47. data/spec/bigint_spec.rb +0 -26
  48. data/spec/cases.json +0 -1
  49. data/spec/cases.msg +0 -0
  50. data/spec/cases_compact.msg +0 -0
  51. data/spec/cases_spec.rb +0 -39
  52. data/spec/cruby/buffer_io_spec.rb +0 -255
  53. data/spec/cruby/buffer_packer.rb +0 -29
  54. data/spec/cruby/buffer_spec.rb +0 -592
  55. data/spec/cruby/buffer_unpacker.rb +0 -19
  56. data/spec/cruby/unpacker_spec.rb +0 -70
  57. data/spec/ext_value_spec.rb +0 -99
  58. data/spec/exttypes.rb +0 -51
  59. data/spec/factory_spec.rb +0 -706
  60. data/spec/format_spec.rb +0 -301
  61. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  62. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  63. data/spec/jruby/unpacker_spec.rb +0 -186
  64. data/spec/msgpack_spec.rb +0 -214
  65. data/spec/pack_spec.rb +0 -61
  66. data/spec/packer_spec.rb +0 -575
  67. data/spec/random_compat.rb +0 -24
  68. data/spec/spec_helper.rb +0 -72
  69. data/spec/timestamp_spec.rb +0 -159
  70. data/spec/unpack_spec.rb +0 -57
  71. data/spec/unpacker_spec.rb +0 -869
@@ -88,33 +88,34 @@ module MessagePack
88
88
 
89
89
  class Pool
90
90
  if RUBY_ENGINE == "ruby"
91
- class AbstractPool
91
+ class MemberPool
92
92
  def initialize(size, &block)
93
93
  @size = size
94
94
  @new_member = block
95
95
  @members = []
96
96
  end
97
97
 
98
- def checkout
99
- @members.pop || @new_member.call
100
- end
101
-
102
- def checkin(member)
103
- # If the pool is already full, we simply drop the extra member.
104
- # This is because contrary to a connection pool, creating an extra instance
105
- # is extremely unlikely to cause some kind of resource exhaustion.
106
- #
107
- # We could cycle the members (keep the newer one) but first It's more work and second
108
- # the older member might have been created pre-fork, so it might be at least partially
109
- # in shared memory.
110
- if member && @members.size < @size
111
- member.reset
112
- @members << member
98
+ def with
99
+ member = @members.pop || @new_member.call
100
+ begin
101
+ yield member
102
+ ensure
103
+ # If the pool is already full, we simply drop the extra member.
104
+ # This is because contrary to a connection pool, creating an extra instance
105
+ # is extremely unlikely to cause some kind of resource exhaustion.
106
+ #
107
+ # We could cycle the members (keep the newer one) but first It's more work and second
108
+ # the older member might have been created pre-fork, so it might be at least partially
109
+ # in shared memory.
110
+ if member && @members.size < @size
111
+ member.reset
112
+ @members << member
113
+ end
113
114
  end
114
115
  end
115
116
  end
116
117
  else
117
- class AbstractPool
118
+ class MemberPool
118
119
  def initialize(size, &block)
119
120
  @size = size
120
121
  @new_member = block
@@ -122,63 +123,50 @@ module MessagePack
122
123
  @mutex = Mutex.new
123
124
  end
124
125
 
125
- def checkout
126
- @mutex.synchronize { @members.pop } || @new_member.call
127
- end
128
-
129
- def checkin(member)
130
- @mutex.synchronize do
131
- if member && @members.size < @size
132
- member.reset
133
- @members << member
126
+ def with
127
+ member = @mutex.synchronize { @members.pop } || @new_member.call
128
+ begin
129
+ yield member
130
+ ensure
131
+ member.reset
132
+ @mutex.synchronize do
133
+ if member && @members.size < @size
134
+ @members << member
135
+ end
134
136
  end
135
137
  end
136
138
  end
137
139
  end
138
140
  end
139
141
 
140
- class PackerPool < AbstractPool
141
- private
142
-
143
- def reset(packer)
144
- packer.clear
145
- end
146
- end
147
-
148
- class UnpackerPool < AbstractPool
149
- private
150
-
151
- def reset(unpacker)
152
- unpacker.reset
153
- end
154
- end
155
-
156
142
  def initialize(factory, size, options = nil)
157
143
  options = nil if !options || options.empty?
158
144
  @factory = factory
159
- @packers = PackerPool.new(size) { factory.packer(options) }
160
- @unpackers = UnpackerPool.new(size) { factory.unpacker(options) }
145
+ @packers = MemberPool.new(size) { factory.packer(options).freeze }
146
+ @unpackers = MemberPool.new(size) { factory.unpacker(options).freeze }
161
147
  end
162
148
 
163
149
  def load(data)
164
- unpacker = @unpackers.checkout
165
- begin
166
- unpacker.feed_reference(data)
150
+ @unpackers.with do |unpacker|
151
+ unpacker.feed(data)
167
152
  unpacker.full_unpack
168
- ensure
169
- @unpackers.checkin(unpacker)
170
153
  end
171
154
  end
172
155
 
173
156
  def dump(object)
174
- packer = @packers.checkout
175
- begin
157
+ @packers.with do |packer|
176
158
  packer.write(object)
177
159
  packer.full_pack
178
- ensure
179
- @packers.checkin(packer)
180
160
  end
181
161
  end
162
+
163
+ def unpacker(&block)
164
+ @unpackers.with(&block)
165
+ end
166
+
167
+ def packer(&block)
168
+ @packers.with(&block)
169
+ end
182
170
  end
183
171
  end
184
172
  end
@@ -2,6 +2,10 @@ module MessagePack
2
2
  class Packer
3
3
  # see ext for other methods
4
4
 
5
+ # The semantic of duping a packer is just too weird.
6
+ undef_method :dup
7
+ undef_method :clone
8
+
5
9
  def registered_types
6
10
  list = []
7
11
 
@@ -2,6 +2,10 @@ module MessagePack
2
2
  class Unpacker
3
3
  # see ext for other methods
4
4
 
5
+ # The semantic of duping an unpacker is just too weird.
6
+ undef_method :dup
7
+ undef_method :clone
8
+
5
9
  def registered_types
6
10
  list = []
7
11
 
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  # Note for maintainers:
4
4
  # Don't miss building/releasing the JRuby version (rake buld:java)
5
5
  # See "How to build -java rubygems" in README for more details.
data/lib/msgpack.rb CHANGED
@@ -7,6 +7,7 @@ else
7
7
  require "msgpack/msgpack"
8
8
  end
9
9
 
10
+ require "msgpack/buffer"
10
11
  require "msgpack/packer"
11
12
  require "msgpack/unpacker"
12
13
  require "msgpack/factory"
data/msgpack.gemspec CHANGED
@@ -12,19 +12,22 @@ Gem::Specification.new do |s|
12
12
  s.homepage = "http://msgpack.org/"
13
13
  s.require_paths = ["lib"]
14
14
  if /java/ =~ RUBY_PLATFORM
15
- s.files = Dir['lib/**/*.rb', 'lib/**/*.jar']
15
+ s.files = Dir['lib/**/*.rb', 'lib/**/*.jar', 'LICENSE']
16
16
  s.platform = Gem::Platform.new('java')
17
17
  else
18
- s.files = `git ls-files`.split("\n")
18
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|bench|doclib|msgpack.org.md|Gemfile|Rakefile)|\.(?:git|circleci|rubocop)|appveyor)})
20
+ end
19
21
  s.extensions = ["ext/msgpack/extconf.rb"]
20
22
  end
21
23
 
22
- s.required_ruby_version = ">= 2.4"
24
+ s.required_ruby_version = ">= 2.5"
23
25
 
24
26
  s.add_development_dependency 'bundler'
25
27
  s.add_development_dependency 'rake'
26
28
  s.add_development_dependency 'rake-compiler', ['>= 1.1.9']
27
29
  s.add_development_dependency 'rspec', ['~> 3.3']
30
+ s.add_development_dependency 'ruby_memcheck'
28
31
  s.add_development_dependency 'yard'
29
32
  s.add_development_dependency 'json'
30
33
  s.add_development_dependency 'benchmark-ips', ['~> 2.10.0']
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: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
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: 2022-09-30 00:00:00.000000000 Z
13
+ date: 2023-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '3.3'
71
+ - !ruby/object:Gem::Dependency
72
+ name: ruby_memcheck
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: yard
73
87
  requirement: !ruby/object:Gem::Requirement
@@ -122,27 +136,9 @@ extensions:
122
136
  - ext/msgpack/extconf.rb
123
137
  extra_rdoc_files: []
124
138
  files:
125
- - ".github/workflows/ci.yaml"
126
- - ".gitignore"
127
- - ".rubocop.yml"
128
139
  - ChangeLog
129
- - Gemfile
130
140
  - LICENSE
131
141
  - README.md
132
- - Rakefile
133
- - appveyor.yml
134
- - bench/bench.rb
135
- - bin/console
136
- - doclib/msgpack.rb
137
- - doclib/msgpack/buffer.rb
138
- - doclib/msgpack/core_ext.rb
139
- - doclib/msgpack/error.rb
140
- - doclib/msgpack/extension_value.rb
141
- - doclib/msgpack/factory.rb
142
- - doclib/msgpack/packer.rb
143
- - doclib/msgpack/time.rb
144
- - doclib/msgpack/timestamp.rb
145
- - doclib/msgpack/unpacker.rb
146
142
  - ext/java/org/msgpack/jruby/Buffer.java
147
143
  - ext/java/org/msgpack/jruby/Decoder.java
148
144
  - ext/java/org/msgpack/jruby/Encoder.java
@@ -183,6 +179,7 @@ files:
183
179
  - ext/msgpack/unpacker_ext_registry.h
184
180
  - lib/msgpack.rb
185
181
  - lib/msgpack/bigint.rb
182
+ - lib/msgpack/buffer.rb
186
183
  - lib/msgpack/core_ext.rb
187
184
  - lib/msgpack/factory.rb
188
185
  - lib/msgpack/packer.rb
@@ -192,32 +189,6 @@ files:
192
189
  - lib/msgpack/unpacker.rb
193
190
  - lib/msgpack/version.rb
194
191
  - msgpack.gemspec
195
- - msgpack.org.md
196
- - spec/bigint_spec.rb
197
- - spec/cases.json
198
- - spec/cases.msg
199
- - spec/cases_compact.msg
200
- - spec/cases_spec.rb
201
- - spec/cruby/buffer_io_spec.rb
202
- - spec/cruby/buffer_packer.rb
203
- - spec/cruby/buffer_spec.rb
204
- - spec/cruby/buffer_unpacker.rb
205
- - spec/cruby/unpacker_spec.rb
206
- - spec/ext_value_spec.rb
207
- - spec/exttypes.rb
208
- - spec/factory_spec.rb
209
- - spec/format_spec.rb
210
- - spec/jruby/benchmarks/shootout_bm.rb
211
- - spec/jruby/benchmarks/symbolize_keys_bm.rb
212
- - spec/jruby/unpacker_spec.rb
213
- - spec/msgpack_spec.rb
214
- - spec/pack_spec.rb
215
- - spec/packer_spec.rb
216
- - spec/random_compat.rb
217
- - spec/spec_helper.rb
218
- - spec/timestamp_spec.rb
219
- - spec/unpack_spec.rb
220
- - spec/unpacker_spec.rb
221
192
  homepage: http://msgpack.org/
222
193
  licenses:
223
194
  - Apache 2.0
@@ -230,14 +201,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
201
  requirements:
231
202
  - - ">="
232
203
  - !ruby/object:Gem::Version
233
- version: '2.4'
204
+ version: '2.5'
234
205
  required_rubygems_version: !ruby/object:Gem::Requirement
235
206
  requirements:
236
207
  - - ">="
237
208
  - !ruby/object:Gem::Version
238
209
  version: '0'
239
210
  requirements: []
240
- rubygems_version: 3.1.2
211
+ rubygems_version: 3.4.6
241
212
  signing_key:
242
213
  specification_version: 4
243
214
  summary: MessagePack, a binary-based efficient data interchange format.
@@ -1,57 +0,0 @@
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/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- *.o
2
- *.so
3
- *.bundle
4
- *.gem
5
- *.class
6
- *.jar
7
- doc
8
- .yardoc
9
- .bundle
10
- Gemfile*
11
- pkg
12
- test/debug.log
13
- *~
14
- *.swp
15
- /rdoc
16
- tmp
17
- .classpath
18
- .project
19
- .settings
20
- /nbproject/private/
21
- coverage/
22
- .idea/
23
- .ruby-version
data/.rubocop.yml DELETED
@@ -1,36 +0,0 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-03-09 17:42:55 +0100 using RuboCop version 0.29.1.
3
- # The point is for the user to remove these configuration records
4
- # one by one as the offenses are removed from the code base.
5
- # Note that changes in the inspected code, or installation of new
6
- # versions of RuboCop, may require this file to be generated again.
7
-
8
- AllCops:
9
- TargetRubyVersion: 2.4
10
-
11
- # Offense count: 3
12
- Lint/AmbiguousOperator:
13
- Enabled: false
14
-
15
- # Offense count: 1
16
- # Configuration parameters: AllowSafeAssignment.
17
- Lint/AssignmentInCondition:
18
- Enabled: false
19
-
20
- # Offense count: 1
21
- Security/Eval:
22
- Enabled: false
23
-
24
- # Offense count: 3
25
- # Cop supports --auto-correct.
26
- Lint/UnusedBlockArgument:
27
- Enabled: false
28
-
29
- # Offense count: 35
30
- # Cop supports --auto-correct.
31
- Lint/UnusedMethodArgument:
32
- Enabled: false
33
-
34
- # Offense count: 128
35
- Lint/Void:
36
- Enabled: false
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org/'
2
-
3
- gemspec
4
-
5
- ## enable this line to run benchmarks
6
- # gem "viiite"
7
-
8
- gem "rubocop", "~> 0.82.0"
9
- gem "simplecov"
data/Rakefile DELETED
@@ -1,70 +0,0 @@
1
-
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
-
5
- require 'fileutils'
6
-
7
- require 'rspec/core'
8
- require 'rspec/core/rake_task'
9
- require 'yard'
10
-
11
- task :spec => :compile
12
-
13
- desc 'Run RSpec code examples and measure coverage'
14
- task :coverage do |t|
15
- ENV['SIMPLE_COV'] = '1'
16
- Rake::Task["spec"].invoke
17
- end
18
-
19
- desc 'Generate YARD document'
20
- YARD::Rake::YardocTask.new(:doc) do |t|
21
- t.files = ['lib/msgpack/version.rb','doclib/**/*.rb']
22
- t.options = []
23
- t.options << '--debug' << '--verbose' if $trace
24
- end
25
-
26
- spec = eval File.read("msgpack.gemspec")
27
-
28
- if RUBY_PLATFORM =~ /java/
29
- require 'rake/javaextensiontask'
30
-
31
- Rake::JavaExtensionTask.new('msgpack', spec) do |ext|
32
- ext.ext_dir = 'ext/java'
33
- jruby_home = RbConfig::CONFIG['prefix']
34
- jars = ["#{jruby_home}/lib/jruby.jar"]
35
- ext.classpath = jars.map { |x| File.expand_path(x) }.join(':')
36
- ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
37
- ext.release = '8'
38
- end
39
- else
40
- require 'rake/extensiontask'
41
-
42
- Rake::ExtensionTask.new('msgpack', spec) do |ext|
43
- ext.ext_dir = 'ext/msgpack'
44
- ext.cross_compile = true
45
- ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
46
- # cross_platform names are of MRI's platform name
47
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
48
- end
49
- end
50
-
51
- test_pattern = case
52
- when RUBY_PLATFORM =~ /java/ then 'spec/{,jruby/}*_spec.rb'
53
- when RUBY_ENGINE =~ /rbx/ then 'spec/*_spec.rb'
54
- else 'spec/{,cruby/}*_spec.rb' # MRI
55
- end
56
- RSpec::Core::RakeTask.new(:spec) do |t|
57
- t.rspec_opts = ["-c", "-f progress"]
58
- t.rspec_opts << "-Ilib"
59
- t.pattern = test_pattern
60
- t.verbose = true
61
- end
62
-
63
- namespace :build do
64
- desc 'Build gem for JRuby after cleaning'
65
- task :java => [:clean, :spec, :build]
66
- end
67
-
68
- CLEAN.include('lib/msgpack/msgpack.*')
69
-
70
- task :default => [:spec, :build, :doc]
data/appveyor.yml DELETED
@@ -1,18 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake -rdevkit
10
-
11
- environment:
12
- matrix:
13
- - ruby_version: "200"
14
- - ruby_version: "200-x64"
15
- - ruby_version: "21"
16
- - ruby_version: "21-x64"
17
- - ruby_version: "22"
18
- - ruby_version: "22-x64"
data/bench/bench.rb DELETED
@@ -1,78 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
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__)