msgpack 1.2.10 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yaml +57 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop.yml +4 -1
  5. data/ChangeLog +60 -0
  6. data/Gemfile +3 -0
  7. data/README.md +264 -0
  8. data/Rakefile +1 -9
  9. data/doclib/msgpack/factory.rb +47 -3
  10. data/doclib/msgpack/packer.rb +5 -4
  11. data/doclib/msgpack/time.rb +22 -0
  12. data/doclib/msgpack/timestamp.rb +44 -0
  13. data/doclib/msgpack/unpacker.rb +2 -2
  14. data/ext/java/org/msgpack/jruby/Buffer.java +23 -16
  15. data/ext/java/org/msgpack/jruby/Decoder.java +46 -23
  16. data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
  17. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +37 -49
  18. data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
  19. data/ext/java/org/msgpack/jruby/Factory.java +47 -7
  20. data/ext/java/org/msgpack/jruby/Packer.java +29 -17
  21. data/ext/java/org/msgpack/jruby/Unpacker.java +72 -37
  22. data/ext/msgpack/buffer.c +4 -16
  23. data/ext/msgpack/buffer.h +46 -5
  24. data/ext/msgpack/buffer_class.c +23 -15
  25. data/ext/msgpack/compat.h +1 -12
  26. data/ext/msgpack/extconf.rb +39 -7
  27. data/ext/msgpack/factory_class.c +87 -20
  28. data/ext/msgpack/packer.c +58 -8
  29. data/ext/msgpack/packer.h +24 -16
  30. data/ext/msgpack/packer_class.c +29 -31
  31. data/ext/msgpack/packer_ext_registry.c +22 -30
  32. data/ext/msgpack/packer_ext_registry.h +38 -31
  33. data/ext/msgpack/unpacker.c +102 -70
  34. data/ext/msgpack/unpacker.h +10 -2
  35. data/ext/msgpack/unpacker_class.c +35 -52
  36. data/ext/msgpack/unpacker_ext_registry.c +40 -16
  37. data/ext/msgpack/unpacker_ext_registry.h +21 -14
  38. data/lib/msgpack/bigint.rb +69 -0
  39. data/lib/msgpack/factory.rb +103 -0
  40. data/lib/msgpack/symbol.rb +21 -4
  41. data/lib/msgpack/time.rb +29 -0
  42. data/lib/msgpack/timestamp.rb +76 -0
  43. data/lib/msgpack/version.rb +4 -7
  44. data/lib/msgpack.rb +8 -12
  45. data/msgpack.gemspec +3 -7
  46. data/spec/bigint_spec.rb +26 -0
  47. data/spec/factory_spec.rb +299 -12
  48. data/spec/msgpack_spec.rb +1 -1
  49. data/spec/packer_spec.rb +18 -0
  50. data/spec/spec_helper.rb +30 -3
  51. data/spec/timestamp_spec.rb +159 -0
  52. data/spec/unpacker_spec.rb +135 -4
  53. metadata +21 -51
  54. data/.travis.yml +0 -43
  55. data/README.rdoc +0 -209
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d969c236941c85e4262f6584ce00a47ff4cdbaeb3d6e7eb6b557ffa02fb4e251
4
- data.tar.gz: 888a6a2392eb3f9a4cc0a2856b47e6b1f969b6dd94ff1d3904d402a4ed376a05
3
+ metadata.gz: 2c5ae461c691018c21ea088c4b629510c0626a31c16e640d7128d1d4be70276a
4
+ data.tar.gz: 32ac330fedeb8fdcf90e172df4480d05564185ef9b3e72f430c83de04eea90b1
5
5
  SHA512:
6
- metadata.gz: 5878a395788cab9c9fc3eec25d5390bcf10c87cf60b0785ce5f25a2a74b868f50861367b8884af11f3003a416a4e8eb420d32629955c36366da3e3e455e0a9d8
7
- data.tar.gz: c6e029cd6ef240337bdf5918e996ddf8ce97d2f903f1c915adf5a5b9a8973bfe5cbbc225330a83bd29cd928107a86d8d70d9094417105a8aa574a3e02f546b00
6
+ metadata.gz: 2a5a1c96cbfdc2030c38cf559a61aaacc466a5b4fcaaa6af809b8d062f3042a44ee6df0f731fe77bbdf1ebba0a123da2b9db033e7117baabcc6e9664dd6f56ef
7
+ data.tar.gz: 07c313bd70f92996b0131a0c5ce9836f025dd4fa98fdbe365ad04fa860b2bd6ca81c62fbd90cc2296a75eddd2a9b648b3ca48b8838a40ffab72a5845dfd6e724
@@ -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
+ jruby:
29
+ strategy:
30
+ fail-fast: false
31
+ matrix:
32
+ os: [ubuntu]
33
+ ruby: ['jruby-9.2.19.0', 'jruby-9.3.3.0']
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
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', 'truffleruby']
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 || echo "failed, but ignore it"
data/.gitignore CHANGED
@@ -18,4 +18,6 @@ tmp
18
18
  .project
19
19
  .settings
20
20
  /nbproject/private/
21
-
21
+ coverage/
22
+ .idea/
23
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -5,6 +5,9 @@
5
5
  # Note that changes in the inspected code, or installation of new
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
+ AllCops:
9
+ TargetRubyVersion: 2.4
10
+
8
11
  # Offense count: 3
9
12
  Lint/AmbiguousOperator:
10
13
  Enabled: false
@@ -15,7 +18,7 @@ Lint/AssignmentInCondition:
15
18
  Enabled: false
16
19
 
17
20
  # Offense count: 1
18
- Lint/Eval:
21
+ Security/Eval:
19
22
  Enabled: false
20
23
 
21
24
  # Offense count: 3
data/ChangeLog CHANGED
@@ -1,3 +1,63 @@
1
+ 2022-04-07 version 1.5.1:
2
+
3
+ * Fix bug about packing/unpacking ext type objects with the recursive option
4
+
5
+ 2022-04-06 version 1.5.0:
6
+
7
+ * Add recursive option on Factory#register_type to operate Packer/Unpacker manually
8
+ * Add oversized_integer_extension option on Factory#register_type to pack/unpack bigint using ext types
9
+ * Add Factory#pool method and Factory::Pool class to provide pooled Packer and Unpacker instances
10
+
11
+ 2022-02-15 version 1.4.5:
12
+
13
+ * Fix to create UTF-8 Symbol keys when symbolize_keys: true
14
+ * Fix to assume Symbols as US-ASCII or UTF-8
15
+ * Optimize Packer/Unpacker initialization
16
+ * Optimize extension class lookup
17
+ * Rename Packer#clear as Packer#reset (#clear is still available as an alias)
18
+
19
+ 2022-01-22 version 1.4.4:
20
+
21
+ * Specify the build option --platform=8 for older Java platforms
22
+
23
+ 2022-01-20 version 1.4.3:
24
+
25
+ * Optimize serialization/deserialization of Symbols
26
+ * Support registering ext types for objects of subclasses of primitive types (like Hash)
27
+ * Add optimized_symbols_parsing option to Factory#register_type on MRI implementation
28
+ * Optimize to deduplicate Hash keys on JRuby
29
+ * Support JRuby 9.3 (and drop 9.1)
30
+
31
+ 2021-02-01 version 1.4.2:
32
+
33
+ * Add the required Ruby version (>= 2.4) to avoid compilation errors on older Ruby runtimes
34
+ * Drop the support of old Ruby versions explicitly (1.8, 1.9, 2.0, 2.1, 2.2, 2.3)
35
+
36
+ 2021-01-27 version 1.4.1:
37
+
38
+ * Bugfix about the wrong string encoding longer than 256 bytes (#200)
39
+
40
+ 2021-01-27 version 1.4.0:
41
+
42
+ * Introduce the optimization to use frozen/deduped keys for map objects
43
+ * Stop releasing fat gem (pre-built binaries) for mswin32 arch environments
44
+
45
+ 2020-02-05 version 1.3.3:
46
+
47
+ * Hotfix release for Windows environments: 1.3.2 missed including binaries
48
+
49
+ 2020-02-04 version 1.3.2:
50
+
51
+ * Add Ruby 2.7.0 binary in gem releases for Windows
52
+
53
+ 2019-08-05 version 1.3.1:
54
+
55
+ * Fix timestamp ext type bug about timestamps with seconds larger than 32bit int (after 2106-02-07 06:28:16 UTC)
56
+
57
+ 2019-06-20 verison 1.3.0:
58
+
59
+ * Add timestamp ext type (id:-1) support
60
+
1
61
  2019-04-19 version 1.2.10:
2
62
 
3
63
  * Optimze MessagePack.unpack not to copy source string
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ gemspec
4
4
 
5
5
  ## enable this line to run benchmarks
6
6
  # gem "viiite"
7
+
8
+ gem "rubocop", "~> 0.82.0"
9
+ gem "simplecov"
data/README.md ADDED
@@ -0,0 +1,264 @@
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 is 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
+ ```
55
+
56
+ ### Streaming serialization
57
+
58
+ Packer provides advanced API to serialize objects in streaming style:
59
+
60
+ ```ruby
61
+ # serialize a 2-element array [e1, e2]
62
+ pk = MessagePack::Packer.new(io)
63
+ pk.write_array_header(2).write(e1).write(e2).flush
64
+ ```
65
+
66
+ See [API reference](http://ruby.msgpack.org/MessagePack/Packer.html) for details.
67
+
68
+ ## Deserializing objects
69
+
70
+ Use `MessagePack.unpack`:
71
+
72
+ ```ruby
73
+ require 'msgpack'
74
+ obj = MessagePack.unpack(msg)
75
+ ```
76
+
77
+ ### Streaming deserialization
78
+
79
+ Unpacker provides advanced API to deserialize objects in streaming style:
80
+
81
+ ```ruby
82
+ # deserialize objects from an IO
83
+ u = MessagePack::Unpacker.new(io)
84
+ u.each do |obj|
85
+ # ...
86
+ end
87
+ ```
88
+
89
+ or event-driven style which works well with EventMachine:
90
+
91
+ ```ruby
92
+ # event-driven deserialization
93
+ def on_read(data)
94
+ @u ||= MessagePack::Unpacker.new
95
+ @u.feed_each(data) {|obj|
96
+ # ...
97
+ }
98
+ end
99
+ ```
100
+
101
+ See [API reference](http://ruby.msgpack.org/MessagePack/Unpacker.html) for details.
102
+
103
+ ## Serializing and deserializing symbols
104
+
105
+ By default, symbols are serialized as strings:
106
+
107
+ ```ruby
108
+ packed = :symbol.to_msgpack # => "\xA6symbol"
109
+ MessagePack.unpack(packed) # => "symbol"
110
+ ```
111
+
112
+ This can be customized by registering an extension type for them:
113
+
114
+ ```ruby
115
+ MessagePack::DefaultFactory.register_type(0x00, Symbol)
116
+
117
+ # symbols now survive round trips
118
+ packed = :symbol.to_msgpack # => "\xc7\x06\x00symbol"
119
+ MessagePack.unpack(packed) # => :symbol
120
+ ```
121
+
122
+ The extension type for symbols is configurable like any other extension type.
123
+ For example, to customize how symbols are packed you can just redefine
124
+ Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from
125
+ being serialized altogether by throwing an exception:
126
+
127
+ ```ruby
128
+ class Symbol
129
+ def to_msgpack_ext
130
+ raise "Serialization of symbols prohibited"
131
+ end
132
+ end
133
+
134
+ MessagePack::DefaultFactory.register_type(0x00, Symbol)
135
+
136
+ [1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited
137
+ ```
138
+
139
+ ## Serializing and deserializing Time instances
140
+
141
+ There are the timestamp extension type in MessagePack,
142
+ but it is not registered by default.
143
+
144
+ To map Ruby's Time to MessagePack's timestamp for the default factory:
145
+
146
+ ```ruby
147
+ MessagePack::DefaultFactory.register_type(
148
+ MessagePack::Timestamp::TYPE, # or just -1
149
+ Time,
150
+ packer: MessagePack::Time::Packer,
151
+ unpacker: MessagePack::Time::Unpacker
152
+ )
153
+ ```
154
+
155
+ See [API reference](http://ruby.msgpack.org/) for details.
156
+
157
+ ## Extension Types
158
+
159
+ Packer and Unpacker support [Extension types of MessagePack](https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type).
160
+
161
+ ```ruby
162
+ # register how to serialize custom class at first
163
+ pk = MessagePack::Packer.new(io)
164
+ pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass)
165
+ pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available
166
+
167
+ # almost same API for unpacker
168
+ uk = MessagePack::Unpacker.new()
169
+ uk.register_type(0x01, MyClass1, :from_msgpack_ext)
170
+ uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }
171
+ ```
172
+
173
+ `MessagePack::Factory` is to create packer and unpacker which have same extension types.
174
+
175
+ ```ruby
176
+ factory = MessagePack::Factory.new
177
+ factory.register_type(0x01, MyClass1) # same with next line
178
+ factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
179
+ pk = factory.packer(options_for_packer)
180
+ uk = factory.unpacker(options_for_unpacker)
181
+ ```
182
+
183
+ For `MessagePack.pack` and `MessagePack.unpack`, default packer/unpacker refer `MessagePack::DefaultFactory`. Call `MessagePack::DefaultFactory.register_type` to enable types process globally.
184
+
185
+ ```ruby
186
+ MessagePack::DefaultFactory.register_type(0x03, MyClass3)
187
+ MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance
188
+ ```
189
+
190
+ Alternatively, extension types can call the packer or unpacker recursively to generate the extension data:
191
+
192
+ ```ruby
193
+ Point = Struct.new(:x, :y)
194
+ factory = MessagePack::Factory.new
195
+ factory.register_type(
196
+ 0x01,
197
+ Point,
198
+ packer: ->(point, packer) {
199
+ packer.write(point.x)
200
+ packer.write(point.y)
201
+ },
202
+ unpacker: ->(unpacker) {
203
+ x = unpacker.read
204
+ y = unpacker.read
205
+ Point.new(x, y)
206
+ },
207
+ recursive: true,
208
+ )
209
+ factory.load(factory.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34>
210
+ ```
211
+
212
+ ## Buffer API
213
+
214
+ MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
215
+
216
+ 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),
217
+ and has zero-copy capability which significantly affects performance to handle large binary data.
218
+
219
+ ## How to build and run tests
220
+
221
+ Before building msgpack, you need to install bundler and dependencies.
222
+
223
+ gem install bundler
224
+ bundle install
225
+
226
+ Then, you can run the tasks as follows:
227
+
228
+ ### Build
229
+
230
+ bundle exec rake build
231
+
232
+ ### Run tests
233
+
234
+ bundle exec rake spec
235
+
236
+ ### Generating docs
237
+
238
+ bundle exec rake doc
239
+
240
+ ## How to build -java rubygems
241
+
242
+ To build -java gems for JRuby, run:
243
+
244
+ rake build:java
245
+
246
+ If this directory has Gemfile.lock (generated with MRI), remove it beforehand.
247
+
248
+ ## Updating documents
249
+
250
+ Online documents (http://ruby.msgpack.org) is generated from gh-pages branch.
251
+ Following commands update documents in gh-pages branch:
252
+
253
+ bundle exec rake doc
254
+ git checkout gh-pages
255
+ cp doc/* ./ -a
256
+
257
+ ## Copyright
258
+
259
+ * Author
260
+ * Sadayuki Furuhashi <frsyuki@gmail.com>
261
+ * Copyright
262
+ * Copyright (c) 2008-2015 Sadayuki Furuhashi
263
+ * License
264
+ * 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'
73
- end
74
66
  end
75
67
 
76
68
  CLEAN.include('lib/msgpack/msgpack.*')
@@ -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.
@@ -0,0 +1,22 @@
1
+ module MessagePack
2
+
3
+ # MessagePack::Time provides packer and unpacker functions for a timestamp type.
4
+ # @example Setup for DefaultFactory
5
+ # MessagePack::DefaultFactory.register_type(
6
+ # MessagePack::Timestamp::TYPE,
7
+ # Time,
8
+ # packer: MessagePack::Time::Packer,
9
+ # unpacker: MessagePack::Time::Unpacker
10
+ # )
11
+ class Time
12
+ # A packer function that packs a Time instance to a MessagePack timestamp.
13
+ Packer = lambda { |payload|
14
+ # ...
15
+ }
16
+
17
+ # An unpacker function that unpacks a MessagePack timestamp to a Time instance.
18
+ Unpacker = lambda { |time|
19
+ # ...
20
+ }
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ module MessagePack
2
+ # A utility class for MessagePack timestamp type
3
+ class Timestamp
4
+ #
5
+ # The timestamp extension type defined in the MessagePack spec.
6
+ #
7
+ # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details.
8
+ #
9
+ TYPE = -1
10
+
11
+ # @return [Integer] Second part of the timestamp.
12
+ attr_reader :sec
13
+
14
+ # @return [Integer] Nanosecond part of the timestamp.
15
+ attr_reader :nsec
16
+
17
+ # @param [Integer] sec
18
+ # @param [Integer] nsec
19
+ def initialize(sec, nsec)
20
+ end
21
+
22
+ # @example An unpacker implementation for the Time class
23
+ # lambda do |payload|
24
+ # tv = MessagePack::Timestamp.from_msgpack_ext(payload)
25
+ # Time.at(tv.sec, tv.nsec, :nanosecond)
26
+ # end
27
+ #
28
+ # @param [String] data
29
+ # @return [MessagePack::Timestamp]
30
+ def self.from_msgpack_ext(data)
31
+ end
32
+
33
+ # @example A packer implementation for the Time class
34
+ # unpacker = lambda do |time|
35
+ # MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
36
+ # end
37
+ #
38
+ # @param [Integer] sec
39
+ # @param [Integer] nsec
40
+ # @return [String]
41
+ def self.to_msgpack_ext(sec, nsec)
42
+ end
43
+ end
44
+ end
@@ -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.