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/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
|
data/doclib/msgpack/time.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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
|
data/doclib/msgpack/timestamp.rb
DELETED
@@ -1,44 +0,0 @@
|
|
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
|
data/doclib/msgpack/unpacker.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
module MessagePack
|
2
|
-
|
3
|
-
#
|
4
|
-
# MessagePack::Unpacker is a class to deserialize objects.
|
5
|
-
#
|
6
|
-
class Unpacker
|
7
|
-
#
|
8
|
-
# Creates a MessagePack::Unpacker instance.
|
9
|
-
#
|
10
|
-
# @overload initialize(options={})
|
11
|
-
# @param options [Hash]
|
12
|
-
#
|
13
|
-
# @overload initialize(io, options={})
|
14
|
-
# @param io [IO]
|
15
|
-
# @param options [Hash]
|
16
|
-
# This unpacker reads data from the _io_ to fill the internal buffer.
|
17
|
-
# _io_ must respond to readpartial(length [,string]) or read(length [,string]) method.
|
18
|
-
#
|
19
|
-
# Supported options:
|
20
|
-
#
|
21
|
-
# * *:symbolize_keys* deserialize keys of Hash objects as Symbol instead of String
|
22
|
-
# * *:allow_unknown_ext* allow to deserialize ext type object with unknown type id as ExtensionValue instance. Otherwise (by default), unpacker throws UnknownExtTypeError.
|
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 deserialize it. This method should be called with
|
31
|
-
# Class and its class method name, or block, which returns a instance object.
|
32
|
-
#
|
33
|
-
# @overload register_type(type, &block)
|
34
|
-
# @param type [Fixnum] type id (0-127) user defined type id for specified deserializer block
|
35
|
-
# @yieldparam data [String] bytes(ASCII-8BIT String) represents serialized object, to be deserialized
|
36
|
-
#
|
37
|
-
# @overload register_type(type, klass, class_method_name)
|
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
|
40
|
-
# @param class_method_name [Symbol] class method which returns an instance object
|
41
|
-
#
|
42
|
-
# @return nil
|
43
|
-
#
|
44
|
-
def register_type(type, klass, method_name, &block)
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Returns a list of registered types, ordered by type id.
|
49
|
-
# Each element is a Hash object includes keys :type, :class and :unpacker.
|
50
|
-
#
|
51
|
-
# @return Array
|
52
|
-
#
|
53
|
-
def registered_types
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# Returns true/false which indicate specified class or type id is registered or not.
|
58
|
-
#
|
59
|
-
# @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked
|
60
|
-
# @return true or false
|
61
|
-
#
|
62
|
-
def type_registered?(klass_or_type)
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Internal buffer
|
67
|
-
#
|
68
|
-
# @return [MessagePack::Buffer]
|
69
|
-
#
|
70
|
-
attr_reader :buffer
|
71
|
-
|
72
|
-
#
|
73
|
-
# Deserializes an object from the io or internal buffer and returns it.
|
74
|
-
#
|
75
|
-
# This method reads data from io into the internal buffer and deserializes an object
|
76
|
-
# from the buffer. It repeats reading data from the io until enough data is available
|
77
|
-
# to deserialize at least one object. After deserializing one object, unused data is
|
78
|
-
# left in the internal buffer.
|
79
|
-
#
|
80
|
-
# If there're not enough data to deserialize one object, this method raises EOFError.
|
81
|
-
# If data format is invalid, this method raises MessagePack::MalformedFormatError.
|
82
|
-
# If the object nests too deeply, this method raises MessagePack::StackError.
|
83
|
-
#
|
84
|
-
# @return [Object] deserialized object
|
85
|
-
#
|
86
|
-
def read
|
87
|
-
end
|
88
|
-
|
89
|
-
alias unpack read
|
90
|
-
|
91
|
-
#
|
92
|
-
# Deserializes an object and ignores it. This method is faster than _read_.
|
93
|
-
#
|
94
|
-
# This method could raise the same errors with _read_.
|
95
|
-
#
|
96
|
-
# @return nil
|
97
|
-
#
|
98
|
-
def skip
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Deserializes a nil value if it exists and returns _true_.
|
103
|
-
# Otherwise, if a byte exists but the byte doesn't represent nil value,
|
104
|
-
# returns _false_.
|
105
|
-
#
|
106
|
-
# If there're not enough data, this method raises EOFError.
|
107
|
-
#
|
108
|
-
# @return [Boolean]
|
109
|
-
#
|
110
|
-
def skip_nil
|
111
|
-
end
|
112
|
-
|
113
|
-
#
|
114
|
-
# Read a header of an array and returns its size.
|
115
|
-
# It converts a serialized array into a stream of elements.
|
116
|
-
#
|
117
|
-
# If the serialized object is not an array, it raises MessagePack::UnexpectedTypeError.
|
118
|
-
# If there're not enough data, this method raises EOFError.
|
119
|
-
#
|
120
|
-
# @return [Integer] size of the array
|
121
|
-
#
|
122
|
-
def read_array_header
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# Reads a header of an map and returns its size.
|
127
|
-
# It converts a serialized map into a stream of key-value pairs.
|
128
|
-
#
|
129
|
-
# If the serialized object is not a map, it raises MessagePack::UnexpectedTypeError.
|
130
|
-
# If there're not enough data, this method raises EOFError.
|
131
|
-
#
|
132
|
-
# @return [Integer] size of the map
|
133
|
-
#
|
134
|
-
def read_map_header
|
135
|
-
end
|
136
|
-
|
137
|
-
#
|
138
|
-
# Appends data into the internal buffer.
|
139
|
-
# This method is equivalent to unpacker.buffer.append(data).
|
140
|
-
#
|
141
|
-
# @param data [String]
|
142
|
-
# @return [Unpacker] self
|
143
|
-
#
|
144
|
-
def feed(data)
|
145
|
-
end
|
146
|
-
|
147
|
-
#
|
148
|
-
# Repeats to deserialize objects.
|
149
|
-
#
|
150
|
-
# It repeats until the io or internal buffer does not include any complete objects.
|
151
|
-
#
|
152
|
-
# If the an IO is set, it repeats to read data from the IO when the buffer
|
153
|
-
# becomes empty until the IO raises EOFError.
|
154
|
-
#
|
155
|
-
# This method could raise same errors with _read_ excepting EOFError.
|
156
|
-
#
|
157
|
-
# @yieldparam object [Object] deserialized object
|
158
|
-
# @return nil
|
159
|
-
#
|
160
|
-
def each(&block)
|
161
|
-
end
|
162
|
-
|
163
|
-
#
|
164
|
-
# Appends data into the internal buffer and repeats to deserialize objects.
|
165
|
-
# This method is equivalent to unpacker.feed(data) && unpacker.each { ... }.
|
166
|
-
#
|
167
|
-
# @param data [String]
|
168
|
-
# @yieldparam object [Object] deserialized object
|
169
|
-
# @return nil
|
170
|
-
#
|
171
|
-
def feed_each(data, &block)
|
172
|
-
end
|
173
|
-
|
174
|
-
#
|
175
|
-
# Clears the internal buffer and resets deserialization state of the unpacker.
|
176
|
-
#
|
177
|
-
# @return nil
|
178
|
-
#
|
179
|
-
def reset
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|