msgpack 1.2.6 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) 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 +59 -0
  6. data/Gemfile +3 -0
  7. data/README.md +242 -0
  8. data/Rakefile +3 -8
  9. data/doclib/msgpack/factory.rb +1 -0
  10. data/doclib/msgpack/packer.rb +20 -0
  11. data/doclib/msgpack/time.rb +22 -0
  12. data/doclib/msgpack/timestamp.rb +44 -0
  13. data/doclib/msgpack.rb +2 -2
  14. data/ext/java/org/msgpack/jruby/Buffer.java +21 -16
  15. data/ext/java/org/msgpack/jruby/Decoder.java +29 -10
  16. data/ext/java/org/msgpack/jruby/Encoder.java +38 -19
  17. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +9 -9
  18. data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
  19. data/ext/java/org/msgpack/jruby/Factory.java +8 -3
  20. data/ext/java/org/msgpack/jruby/Packer.java +31 -8
  21. data/ext/java/org/msgpack/jruby/Unpacker.java +40 -27
  22. data/ext/msgpack/buffer.c +4 -16
  23. data/ext/msgpack/buffer.h +60 -5
  24. data/ext/msgpack/compat.h +1 -12
  25. data/ext/msgpack/extconf.rb +39 -7
  26. data/ext/msgpack/factory_class.c +10 -5
  27. data/ext/msgpack/packer.c +18 -5
  28. data/ext/msgpack/packer.h +0 -16
  29. data/ext/msgpack/packer_class.c +21 -9
  30. data/ext/msgpack/packer_ext_registry.c +0 -22
  31. data/ext/msgpack/unpacker.c +41 -49
  32. data/ext/msgpack/unpacker.h +8 -0
  33. data/ext/msgpack/unpacker_class.c +23 -13
  34. data/lib/msgpack/symbol.rb +14 -4
  35. data/lib/msgpack/time.rb +29 -0
  36. data/lib/msgpack/timestamp.rb +76 -0
  37. data/lib/msgpack/version.rb +4 -7
  38. data/lib/msgpack.rb +8 -10
  39. data/msgpack.gemspec +3 -7
  40. data/spec/cruby/buffer_spec.rb +6 -1
  41. data/spec/factory_spec.rb +17 -0
  42. data/spec/msgpack_spec.rb +44 -1
  43. data/spec/packer_spec.rb +54 -0
  44. data/spec/spec_helper.rb +27 -0
  45. data/spec/timestamp_spec.rb +161 -0
  46. data/spec/unpacker_spec.rb +113 -1
  47. metadata +19 -51
  48. data/.travis.yml +0 -41
  49. data/README.rdoc +0 -201
data/README.rdoc DELETED
@@ -1,201 +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 -mingw32 rubygems
180
-
181
- MessagePack mingw32/64 rubygems build process uses {rake-compiler-dock}[https://github.com/rake-compiler/rake-compiler-dock]. Run:
182
-
183
- rake build:windows
184
-
185
- Once this step successes, target gems exist in pkg/msgpack-*-{x86,x64}-mingw32.gem.
186
-
187
- == Updating documents
188
-
189
- Online documents (http://ruby.msgpack.org) is generated from gh-pages branch.
190
- Following commands update documents in gh-pages branch:
191
-
192
- bundle exec rake doc
193
- git checkout gh-pages
194
- cp doc/* ./ -a
195
-
196
- = Copyright
197
-
198
- Author:: Sadayuki Furuhashi <frsyuki@gmail.com>
199
- Copyright:: Copyright (c) 2008-2015 Sadayuki Furuhashi
200
- License:: Apache License, Version 2.0
201
-