Class: MessagePack::Unpacker
- Inherits:
-
Object
- Object
- MessagePack::Unpacker
- Defined in:
- doclib/msgpack/unpacker.rb
Overview
MessagePack::Unpacker is a class to deserialize objects.
Instance Attribute Summary collapse
-
#buffer ⇒ MessagePack::Buffer
readonly
Internal buffer.
Instance Method Summary collapse
-
#each {|object| ... } ⇒ Object
Repeats to deserialize objects.
-
#feed(data) ⇒ Unpacker
Appends data into the internal buffer.
-
#feed_each(data) {|object| ... } ⇒ Object
Appends data into the internal buffer and repeats to deserialize objects.
-
#initialize(*args) ⇒ Unpacker
constructor
Creates a MessagePack::Unpacker instance.
-
#read ⇒ Object
(also: #unpack)
Deserializes an object from the io or internal buffer and returns it.
-
#read_array_header ⇒ Integer
Read a header of an array and returns its size.
-
#read_map_header ⇒ Integer
Reads a header of an map and returns its size.
-
#register_type(type, klass, method_name, &block) ⇒ Object
Register a new ext type to deserialize it.
-
#registered_types ⇒ Object
Returns a list of registered types, ordered by type id.
-
#reset ⇒ Object
Clears the internal buffer and resets deserialization state of the unpacker.
-
#skip ⇒ Object
Deserializes an object and ignores it.
-
#skip_nil ⇒ Boolean
Deserializes a nil value if it exists and returns true.
-
#type_registered?(klass_or_type) ⇒ Boolean
Returns true/false which indicate specified class or type id is registered or not.
Constructor Details
#initialize(options = {}) ⇒ Unpacker #initialize(io, options = {}) ⇒ Unpacker
Creates a MessagePack::Unpacker instance.
Supported options:
-
:symbolize_keys deserialize keys of Hash objects as Symbol instead of String
-
:allow_unknown_ext allow to deserialize ext type object with unknown type id as ExtensionValue instance. Otherwise (by default), unpacker throws UnknownExtTypeError.
See also Buffer#initialize for other options.
26 27 |
# File 'doclib/msgpack/unpacker.rb', line 26 def initialize(*args) end |
Instance Attribute Details
#buffer ⇒ MessagePack::Buffer (readonly)
Internal buffer
70 71 72 |
# File 'doclib/msgpack/unpacker.rb', line 70 def buffer @buffer end |
Instance Method Details
#each {|object| ... } ⇒ Object
Repeats to deserialize objects.
It repeats until the io or internal buffer does not include any complete objects.
If an IO is set, it repeats to read data from the IO when the buffer becomes empty until the IO raises EOFError.
This method could raise same errors with read excepting EOFError.
160 161 |
# File 'doclib/msgpack/unpacker.rb', line 160 def each(&block) end |
#feed(data) ⇒ Unpacker
Appends data into the internal buffer. This method is equivalent to unpacker.buffer.append(data).
144 145 |
# File 'doclib/msgpack/unpacker.rb', line 144 def feed(data) end |
#feed_each(data) {|object| ... } ⇒ Object
Appends data into the internal buffer and repeats to deserialize objects. This method is equivalent to unpacker.feed(data) && unpacker.each { … }.
171 172 |
# File 'doclib/msgpack/unpacker.rb', line 171 def feed_each(data, &block) end |
#read ⇒ Object Also known as: unpack
Deserializes an object from the io or internal buffer and returns it.
This method reads data from io into the internal buffer and deserializes an object from the buffer. It repeats reading data from the io until enough data is available to deserialize at least one object. After deserializing one object, unused data is left in the internal buffer.
If there're not enough data to deserialize one object, this method raises EOFError. If data format is invalid, this method raises MessagePack::MalformedFormatError. If the object nests too deeply, this method raises MessagePack::StackError.
86 87 |
# File 'doclib/msgpack/unpacker.rb', line 86 def read end |
#read_array_header ⇒ Integer
Read a header of an array and returns its size. It converts a serialized array into a stream of elements.
If the serialized object is not an array, it raises MessagePack::UnexpectedTypeError. If there're not enough data, this method raises EOFError.
122 123 |
# File 'doclib/msgpack/unpacker.rb', line 122 def read_array_header end |
#read_map_header ⇒ Integer
Reads a header of an map and returns its size. It converts a serialized map into a stream of key-value pairs.
If the serialized object is not a map, it raises MessagePack::UnexpectedTypeError. If there're not enough data, this method raises EOFError.
134 135 |
# File 'doclib/msgpack/unpacker.rb', line 134 def read_map_header end |
#register_type(type) {|data| ... } ⇒ Object #register_type(type, klass, class_method_name) ⇒ Object
Register a new ext type to deserialize it. This method should be called with Class and its class method name, or block, which returns a instance object.
44 45 |
# File 'doclib/msgpack/unpacker.rb', line 44 def register_type(type, klass, method_name, &block) end |
#registered_types ⇒ Object
Returns a list of registered types, ordered by type id. Each element is a Hash object includes keys :type, :class and :unpacker.
53 54 |
# File 'doclib/msgpack/unpacker.rb', line 53 def registered_types end |
#reset ⇒ Object
Clears the internal buffer and resets deserialization state of the unpacker.
179 180 |
# File 'doclib/msgpack/unpacker.rb', line 179 def reset end |
#skip ⇒ Object
Deserializes an object and ignores it. This method is faster than read.
This method could raise the same errors with read.
98 99 |
# File 'doclib/msgpack/unpacker.rb', line 98 def skip end |
#skip_nil ⇒ Boolean
Deserializes a nil value if it exists and returns true. Otherwise, if a byte exists but the byte doesn't represent nil value, returns false.
If there're not enough data, this method raises EOFError.
110 111 |
# File 'doclib/msgpack/unpacker.rb', line 110 def skip_nil end |
#type_registered?(klass_or_type) ⇒ Boolean
Returns true/false which indicate specified class or type id is registered or not.
62 63 |
# File 'doclib/msgpack/unpacker.rb', line 62 def type_registered?(klass_or_type) end |