msgpack 0.7.4 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +27 -14
  5. data/ChangeLog +89 -1
  6. data/Gemfile +6 -1
  7. data/README.rdoc +55 -1
  8. data/Rakefile +5 -1
  9. data/bench/pack_symbols.rb +28 -0
  10. data/bench/run_symbols.sh +26 -0
  11. data/doclib/msgpack.rb +2 -2
  12. data/doclib/msgpack/core_ext.rb +20 -20
  13. data/doclib/msgpack/factory.rb +33 -0
  14. data/doclib/msgpack/packer.rb +20 -0
  15. data/doclib/msgpack/time.rb +22 -0
  16. data/doclib/msgpack/timestamp.rb +44 -0
  17. data/ext/java/org/msgpack/jruby/Buffer.java +4 -0
  18. data/ext/java/org/msgpack/jruby/Encoder.java +48 -18
  19. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +67 -38
  20. data/ext/java/org/msgpack/jruby/Factory.java +20 -8
  21. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +0 -92
  22. data/ext/java/org/msgpack/jruby/Packer.java +114 -11
  23. data/ext/java/org/msgpack/jruby/Unpacker.java +15 -8
  24. data/ext/msgpack/buffer.h +14 -0
  25. data/ext/msgpack/buffer_class.c +1 -1
  26. data/ext/msgpack/compat.h +10 -0
  27. data/ext/msgpack/factory_class.c +24 -17
  28. data/ext/msgpack/factory_class.h +0 -2
  29. data/ext/msgpack/packer.c +5 -4
  30. data/ext/msgpack/packer.h +13 -1
  31. data/ext/msgpack/packer_class.c +130 -43
  32. data/ext/msgpack/packer_class.h +0 -2
  33. data/ext/msgpack/packer_ext_registry.c +2 -2
  34. data/ext/msgpack/packer_ext_registry.h +64 -25
  35. data/ext/msgpack/rbinit.c +0 -2
  36. data/ext/msgpack/unpacker.c +3 -3
  37. data/ext/msgpack/unpacker_class.c +25 -56
  38. data/ext/msgpack/unpacker_class.h +0 -2
  39. data/ext/msgpack/unpacker_ext_registry.c +2 -2
  40. data/ext/msgpack/unpacker_ext_registry.h +3 -3
  41. data/lib/msgpack.rb +36 -0
  42. data/lib/msgpack/core_ext.rb +139 -0
  43. data/lib/msgpack/factory.rb +21 -0
  44. data/lib/msgpack/symbol.rb +9 -0
  45. data/lib/msgpack/time.rb +29 -0
  46. data/lib/msgpack/timestamp.rb +76 -0
  47. data/lib/msgpack/version.rb +8 -1
  48. data/msgpack.gemspec +6 -7
  49. data/spec/cruby/buffer_spec.rb +6 -1
  50. data/spec/factory_spec.rb +134 -0
  51. data/spec/msgpack_spec.rb +52 -0
  52. data/spec/packer_spec.rb +200 -0
  53. data/spec/timestamp_spec.rb +121 -0
  54. data/spec/unpacker_spec.rb +29 -0
  55. metadata +29 -23
  56. data/ext/msgpack/core_ext.c +0 -144
  57. data/ext/msgpack/core_ext.h +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 452730fc6dbf9e301355b759c9f5ff7080bb88ad
4
- data.tar.gz: 7bd19e617d2298a59be2505929f0888167c39d1c
2
+ SHA256:
3
+ metadata.gz: 40d206a80a2ab99957b78f2d054417dc273933da4accf5f39a25ff4b16ec30ce
4
+ data.tar.gz: e39c06187017d057a44e71d3690662455934c2c1acafc667d49e91aaf626fbd9
5
5
  SHA512:
6
- metadata.gz: f42256792f53a9188e688222f0f44c461bdc3849614bd155f0340a48de437fde596d294341a8b30de27269c69f4ef984da40cca12c76f76c312b83d08a8bf58d
7
- data.tar.gz: eab376976af6d888b3422a25cd49a4a7dbbe9e11071a0b8ae40491700505cb10d7e5b7768fc8f459aa93e3a58d7f9fe940d0fb70e268244e76f67f3757dfad32
6
+ metadata.gz: d20c8da71f90435f264c0e1c9c90e4a5c8c09c014d33076149e6e5faa3b849ac5192d2f086b917f09eb199bcfd8cc748093d6f59e3f5fcb7c228199f549c23c5
7
+ data.tar.gz: dd5c662d5abbf45901d59a7400f2b92a6c296b2298035fecc55a31f82b19b4e9206ca3b0a7cab090d9cc9768bea015b74ad9bf5a997a763eb6ba3387b6a7fc30
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.3
10
+
8
11
  # Offense count: 3
9
12
  Lint/AmbiguousOperator:
10
13
  Enabled: false
data/.travis.yml CHANGED
@@ -1,17 +1,5 @@
1
1
  language: ruby
2
2
 
3
- rvm:
4
- - 2.0.0
5
- - 2.1.6
6
- - 2.2.2
7
- - ruby-head
8
- - jruby-19mode
9
- - jruby-head
10
-
11
- os:
12
- - linux
13
- - osx
14
-
15
3
  sudo: false
16
4
 
17
5
  branches:
@@ -21,10 +9,35 @@ branches:
21
9
  gemfile:
22
10
  - Gemfile
23
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/
24
18
  matrix:
25
- allow_failures:
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.1
27
+ os: linux
28
+ - rvm: 2.6.1
29
+ os: osx
26
30
  - rvm: ruby-head
31
+ os: linux
32
+ - rvm: jruby-9.1.9.0
33
+ os: linux
27
34
  - rvm: jruby-head
35
+ os: linux
28
36
  - rvm: jruby-19mode
37
+ os: linux
38
+ allow_failures:
39
+ - rvm: 2.6.1
29
40
  os: osx
30
- - rvm: rbx-2
41
+ - rvm: ruby-head
42
+ - rvm: jruby-head
43
+ - rvm: jruby-19mode
data/ChangeLog CHANGED
@@ -1,3 +1,91 @@
1
+ 2020-02-05 version 1.3.3:
2
+
3
+ * Hotfix release for Windows environments: 1.3.2 missed including binaries
4
+
5
+ 2020-02-04 version 1.3.2:
6
+
7
+ * Add Ruby 2.7.0 binary in gem releases for Windows
8
+
9
+ 2019-08-05 version 1.3.1:
10
+
11
+ * Fix timestamp ext type bug about timestamps with seconds larger than 32bit int (after 2106-02-07 06:28:16 UTC)
12
+
13
+ 2019-06-20 verison 1.3.0:
14
+
15
+ * Add timestamp ext type (id:-1) support
16
+
17
+ 2019-04-19 version 1.2.10:
18
+
19
+ * Optimze MessagePack.unpack not to copy source string
20
+
21
+ 2019-03-13 version 1.2.9:
22
+
23
+ * Hotfix release only for JRuby: 1.2.8-java was built incorrectly
24
+
25
+ 2019-03-11 version 1.2.8:
26
+
27
+ * Fix a regression that MessagePack#unpack raises error if IO is assigned as the (only) argument
28
+ * Improve compatibility that MessagePack#pack returns nil if IO is assigned as 2nd argument
29
+
30
+ 2019-03-01 version 1.2.7:
31
+
32
+ * Add Packer#write_bin and Packer#write_bin_header methods
33
+
34
+ 2019-01-08 verison 1.2.6:
35
+
36
+ * Update Ruby version 2.6 dependency (especially for Windows environment)
37
+ * (version 1.2.4 and 1.2.5 were also releases for updated Ruby versions)
38
+
39
+ 2018-03-02 version 1.2.3:
40
+
41
+ * Add Ruby 2.5.0 binary in gem releases for Windows
42
+
43
+ 2018-01-11 version 1.2.2:
44
+
45
+ * Fix bug to occur SEGV occasionally (depends on GC timing) when exttype is used
46
+ * Fix bug to encode an ext type with wrong type id if superclass is also registered as ext type
47
+
48
+ 2017-12-08 version 1.2.1:
49
+
50
+ * Hotfix release only for JRuby: 1.2.0-java was built in incorrect way
51
+
52
+ 2017-12-07 version 1.2.0:
53
+
54
+ * Add MessagePack::Factory#dump and MessagePack::Factory#load as convenient methods
55
+ like MessagePack.dump and MessagePack.load
56
+ * Fix bug to accept MessagePack::Factory#register_type after #freeze
57
+
58
+ 2017-02-28 version 1.1.0:
59
+
60
+ * Fix the extension type handling to accept modules in addition to classes
61
+
62
+ 2017-01-24 version 1.0.3:
63
+
64
+ * Support Ruby 2.4
65
+
66
+ 2016-10-17 version 1.0.2:
67
+
68
+ * Bump version up to release newer version to fix broken gem release for JRuby
69
+
70
+ 2016-10-17 version 1.0.1:
71
+
72
+ * Fix a bug to crash at packer when ext type is registered for superclass of packed object
73
+ * Fix JRuby implementation about inconsistent API of Unpacker constructor
74
+
75
+ 2016-07-08 version 1.0.0:
76
+
77
+ * Fix to be able to pack Symbol with ext types
78
+ * Fix for MRI 2.4 (Integer unification)
79
+
80
+ 2016-05-10 version 0.7.6:
81
+
82
+ * Fix bug to raise IndexOutOfBoundsException for Bignum value with small int in JRuby
83
+
84
+ 2016-04-06 version 0.7.5:
85
+
86
+ * Improved support for i386/armel/armhf environments
87
+ * Fix bug for negative ext type id and some architectures (arm*)
88
+
1
89
  2016-01-08 version 0.7.4:
2
90
 
3
91
  * Improved compatibility of Packer between CRuby and JRuby about argument IO-ish object values.
@@ -17,7 +105,7 @@
17
105
 
18
106
  2015-10-24 version 0.7.0:
19
107
 
20
- * Add extention types support.
108
+ * Add extension types support.
21
109
  * Fix to share almost all test cases between CRuby and JRuby implementations.
22
110
  * Fixed JRuby implementation to raise UnknownExtTypeError for unregistered ext type ids
23
111
  instead to generate MessagePack::ExtensionValue instances.
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org/'
2
2
 
3
3
  gemspec
4
- gem "viiite"
4
+
5
+ ## enable this line to run benchmarks
6
+ # gem "viiite"
7
+
8
+ gem "rubocop"
9
+ gem "simplecov"
data/README.rdoc CHANGED
@@ -91,6 +91,52 @@ or event-driven style which works well with EventMachine:
91
91
 
92
92
  See {API reference}[http://ruby.msgpack.org/MessagePack/Unpacker.html] for details.
93
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
+ = Serializing and deserializing Time instances
125
+
126
+ There are the timestamp extension type in MessagePack,
127
+ but it is not registered by default.
128
+
129
+ To map Ruby's Time to MessagePack's timestamp for the default factory:
130
+
131
+ MessagePack::DefaultFactory.register_type(
132
+ MessagePack::Timestamp::TYPE, # or just -1
133
+ Time,
134
+ packer: MessagePack::Time::Packer,
135
+ unpacker: MessagePack::Time::Unpacker
136
+ )
137
+
138
+ See {API reference}[http://ruby.msgpack.org/] for details.
139
+
94
140
  = Extension Types
95
141
 
96
142
  Packer and Unpacker support {Extension types of MessagePack}[https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type].
@@ -105,7 +151,7 @@ Packer and Unpacker support {Extension types of MessagePack}[https://github.com/
105
151
  uk.register_type(0x01, MyClass1, :from_msgpack_ext)
106
152
  uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }
107
153
 
108
- MessagePack::Factory is to create packer and unpacker which have same extention types.
154
+ MessagePack::Factory is to create packer and unpacker which have same extension types.
109
155
 
110
156
  factory = MessagePack::Factory.new
111
157
  factory.register_type(0x01, MyClass1) # same with next line
@@ -146,6 +192,14 @@ Then, you can run the tasks as follows:
146
192
 
147
193
  bundle exec rake doc
148
194
 
195
+ == How to build -java rubygems
196
+
197
+ To build -java gems for JRuby, run:
198
+
199
+ rake build:java
200
+
201
+ If this directory has Gemfile.lock (generated with MRI), remove it beforehand.
202
+
149
203
  == How to build -mingw32 rubygems
150
204
 
151
205
  MessagePack mingw32/64 rubygems build process uses {rake-compiler-dock}[https://github.com/rake-compiler/rake-compiler-dock]. Run:
data/Rakefile CHANGED
@@ -62,10 +62,14 @@ RSpec::Core::RakeTask.new(:spec) do |t|
62
62
  end
63
63
 
64
64
  namespace :build do
65
+ desc 'Build gem for JRuby after cleaning'
66
+ task :java => [:clean, :spec, :build]
67
+
65
68
  desc 'Build gems for Windows per rake-compiler-dock'
66
69
  task :windows do
67
70
  require 'rake_compiler_dock'
68
- RakeCompilerDock.sh 'bundle && rake cross native gem RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2:2.3.0'
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'
69
73
  end
70
74
  end
71
75
 
@@ -0,0 +1,28 @@
1
+ require 'viiite'
2
+ require 'msgpack'
3
+
4
+ data = :symbol
5
+
6
+ Viiite.bench do |b|
7
+ b.variation_point :branch, `git rev-parse --abbrev-ref HEAD`
8
+
9
+ b.range_over([:symbol, :none], :reg_type) do |reg_type|
10
+ packer = MessagePack::Packer.new
11
+ packer.register_type(0x00, Symbol, :to_msgpack_ext) if reg_type == :symbol
12
+
13
+ b.range_over([100_000, 1_000_000, 10_000_000], :count) do |count|
14
+ packer.clear
15
+ b.report(:multi_run) do
16
+ count.times do
17
+ packer.pack(data)
18
+ end
19
+ end
20
+
21
+ packer.clear
22
+ items_data = [].fill(data, 0, count)
23
+ b.report(:large_run) do
24
+ packer.pack(items_data)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+
3
+ # so master and this branch have the benchmark file in any case
4
+ cp bench/pack_symbols.rb bench/pack_symbols_tmp.rb
5
+
6
+ benchmark=""
7
+ current_branch=`git rev-parse --abbrev-ref HEAD`
8
+
9
+ for branch in master $current_branch; do
10
+ echo "Testing branch $branch"
11
+ git checkout $branch
12
+
13
+ echo "Installing gem..."
14
+ rake install
15
+
16
+ echo "Running benchmark..."
17
+ if [ "$benchmark" ]; then
18
+ benchmark+=$'\n'
19
+ fi
20
+ benchmark+=$(viiite run bench/pack_symbols_tmp.rb)
21
+ echo
22
+ done
23
+
24
+ rm bench/pack_symbols_tmp.rb
25
+
26
+ echo "$benchmark" | viiite report --regroup bench,reg_type,count,branch
data/doclib/msgpack.rb CHANGED
@@ -12,7 +12,7 @@ module MessagePack
12
12
  # @param obj [Object] object to be serialized
13
13
  # @param io [IO]
14
14
  # @param options [Hash]
15
- # @return [IO]
15
+ # @return [nil]
16
16
  #
17
17
  # See Packer#initialize for supported options.
18
18
  #
@@ -31,7 +31,7 @@ module MessagePack
31
31
  # @param obj [Object] object to be serialized
32
32
  # @param io [IO]
33
33
  # @param options [Hash]
34
- # @return [IO]
34
+ # @return [nil]
35
35
  #
36
36
  # See Packer#initialize for supported options.
37
37
  #
@@ -1,101 +1,101 @@
1
1
 
2
2
  class NilClass
3
3
  #
4
- # Same as MessagePack.to_msgpack(self[, io]).
4
+ # Same as MessagePack.to_msgpack(self[, packer]).
5
5
  #
6
6
  # @return [String] serialized data
7
7
  #
8
- def to_msgpack(io=nil)
8
+ def to_msgpack(packer=nil)
9
9
  end
10
10
  end
11
11
 
12
12
  class TrueClass
13
13
  #
14
- # Same as MessagePack.to_msgpack(self[, io]).
14
+ # Same as MessagePack.to_msgpack(self[, packer]).
15
15
  #
16
16
  # @return [String] serialized data
17
17
  #
18
- def to_msgpack(io=nil)
18
+ def to_msgpack(packer=nil)
19
19
  end
20
20
  end
21
21
 
22
22
  class FalseClass
23
23
  #
24
- # Same as MessagePack.to_msgpack(self[, io]).
24
+ # Same as MessagePack.to_msgpack(self[, packer]).
25
25
  #
26
26
  # @return [String] serialized data
27
27
  #
28
- def to_msgpack(io=nil)
28
+ def to_msgpack(packer=nil)
29
29
  end
30
30
  end
31
31
 
32
32
  class Fixnum < Integer
33
33
  #
34
- # Same as MessagePack.to_msgpack(self[, io]).
34
+ # Same as MessagePack.to_msgpack(self[, packer]).
35
35
  #
36
36
  # @return [String] serialized data
37
37
  #
38
- def to_msgpack(io=nil)
38
+ def to_msgpack(packer=nil)
39
39
  end
40
40
  end
41
41
 
42
42
  class Bignum < Integer
43
43
  #
44
- # Same as MessagePack.to_msgpack(self[, io]).
44
+ # Same as MessagePack.to_msgpack(self[, packer]).
45
45
  #
46
46
  # @return [String] serialized data
47
47
  #
48
- def to_msgpack(io=nil)
48
+ def to_msgpack(packer=nil)
49
49
  end
50
50
  end
51
51
 
52
52
  class Float < Numeric
53
53
  #
54
- # Same as MessagePack.to_msgpack(self[, io]).
54
+ # Same as MessagePack.to_msgpack(self[, packer]).
55
55
  #
56
56
  # @return [String] serialized data
57
57
  #
58
- def to_msgpack(io=nil)
58
+ def to_msgpack(packer=nil)
59
59
  end
60
60
  end
61
61
 
62
62
  class String
63
63
  #
64
- # Same as MessagePack.to_msgpack(self[, io]).
64
+ # Same as MessagePack.to_msgpack(self[, packer]).
65
65
  #
66
66
  # @return [String] serialized data
67
67
  #
68
- def to_msgpack(io=nil)
68
+ def to_msgpack(packer=nil)
69
69
  end
70
70
  end
71
71
 
72
72
  class Array
73
73
  #
74
- # Same as MessagePack.to_msgpack(self[, io]).
74
+ # Same as MessagePack.to_msgpack(self[, packer]).
75
75
  #
76
76
  # @return [String] serialized data
77
77
  #
78
- def to_msgpack(io=nil)
78
+ def to_msgpack(packer=nil)
79
79
  end
80
80
  end
81
81
 
82
82
  class Hash
83
83
  #
84
- # Same as MessagePack.to_msgpack(self[, io]).
84
+ # Same as MessagePack.to_msgpack(self[, packer]).
85
85
  #
86
86
  # @return [String] serialized data
87
87
  #
88
- def to_msgpack(io=nil)
88
+ def to_msgpack(packer=nil)
89
89
  end
90
90
  end
91
91
 
92
92
  class Symbol
93
93
  #
94
- # Same as MessagePack.to_msgpack(self[, io]).
94
+ # Same as MessagePack.to_msgpack(self[, packer]).
95
95
  #
96
96
  # @return [String] serialized data
97
97
  #
98
- def to_msgpack(io=nil)
98
+ def to_msgpack(packer=nil)
99
99
  end
100
100
  end
101
101