msgpack 1.4.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +89 -0
- data/README.md +73 -13
- data/ext/java/org/msgpack/jruby/Buffer.java +26 -19
- data/ext/java/org/msgpack/jruby/Decoder.java +29 -21
- data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +43 -64
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +6 -9
- data/ext/java/org/msgpack/jruby/Factory.java +43 -42
- data/ext/java/org/msgpack/jruby/Packer.java +37 -40
- data/ext/java/org/msgpack/jruby/Unpacker.java +80 -73
- data/ext/msgpack/buffer.c +54 -74
- data/ext/msgpack/buffer.h +21 -18
- data/ext/msgpack/buffer_class.c +161 -52
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/compat.h +0 -99
- data/ext/msgpack/extconf.rb +25 -46
- data/ext/msgpack/factory_class.c +143 -87
- data/ext/msgpack/packer.c +66 -43
- data/ext/msgpack/packer.h +25 -20
- data/ext/msgpack/packer_class.c +102 -130
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +35 -40
- data/ext/msgpack/packer_ext_registry.h +41 -38
- data/ext/msgpack/rbinit.c +1 -1
- data/ext/msgpack/rmem.c +3 -4
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +136 -111
- data/ext/msgpack/unpacker.h +16 -13
- data/ext/msgpack/unpacker_class.c +86 -126
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +40 -28
- data/ext/msgpack/unpacker_ext_registry.h +21 -18
- data/lib/msgpack/bigint.rb +69 -0
- data/lib/msgpack/buffer.rb +9 -0
- data/lib/msgpack/factory.rb +140 -10
- data/lib/msgpack/packer.rb +10 -1
- data/lib/msgpack/symbol.rb +21 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/unpacker.rb +14 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +6 -7
- data/msgpack.gemspec +8 -5
- metadata +37 -82
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/.travis.yml +0 -39
- data/Gemfile +0 -9
- data/Rakefile +0 -71
- data/appveyor.yml +0 -18
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
- data/doclib/msgpack/buffer.rb +0 -193
- data/doclib/msgpack/core_ext.rb +0 -101
- data/doclib/msgpack/error.rb +0 -19
- data/doclib/msgpack/extension_value.rb +0 -9
- data/doclib/msgpack/factory.rb +0 -101
- data/doclib/msgpack/packer.rb +0 -208
- data/doclib/msgpack/time.rb +0 -22
- data/doclib/msgpack/timestamp.rb +0 -44
- data/doclib/msgpack/unpacker.rb +0 -183
- data/doclib/msgpack.rb +0 -87
- data/msgpack.org.md +0 -46
- data/spec/cases.json +0 -1
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +0 -39
- data/spec/cruby/buffer_io_spec.rb +0 -255
- data/spec/cruby/buffer_packer.rb +0 -29
- data/spec/cruby/buffer_spec.rb +0 -575
- data/spec/cruby/buffer_unpacker.rb +0 -19
- data/spec/cruby/unpacker_spec.rb +0 -70
- data/spec/ext_value_spec.rb +0 -99
- data/spec/exttypes.rb +0 -51
- data/spec/factory_spec.rb +0 -367
- data/spec/format_spec.rb +0 -301
- data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
- data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
- data/spec/jruby/unpacker_spec.rb +0 -186
- data/spec/msgpack_spec.rb +0 -214
- data/spec/pack_spec.rb +0 -61
- data/spec/packer_spec.rb +0 -557
- data/spec/random_compat.rb +0 -24
- data/spec/spec_helper.rb +0 -55
- data/spec/timestamp_spec.rb +0 -121
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -819
data/doclib/msgpack.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
|
2
|
-
module MessagePack
|
3
|
-
#
|
4
|
-
# Serializes an object into an IO or String.
|
5
|
-
#
|
6
|
-
# @overload dump(obj, options={})
|
7
|
-
# @param obj [Object] object to be serialized
|
8
|
-
# @param options [Hash]
|
9
|
-
# @return [String] serialized data
|
10
|
-
#
|
11
|
-
# @overload dump(obj, io, options={})
|
12
|
-
# @param obj [Object] object to be serialized
|
13
|
-
# @param io [IO]
|
14
|
-
# @param options [Hash]
|
15
|
-
# @return [nil]
|
16
|
-
#
|
17
|
-
# See Packer#initialize for supported options.
|
18
|
-
#
|
19
|
-
def self.dump(obj)
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Serializes an object into an IO or String. Alias of dump.
|
24
|
-
#
|
25
|
-
# @overload pack(obj, options={})
|
26
|
-
# @param obj [Object] object to be serialized
|
27
|
-
# @param options [Hash]
|
28
|
-
# @return [String] serialized data
|
29
|
-
#
|
30
|
-
# @overload pack(obj, io, options={})
|
31
|
-
# @param obj [Object] object to be serialized
|
32
|
-
# @param io [IO]
|
33
|
-
# @param options [Hash]
|
34
|
-
# @return [nil]
|
35
|
-
#
|
36
|
-
# See Packer#initialize for supported options.
|
37
|
-
#
|
38
|
-
def self.pack(obj)
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Deserializes an object from an IO or String.
|
43
|
-
#
|
44
|
-
# @overload load(string, options={})
|
45
|
-
# @param string [String] data to deserialize
|
46
|
-
# @param options [Hash]
|
47
|
-
#
|
48
|
-
# @overload load(io, options={})
|
49
|
-
# @param io [IO]
|
50
|
-
# @param options [Hash]
|
51
|
-
#
|
52
|
-
# @return [Object] deserialized object
|
53
|
-
#
|
54
|
-
# See Unpacker#initialize for supported options.
|
55
|
-
#
|
56
|
-
def self.load(src, options={})
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Deserializes an object from an IO or String. Alias of load.
|
61
|
-
#
|
62
|
-
# @overload unpack(string, options={})
|
63
|
-
# @param string [String] data to deserialize
|
64
|
-
# @param options [Hash]
|
65
|
-
#
|
66
|
-
# @overload unpack(io, options={})
|
67
|
-
# @param io [IO]
|
68
|
-
# @param options [Hash]
|
69
|
-
#
|
70
|
-
# @return [Object] deserialized object
|
71
|
-
#
|
72
|
-
# See Unpacker#initialize for supported options.
|
73
|
-
#
|
74
|
-
def self.unpack(src, options={})
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
# An instance of Factory class. DefaultFactory is also used
|
79
|
-
# by global pack/unpack methods such as MessagePack.dump/load,
|
80
|
-
# Hash#to_msgpack, and other to_msgpack methods.
|
81
|
-
#
|
82
|
-
# Calling DefaultFactory.register_type lets you add an extension
|
83
|
-
# type globally.
|
84
|
-
#
|
85
|
-
DefaultFactory = Factory.new
|
86
|
-
end
|
87
|
-
|
data/msgpack.org.md
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# MessagePack for Ruby
|
2
|
-
|
3
|
-
```
|
4
|
-
require 'msgpack'
|
5
|
-
msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
|
6
|
-
MessagePack.unpack(msg) #=> [1,2,3]
|
7
|
-
```
|
8
|
-
|
9
|
-
## Install
|
10
|
-
|
11
|
-
```
|
12
|
-
gem install msgpack
|
13
|
-
```
|
14
|
-
|
15
|
-
## Use cases
|
16
|
-
|
17
|
-
* Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl)
|
18
|
-
* Store objects efficiently in memcached or Redis
|
19
|
-
* Upload data in efficient format from mobile devices. See also MessagePack for [Objective-C](https://github.com/msgpack/msgpack-objectivec) and [Java](https://github.com/msgpack/msgpack-java)
|
20
|
-
|
21
|
-
## Links
|
22
|
-
|
23
|
-
* [Github](https://github.com/msgpack/msgpack-ruby)
|
24
|
-
* [API document](http://ruby.msgpack.org/)
|
25
|
-
|
26
|
-
## Streaming API
|
27
|
-
|
28
|
-
```
|
29
|
-
# serialize a 2-element array [e1, e2]
|
30
|
-
pk = MessagePack::Packer.new(io)
|
31
|
-
pk.write_array_header(2).write(e1).write(e2).flush
|
32
|
-
```
|
33
|
-
|
34
|
-
```
|
35
|
-
# deserialize objects from an IO
|
36
|
-
u = MessagePack::Unpacker.new(io)
|
37
|
-
u.each { |obj| ... }
|
38
|
-
```
|
39
|
-
|
40
|
-
```
|
41
|
-
# event-driven deserialization
|
42
|
-
def on_read(data)
|
43
|
-
@u ||= MessagePack::Unpacker.new
|
44
|
-
@u.feed_each(data) { |obj| ... }
|
45
|
-
end
|
46
|
-
```
|
data/spec/cases.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,127,127,255,65535,4294967295,-32,-32,-128,-32768,-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",[0],[0],[0],[],[],[],{},{},{},{"a":97},{"a":97},{"a":97},[[]],[["a"]]]
|
data/spec/cases.msg
DELETED
Binary file
|
data/spec/cases_compact.msg
DELETED
Binary file
|
data/spec/cases_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
describe MessagePack do
|
5
|
-
here = File.dirname(__FILE__)
|
6
|
-
CASES = File.read("#{here}/cases.msg")
|
7
|
-
CASES_JSON = File.read("#{here}/cases.json")
|
8
|
-
CASES_COMPACT = File.read("#{here}/cases_compact.msg")
|
9
|
-
|
10
|
-
it 'compare with json' do
|
11
|
-
ms = []
|
12
|
-
MessagePack::Unpacker.new.feed_each(CASES) {|m|
|
13
|
-
ms << m
|
14
|
-
}
|
15
|
-
|
16
|
-
js = JSON.load(CASES_JSON)
|
17
|
-
|
18
|
-
ms.zip(js) {|m,j|
|
19
|
-
m.should == j
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'compare with compat' do
|
24
|
-
ms = []
|
25
|
-
MessagePack::Unpacker.new.feed_each(CASES) {|m|
|
26
|
-
ms << m
|
27
|
-
}
|
28
|
-
|
29
|
-
cs = []
|
30
|
-
MessagePack::Unpacker.new.feed_each(CASES_COMPACT) {|c|
|
31
|
-
cs << c
|
32
|
-
}
|
33
|
-
|
34
|
-
ms.zip(cs) {|m,c|
|
35
|
-
m.should == c
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
@@ -1,255 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'random_compat'
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
if defined?(Encoding)
|
6
|
-
Encoding.default_external = 'ASCII-8BIT'
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Buffer do
|
10
|
-
r = Random.new
|
11
|
-
random_seed = r.seed
|
12
|
-
puts "buffer_io random seed: 0x#{random_seed.to_s(16)}"
|
13
|
-
|
14
|
-
let :source do
|
15
|
-
''
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_source(s)
|
19
|
-
source.replace(s)
|
20
|
-
end
|
21
|
-
|
22
|
-
let :io do
|
23
|
-
StringIO.new(source.dup)
|
24
|
-
end
|
25
|
-
|
26
|
-
let :buffer do
|
27
|
-
Buffer.new(io)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'io returns internal io' do
|
31
|
-
buffer.io.should == io
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'close closes internal io' do
|
35
|
-
expect(io).to receive(:close)
|
36
|
-
buffer.close
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'short feed and read all' do
|
40
|
-
set_source 'aa'
|
41
|
-
buffer.read.should == 'aa'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'short feed and read short' do
|
45
|
-
set_source 'aa'
|
46
|
-
buffer.read(1).should == 'a'
|
47
|
-
buffer.read(1).should == 'a'
|
48
|
-
buffer.read(1).should == nil
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'long feed and read all' do
|
52
|
-
set_source ' '*(1024*1024)
|
53
|
-
s = buffer.read
|
54
|
-
s.size.should == source.size
|
55
|
-
s.should == source
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'long feed and read mixed' do
|
59
|
-
set_source ' '*(1024*1024)
|
60
|
-
buffer.read(10).should == source.slice!(0, 10)
|
61
|
-
buffer.read(10).should == source.slice!(0, 10)
|
62
|
-
buffer.read(10).should == source.slice!(0, 10)
|
63
|
-
s = buffer.read
|
64
|
-
s.size.should == source.size
|
65
|
-
s.should == source
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'eof' do
|
69
|
-
set_source ''
|
70
|
-
buffer.read.should == ''
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'eof 2' do
|
74
|
-
set_source 'a'
|
75
|
-
buffer.read.should == 'a'
|
76
|
-
buffer.read.should == ''
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'write short once and flush' do
|
80
|
-
buffer.write('aa')
|
81
|
-
buffer.flush
|
82
|
-
io.string.should == 'aa'
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'write short twice and flush' do
|
86
|
-
buffer.write('a')
|
87
|
-
buffer.write('a')
|
88
|
-
buffer.flush
|
89
|
-
io.string.should == 'aa'
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'write long once and flush' do
|
93
|
-
s = ' '*(1024*1024)
|
94
|
-
buffer.write s
|
95
|
-
buffer.flush
|
96
|
-
io.string.size.should == s.size
|
97
|
-
io.string.should == s
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'write short multi and flush' do
|
101
|
-
s = ' '*(1024*1024)
|
102
|
-
1024.times {
|
103
|
-
buffer.write ' '*1024
|
104
|
-
}
|
105
|
-
buffer.flush
|
106
|
-
io.string.size.should == s.size
|
107
|
-
io.string.should == s
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'random read' do
|
111
|
-
r = Random.new(random_seed)
|
112
|
-
|
113
|
-
50.times {
|
114
|
-
fragments = []
|
115
|
-
|
116
|
-
r.rand(4).times do
|
117
|
-
n = r.rand(1024*1400)
|
118
|
-
s = r.bytes(n)
|
119
|
-
fragments << s
|
120
|
-
end
|
121
|
-
|
122
|
-
io = StringIO.new(fragments.join)
|
123
|
-
b = Buffer.new(io)
|
124
|
-
|
125
|
-
fragments.each {|s|
|
126
|
-
x = b.read(s.size)
|
127
|
-
x.size.should == s.size
|
128
|
-
x.should == s
|
129
|
-
}
|
130
|
-
b.empty?.should == true
|
131
|
-
b.read.should == ''
|
132
|
-
}
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'random read_all' do
|
136
|
-
r = Random.new(random_seed)
|
137
|
-
|
138
|
-
50.times {
|
139
|
-
fragments = []
|
140
|
-
r.bytes(0)
|
141
|
-
|
142
|
-
r.rand(4).times do
|
143
|
-
n = r.rand(1024*1400)
|
144
|
-
s = r.bytes(n)
|
145
|
-
fragments << s
|
146
|
-
end
|
147
|
-
|
148
|
-
io = StringIO.new(fragments.join)
|
149
|
-
b = Buffer.new(io)
|
150
|
-
|
151
|
-
fragments.each {|s|
|
152
|
-
x = b.read_all(s.size)
|
153
|
-
x.size.should == s.size
|
154
|
-
x.should == s
|
155
|
-
}
|
156
|
-
b.empty?.should == true
|
157
|
-
lambda {
|
158
|
-
b.read_all(1)
|
159
|
-
}.should raise_error(EOFError)
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'random skip' do
|
164
|
-
r = Random.new(random_seed)
|
165
|
-
|
166
|
-
50.times {
|
167
|
-
fragments = []
|
168
|
-
|
169
|
-
r.rand(4).times do
|
170
|
-
n = r.rand(1024*1400)
|
171
|
-
s = r.bytes(n)
|
172
|
-
fragments << s
|
173
|
-
end
|
174
|
-
|
175
|
-
io = StringIO.new(fragments.join)
|
176
|
-
b = Buffer.new(io)
|
177
|
-
|
178
|
-
fragments.each {|s|
|
179
|
-
b.skip(s.size).should == s.size
|
180
|
-
}
|
181
|
-
b.empty?.should == true
|
182
|
-
b.skip(1).should == 0
|
183
|
-
}
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'random skip_all' do
|
187
|
-
r = Random.new(random_seed)
|
188
|
-
|
189
|
-
50.times {
|
190
|
-
fragments = []
|
191
|
-
|
192
|
-
r.rand(4).times do
|
193
|
-
n = r.rand(1024*1400)
|
194
|
-
s = r.bytes(n)
|
195
|
-
fragments << s
|
196
|
-
end
|
197
|
-
|
198
|
-
io = StringIO.new(fragments.join)
|
199
|
-
b = Buffer.new(io)
|
200
|
-
|
201
|
-
fragments.each {|s|
|
202
|
-
lambda {
|
203
|
-
b.skip_all(s.size)
|
204
|
-
}.should_not raise_error
|
205
|
-
}
|
206
|
-
b.empty?.should == true
|
207
|
-
lambda {
|
208
|
-
b.skip_all(1)
|
209
|
-
}.should raise_error(EOFError)
|
210
|
-
}
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'random write and flush' do
|
214
|
-
r = Random.new(random_seed)
|
215
|
-
|
216
|
-
50.times {
|
217
|
-
s = r.bytes(0)
|
218
|
-
io = StringIO.new
|
219
|
-
b = Buffer.new(io)
|
220
|
-
|
221
|
-
r.rand(4).times do
|
222
|
-
n = r.rand(1024*1400)
|
223
|
-
x = r.bytes(n)
|
224
|
-
s << x
|
225
|
-
b.write(x)
|
226
|
-
end
|
227
|
-
|
228
|
-
(io.string.size + b.size).should == s.size
|
229
|
-
|
230
|
-
b.flush
|
231
|
-
|
232
|
-
io.string.size.should == s.size
|
233
|
-
io.string.should == s
|
234
|
-
}
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'random write and clear' do
|
238
|
-
r = Random.new(random_seed)
|
239
|
-
b = Buffer.new
|
240
|
-
|
241
|
-
50.times {
|
242
|
-
s = r.bytes(0)
|
243
|
-
|
244
|
-
r.rand(4).times do
|
245
|
-
n = r.rand(1024*1400)
|
246
|
-
x = r.bytes(n)
|
247
|
-
s << x
|
248
|
-
b.write(x)
|
249
|
-
end
|
250
|
-
|
251
|
-
b.size.should == s.size
|
252
|
-
b.clear
|
253
|
-
}
|
254
|
-
end
|
255
|
-
end
|
data/spec/cruby/buffer_packer.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
if defined?(Encoding)
|
6
|
-
Encoding.default_external = 'ASCII-8BIT'
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Packer do
|
10
|
-
let :packer do
|
11
|
-
Packer.new
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'initialize' do
|
15
|
-
Packer.new
|
16
|
-
Packer.new(nil)
|
17
|
-
Packer.new(StringIO.new)
|
18
|
-
Packer.new({})
|
19
|
-
Packer.new(StringIO.new, {})
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'buffer' do
|
23
|
-
o1 = packer.buffer.object_id
|
24
|
-
packer.buffer << 'frsyuki'
|
25
|
-
packer.buffer.to_s.should == 'frsyuki'
|
26
|
-
packer.buffer.object_id.should == o1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|