msgpack 1.3.3 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +99 -0
- data/README.md +293 -0
- data/ext/java/org/msgpack/jruby/Buffer.java +26 -19
- data/ext/java/org/msgpack/jruby/Decoder.java +46 -23
- 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 +86 -68
- data/ext/msgpack/buffer.c +58 -85
- data/ext/msgpack/buffer.h +59 -20
- data/ext/msgpack/buffer_class.c +161 -52
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/compat.h +1 -111
- data/ext/msgpack/extconf.rb +41 -23
- data/ext/msgpack/factory_class.c +143 -87
- data/ext/msgpack/packer.c +66 -43
- data/ext/msgpack/packer.h +25 -27
- 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 +130 -126
- data/ext/msgpack/unpacker.h +22 -13
- data/ext/msgpack/unpacker_class.c +94 -124
- 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 +4 -8
- data/lib/msgpack.rb +7 -12
- data/msgpack.gemspec +9 -8
- metadata +37 -96
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/.travis.yml +0 -43
- data/Gemfile +0 -9
- data/README.rdoc +0 -225
- data/Rakefile +0 -78
- 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 -38
- data/spec/timestamp_spec.rb +0 -121
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -716
data/bench/unpack_log_long.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# viiite report --regroup bench,threads bench/pack_log_long.rb
|
2
|
-
|
3
|
-
require 'viiite'
|
4
|
-
require 'msgpack'
|
5
|
-
|
6
|
-
data_plain = MessagePack.pack({
|
7
|
-
'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)"'
|
8
|
-
})
|
9
|
-
data_structure = MessagePack.pack({
|
10
|
-
'remote_host' => '127.0.0.1',
|
11
|
-
'remote_user' => '-',
|
12
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
13
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
14
|
-
'method' => 'GET',
|
15
|
-
'path' => '/apache_pb.gif',
|
16
|
-
'protocol' => 'HTTP/1.0',
|
17
|
-
'status' => 200,
|
18
|
-
'bytes' => 2326,
|
19
|
-
'referer' => 'http://www.example.com/start.html',
|
20
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
21
|
-
})
|
22
|
-
|
23
|
-
seconds = 3600 # 1 hour
|
24
|
-
|
25
|
-
Viiite.bench do |b|
|
26
|
-
b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
|
27
|
-
b.report(:plain) do
|
28
|
-
ths = []
|
29
|
-
end_at = Time.now + seconds
|
30
|
-
threads.times do
|
31
|
-
t = Thread.new do
|
32
|
-
packs = 0
|
33
|
-
while Time.now < end_at
|
34
|
-
10000.times do
|
35
|
-
MessagePack.unpack(data_plain)
|
36
|
-
end
|
37
|
-
packs += 10000
|
38
|
-
end
|
39
|
-
packs
|
40
|
-
end
|
41
|
-
ths.push t
|
42
|
-
end
|
43
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
44
|
-
puts "MessagePack.unpack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
45
|
-
end
|
46
|
-
|
47
|
-
b.report(:structure) do
|
48
|
-
ths = []
|
49
|
-
end_at = Time.now + seconds
|
50
|
-
threads.times do
|
51
|
-
t = Thread.new do
|
52
|
-
packs = 0
|
53
|
-
while Time.now < end_at
|
54
|
-
10000.times do
|
55
|
-
MessagePack.unpack(data_structure)
|
56
|
-
end
|
57
|
-
packs += 10000
|
58
|
-
end
|
59
|
-
packs
|
60
|
-
end
|
61
|
-
ths.push t
|
62
|
-
end
|
63
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
64
|
-
puts "MessagePack.unpack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/doclib/msgpack/buffer.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
|
3
|
-
class Buffer
|
4
|
-
#
|
5
|
-
# Creates a MessagePack::Buffer instance.
|
6
|
-
#
|
7
|
-
# @overload initialize(options={})
|
8
|
-
# @param options [Hash]
|
9
|
-
#
|
10
|
-
# @overload initialize(io, options={})
|
11
|
-
# @param io [IO]
|
12
|
-
# @param options [Hash]
|
13
|
-
# This buffer writes written data into the IO when it is filled.
|
14
|
-
# This buffer reads data from the IO when it is empty.
|
15
|
-
#
|
16
|
-
# _io_ must respond to readpartial(length, [,string]) or read(string) method and
|
17
|
-
# write(string) or append(string) method.
|
18
|
-
#
|
19
|
-
# Supported options:
|
20
|
-
#
|
21
|
-
# * *:io_buffer_size* buffer size to read data from the internal IO. (default: 32768)
|
22
|
-
# * *:read_reference_threshold* the threshold size to enable zero-copy deserialize optimization. Read strings longer than this threshold will refer the original string instead of copying it. (default: 256) (supported in MRI only)
|
23
|
-
# * *:write_reference_threshold* the threshold size to enable zero-copy serialize optimization. The buffer refers written strings longer than this threshold instead of copying it. (default: 524288) (supported in MRI only)
|
24
|
-
#
|
25
|
-
def initialize(*args)
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Makes the buffer empty
|
30
|
-
#
|
31
|
-
# @return nil
|
32
|
-
#
|
33
|
-
def clear
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# Returns byte size of the buffer.
|
38
|
-
#
|
39
|
-
# @return nil
|
40
|
-
#
|
41
|
-
def size
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Returns _true_ if the buffer is empty.
|
46
|
-
# This method is slightly faster than _size_.
|
47
|
-
#
|
48
|
-
# @return [Boolean]
|
49
|
-
#
|
50
|
-
def empty?
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Appends the given data to the buffer.
|
55
|
-
#
|
56
|
-
# @param data [String]
|
57
|
-
# @return [Integer] byte size written
|
58
|
-
#
|
59
|
-
def write(data)
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Appends the given data to the buffer.
|
64
|
-
#
|
65
|
-
# @param data [String]
|
66
|
-
# @return [Buffer] self
|
67
|
-
#
|
68
|
-
def <<(data)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Consumes _n_ bytes from the head of the buffer and returns consumed data.
|
73
|
-
# If the size of the buffer is less than _n_, it reads all of data in the buffer.
|
74
|
-
#
|
75
|
-
# If _n_ is 0, it does nothing and returns an empty string.
|
76
|
-
# If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
|
77
|
-
#
|
78
|
-
# @overload read
|
79
|
-
#
|
80
|
-
# @overload read(n)
|
81
|
-
# @param n [Integer] bytes to read
|
82
|
-
#
|
83
|
-
# @overload read(n, buffer)
|
84
|
-
# @param n [Integer] bytes to read
|
85
|
-
# @param buffer [String] buffer to read into
|
86
|
-
#
|
87
|
-
# @return [String]
|
88
|
-
#
|
89
|
-
def read(n)
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Consumes _n_ bytes from the head of the buffer and returns consumed data.
|
94
|
-
# If the size of the buffer is less than _n_, it does nothing and raises EOFError.
|
95
|
-
#
|
96
|
-
# If _n_ is 0, it does nothing and returns an empty string.
|
97
|
-
# If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
|
98
|
-
#
|
99
|
-
# @overload read_all
|
100
|
-
#
|
101
|
-
# @overload read_all(n)
|
102
|
-
# @param n [Integer] bytes to read
|
103
|
-
#
|
104
|
-
# @overload read_all(n, buffer)
|
105
|
-
# @param n [Integer] bytes to read
|
106
|
-
# @param buffer [String] buffer to read into
|
107
|
-
#
|
108
|
-
# @return [String]
|
109
|
-
#
|
110
|
-
def read_all(n, buffer=nil)
|
111
|
-
end
|
112
|
-
|
113
|
-
#
|
114
|
-
# Consumes _n_ bytes from the head of the buffer.
|
115
|
-
# If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_.
|
116
|
-
#
|
117
|
-
# If _n_ is 0, it does nothing and returns _0_.
|
118
|
-
#
|
119
|
-
# @param n [Integer] byte size to skip
|
120
|
-
# @return [Integer] byte size actually skipped
|
121
|
-
#
|
122
|
-
def skip(n)
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# Consumes _n_ bytes from the head of the buffer.
|
127
|
-
# If the size of the buffer is less than _n_, it does nothing and raises EOFError.
|
128
|
-
# If _n_ is 0, it does nothing.
|
129
|
-
#
|
130
|
-
# @param n [Integer] byte size to skip
|
131
|
-
# @return [Buffer] self
|
132
|
-
#
|
133
|
-
def skip_all(n)
|
134
|
-
end
|
135
|
-
|
136
|
-
#
|
137
|
-
# Returns all data in the buffer as a string.
|
138
|
-
# Destructive update to the returned string does NOT effect the buffer.
|
139
|
-
#
|
140
|
-
# @return [String]
|
141
|
-
#
|
142
|
-
def to_str
|
143
|
-
end
|
144
|
-
|
145
|
-
#
|
146
|
-
# Returns content of the buffer as an array of strings.
|
147
|
-
#
|
148
|
-
# This method is sometimes faster than to_s because the internal
|
149
|
-
# structure of the buffer is a queue of buffer chunks.
|
150
|
-
#
|
151
|
-
# @return [Array] array of strings
|
152
|
-
#
|
153
|
-
def to_a
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Internal io
|
158
|
-
#
|
159
|
-
# @return IO
|
160
|
-
#
|
161
|
-
attr_reader :io
|
162
|
-
|
163
|
-
#
|
164
|
-
# Flushes data in the internal buffer to the internal IO.
|
165
|
-
# If internal IO is not set, it does nothing.
|
166
|
-
#
|
167
|
-
# @return [Buffer] self
|
168
|
-
#
|
169
|
-
def flush
|
170
|
-
end
|
171
|
-
|
172
|
-
#
|
173
|
-
# Closes internal IO if its set.
|
174
|
-
# If internal IO is not set, it does nothing
|
175
|
-
#
|
176
|
-
# @return nil
|
177
|
-
#
|
178
|
-
def close
|
179
|
-
end
|
180
|
-
|
181
|
-
#
|
182
|
-
# Writes all of data in the internal buffer into the given IO.
|
183
|
-
# This method consumes and removes data from the internal buffer.
|
184
|
-
# _io_ must respond to write(data) method.
|
185
|
-
#
|
186
|
-
# @param io [IO]
|
187
|
-
# @return [Integer] byte size of written data
|
188
|
-
#
|
189
|
-
def write_to(io)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
data/doclib/msgpack/core_ext.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
|
2
|
-
class NilClass
|
3
|
-
#
|
4
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
5
|
-
#
|
6
|
-
# @return [String] serialized data
|
7
|
-
#
|
8
|
-
def to_msgpack(packer=nil)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class TrueClass
|
13
|
-
#
|
14
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
15
|
-
#
|
16
|
-
# @return [String] serialized data
|
17
|
-
#
|
18
|
-
def to_msgpack(packer=nil)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class FalseClass
|
23
|
-
#
|
24
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
25
|
-
#
|
26
|
-
# @return [String] serialized data
|
27
|
-
#
|
28
|
-
def to_msgpack(packer=nil)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Fixnum < Integer
|
33
|
-
#
|
34
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
35
|
-
#
|
36
|
-
# @return [String] serialized data
|
37
|
-
#
|
38
|
-
def to_msgpack(packer=nil)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class Bignum < Integer
|
43
|
-
#
|
44
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
45
|
-
#
|
46
|
-
# @return [String] serialized data
|
47
|
-
#
|
48
|
-
def to_msgpack(packer=nil)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Float < Numeric
|
53
|
-
#
|
54
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
55
|
-
#
|
56
|
-
# @return [String] serialized data
|
57
|
-
#
|
58
|
-
def to_msgpack(packer=nil)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class String
|
63
|
-
#
|
64
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
65
|
-
#
|
66
|
-
# @return [String] serialized data
|
67
|
-
#
|
68
|
-
def to_msgpack(packer=nil)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class Array
|
73
|
-
#
|
74
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
75
|
-
#
|
76
|
-
# @return [String] serialized data
|
77
|
-
#
|
78
|
-
def to_msgpack(packer=nil)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class Hash
|
83
|
-
#
|
84
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
85
|
-
#
|
86
|
-
# @return [String] serialized data
|
87
|
-
#
|
88
|
-
def to_msgpack(packer=nil)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class Symbol
|
93
|
-
#
|
94
|
-
# Same as MessagePack.to_msgpack(self[, packer]).
|
95
|
-
#
|
96
|
-
# @return [String] serialized data
|
97
|
-
#
|
98
|
-
def to_msgpack(packer=nil)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
data/doclib/msgpack/error.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
|
3
|
-
class UnpackError < StandardError
|
4
|
-
end
|
5
|
-
|
6
|
-
class MalformedFormatError < UnpackError
|
7
|
-
end
|
8
|
-
|
9
|
-
class StackError < UnpackError
|
10
|
-
end
|
11
|
-
|
12
|
-
class UnexpectedTypeError < UnpackError
|
13
|
-
include TypeError
|
14
|
-
end
|
15
|
-
|
16
|
-
class UnknownExtTypeError < UnpackError
|
17
|
-
include TypeError
|
18
|
-
end
|
19
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
|
3
|
-
#
|
4
|
-
# MessagePack::ExtensionValue is a struct to represent unknown ext type object.
|
5
|
-
# Its contents are accessed by type and payload (messagepack bytes representation) methods.
|
6
|
-
# And it is extended to add to_msgpack object.
|
7
|
-
#
|
8
|
-
ExtensionValue = Struct.new(:type, :payload)
|
9
|
-
end
|
data/doclib/msgpack/factory.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
#
|
3
|
-
# MessagePack::Factory is a class to generate Packer and Unpacker which has
|
4
|
-
# same set of ext types.
|
5
|
-
#
|
6
|
-
class Factory
|
7
|
-
#
|
8
|
-
# Creates a MessagePack::Factory instance
|
9
|
-
#
|
10
|
-
def initialize
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
# Creates a MessagePack::Packer instance, which has ext types already registered.
|
15
|
-
# Options are passed to MessagePack::Packer#initialized.
|
16
|
-
#
|
17
|
-
# See also Packer#initialize for options.
|
18
|
-
#
|
19
|
-
def packer(*args)
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Serialize the passed value
|
24
|
-
#
|
25
|
-
# If it could not serialize the object, it raises
|
26
|
-
# NoMethodError: undefined method `to_msgpack' for #<the_object>.
|
27
|
-
#
|
28
|
-
# @param obj [Object] object to serialize
|
29
|
-
# @param options [Hash]
|
30
|
-
# @return [String] serialized object
|
31
|
-
#
|
32
|
-
# See Packer#initialize for supported options.
|
33
|
-
#
|
34
|
-
def dump(obj, options={})
|
35
|
-
end
|
36
|
-
alias pack dump
|
37
|
-
|
38
|
-
#
|
39
|
-
# Creates a MessagePack::Unpacker instance, which has ext types already registered.
|
40
|
-
# Options are passed to MessagePack::Unpacker#initialized.
|
41
|
-
#
|
42
|
-
# See also Unpacker#initialize for options.
|
43
|
-
#
|
44
|
-
def unpacker(*args)
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Deserializes an object from the string or io and returns it.
|
49
|
-
#
|
50
|
-
# If there're not enough data to deserialize one object, this method raises EOFError.
|
51
|
-
# If data format is invalid, this method raises MessagePack::MalformedFormatError.
|
52
|
-
# If the object nests too deeply, this method raises MessagePack::StackError.
|
53
|
-
#
|
54
|
-
# @param data [String]
|
55
|
-
# @param options [Hash]
|
56
|
-
# @return [Object] deserialized object
|
57
|
-
#
|
58
|
-
# See Unpacker#initialize for supported options.
|
59
|
-
#
|
60
|
-
def load(data, options={})
|
61
|
-
end
|
62
|
-
alias unpack load
|
63
|
-
|
64
|
-
#
|
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
|
67
|
-
# :from_msgpack_ext for unpacker.
|
68
|
-
#
|
69
|
-
# @param type [Fixnum] type id of registered Class (0-127)
|
70
|
-
# @param klass [Class] Class to be associated with type id
|
71
|
-
# @param options [Hash] specify method name or Proc which are used by packer/unpacker
|
72
|
-
# @return nil
|
73
|
-
#
|
74
|
-
# Supported options:
|
75
|
-
#
|
76
|
-
# * *:packer* specify symbol or proc object for packer
|
77
|
-
# * *:unpacker* specify symbol or proc object for unpacker
|
78
|
-
#
|
79
|
-
def register_type(type, klass, options={})
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Returns a list of registered types, ordered by type id.
|
84
|
-
#
|
85
|
-
# @param selector [Symbol] specify to list types registered for :packer, :unpacker or :both (default)
|
86
|
-
# @return Array
|
87
|
-
#
|
88
|
-
def registered_types(selector=:both)
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# Returns true/false which indicate specified class or type id is registered or not.
|
93
|
-
#
|
94
|
-
# @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked
|
95
|
-
# @param selector [Symbol] specify to check for :packer, :unpacker or :both (default)
|
96
|
-
# @return true or false
|
97
|
-
#
|
98
|
-
def type_registered?(klass_or_type, selector=:both)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/doclib/msgpack/packer.rb
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
|
3
|
-
#
|
4
|
-
# MessagePack::Packer is a class to serialize objects.
|
5
|
-
#
|
6
|
-
class Packer
|
7
|
-
#
|
8
|
-
# Creates a MessagePack::Packer instance.
|
9
|
-
# See Buffer#initialize for supported options.
|
10
|
-
#
|
11
|
-
# @overload initialize(options={})
|
12
|
-
# @param options [Hash]
|
13
|
-
#
|
14
|
-
# @overload initialize(io, options={})
|
15
|
-
# @param io [IO]
|
16
|
-
# @param options [Hash]
|
17
|
-
# This packer writes serialzied objects into the IO when the internal buffer is filled.
|
18
|
-
# _io_ must respond to write(string) or append(string) method.
|
19
|
-
#
|
20
|
-
# Supported options:
|
21
|
-
#
|
22
|
-
# * *:compatibility_mode* serialize in older versions way, without str8 and bin types
|
23
|
-
#
|
24
|
-
# See also Buffer#initialize for other options.
|
25
|
-
#
|
26
|
-
def initialize(*args)
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# Register a new ext type to serialize it. This method should be called with one of
|
31
|
-
# method name or block, which returns bytes(ASCII-8BIT String) representation of
|
32
|
-
# object to be serialized.
|
33
|
-
#
|
34
|
-
# @overload register_type(type, klass, &block)
|
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
|
37
|
-
# @yieldparam object [Object] object to be serialized
|
38
|
-
#
|
39
|
-
# @overload register_type(type, klass, method_name)
|
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
|
42
|
-
# @param method_name [Symbol] method which returns bytes of serialized representation
|
43
|
-
#
|
44
|
-
# @return nil
|
45
|
-
#
|
46
|
-
def register_type(type, klass, method_name, &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# Returns a list of registered types, ordered by type id.
|
51
|
-
# Each element is a Hash object includes keys :type, :class and :packer.
|
52
|
-
#
|
53
|
-
# @return Array
|
54
|
-
#
|
55
|
-
def registered_types
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# Returns true/false which indicate specified class or type id is registered or not.
|
60
|
-
#
|
61
|
-
# @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked
|
62
|
-
# @return true or false
|
63
|
-
#
|
64
|
-
def type_registered?(klass_or_type)
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# Internal buffer
|
69
|
-
#
|
70
|
-
# @return MessagePack::Buffer
|
71
|
-
#
|
72
|
-
attr_reader :buffer
|
73
|
-
|
74
|
-
#
|
75
|
-
# Serializes an object into internal buffer, and flushes to io if necessary.
|
76
|
-
#
|
77
|
-
# If it could not serialize the object, it raises
|
78
|
-
# NoMethodError: undefined method `to_msgpack' for #<the_object>.
|
79
|
-
#
|
80
|
-
# @param obj [Object] object to serialize
|
81
|
-
# @return [Packer] self
|
82
|
-
#
|
83
|
-
def write(obj)
|
84
|
-
end
|
85
|
-
|
86
|
-
alias pack write
|
87
|
-
|
88
|
-
#
|
89
|
-
# Serializes a nil object. Same as write(nil).
|
90
|
-
#
|
91
|
-
def write_nil
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# Serializes a string object as binary data. Same as write("string".encode(Encoding::BINARY)).
|
96
|
-
#
|
97
|
-
def write_bin(obj)
|
98
|
-
end
|
99
|
-
|
100
|
-
#
|
101
|
-
# Write a header of an array whose size is _n_.
|
102
|
-
# For example, write_array_header(1).write(true) is same as write([ true ]).
|
103
|
-
#
|
104
|
-
# @return [Packer] self
|
105
|
-
#
|
106
|
-
def write_array_header(n)
|
107
|
-
end
|
108
|
-
|
109
|
-
#
|
110
|
-
# Write a header of an map whose size is _n_.
|
111
|
-
# For example, write_map_header(1).write('key').write(true) is same as write('key'=>true).
|
112
|
-
#
|
113
|
-
# @return [Packer] self
|
114
|
-
#
|
115
|
-
def write_map_header(n)
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
# Write a header of a binary string whose size is _n_. Useful if you want to append large binary data without loading it into memory at once.
|
120
|
-
# For example,
|
121
|
-
# MessagePack::Packer.new(io).write_bin_header(12).flush
|
122
|
-
# io.write('chunk1')
|
123
|
-
# io.write('chunk2')
|
124
|
-
# is the same as
|
125
|
-
# write('chunk1chunk2'.encode(Encoding::BINARY)).
|
126
|
-
#
|
127
|
-
# @return [Packer] self
|
128
|
-
#
|
129
|
-
def write_bin_header(n)
|
130
|
-
end
|
131
|
-
|
132
|
-
#
|
133
|
-
# Serializes _value_ as 32-bit single precision float into internal buffer.
|
134
|
-
# _value_ will be approximated with the nearest possible single precision float, thus
|
135
|
-
# being potentially lossy. However, the serialized string will only take up 5 bytes
|
136
|
-
# instead of 9 bytes compared to directly serializing a 64-bit double precision Ruby Float.
|
137
|
-
#
|
138
|
-
# @param value [Numeric]
|
139
|
-
# @return [Packer] self
|
140
|
-
#
|
141
|
-
def write_float32(value)
|
142
|
-
end
|
143
|
-
|
144
|
-
#
|
145
|
-
# Flushes data in the internal buffer to the internal IO. Same as _buffer.flush.
|
146
|
-
# If internal IO is not set, it does nothing.
|
147
|
-
#
|
148
|
-
# @return [Packer] self
|
149
|
-
#
|
150
|
-
def flush
|
151
|
-
end
|
152
|
-
|
153
|
-
#
|
154
|
-
# Makes the internal buffer empty. Same as _buffer.clear_.
|
155
|
-
#
|
156
|
-
# @return nil
|
157
|
-
#
|
158
|
-
def clear
|
159
|
-
end
|
160
|
-
|
161
|
-
#
|
162
|
-
# Returns size of the internal buffer. Same as buffer.size.
|
163
|
-
#
|
164
|
-
# @return [Integer]
|
165
|
-
#
|
166
|
-
def size
|
167
|
-
end
|
168
|
-
|
169
|
-
#
|
170
|
-
# Returns _true_ if the internal buffer is empty. Same as buffer.empty?.
|
171
|
-
# This method is slightly faster than _size_.
|
172
|
-
#
|
173
|
-
# @return [Boolean]
|
174
|
-
#
|
175
|
-
def empty?
|
176
|
-
end
|
177
|
-
|
178
|
-
#
|
179
|
-
# Returns all data in the buffer as a string. Same as buffer.to_str.
|
180
|
-
#
|
181
|
-
# @return [String]
|
182
|
-
#
|
183
|
-
def to_str
|
184
|
-
end
|
185
|
-
|
186
|
-
alias to_s to_str
|
187
|
-
|
188
|
-
#
|
189
|
-
# Returns content of the internal buffer as an array of strings. Same as buffer.to_a.
|
190
|
-
# This method is faster than _to_str_.
|
191
|
-
#
|
192
|
-
# @return [Array] array of strings
|
193
|
-
#
|
194
|
-
def to_a
|
195
|
-
end
|
196
|
-
|
197
|
-
#
|
198
|
-
# Writes all of data in the internal buffer into the given IO. Same as buffer.write_to(io).
|
199
|
-
# This method consumes and removes data from the internal buffer.
|
200
|
-
# _io_ must respond to write(data) method.
|
201
|
-
#
|
202
|
-
# @param io [IO]
|
203
|
-
# @return [Integer] byte size of written data
|
204
|
-
#
|
205
|
-
def write_to(io)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|