Class: MessagePack::Factory

Inherits:
Object
  • Object
show all
Defined in:
doclib/msgpack/factory.rb

Overview

MessagePack::Factory is a class to generate Packer and Unpacker which has same set of ext types.

Instance Method Summary (collapse)

Constructor Details

- (Factory) initialize

Creates a MessagePack::Factory instance



10
11
# File 'doclib/msgpack/factory.rb', line 10

def initialize
end

Instance Method Details

- (String) dump(obj, options = {}) Also known as: pack

Serialize the passed value

If it could not serialize the object, it raises NoMethodError: undefined method `to_msgpack' for #<the_object>.

See Packer#initialize for supported options.

Parameters:

  • obj (Object)

    object to serialize

  • options (Hash) (defaults to: {})

Returns:

  • (String)

    serialized object



34
35
# File 'doclib/msgpack/factory.rb', line 34

def dump(obj, options={})
end

- (Object) load(data, options = {}) Also known as: unpack

Deserializes an object from the string or io and returns it.

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.

See Unpacker#initialize for supported options.

Parameters:

Returns:

  • (Object)

    deserialized object



60
61
# File 'doclib/msgpack/factory.rb', line 60

def load(data, options={})
end

- (Object) packer(*args)

Creates a MessagePack::Packer instance, which has ext types already registered. Options are passed to MessagePack::Packer#initialized.

See also Packer#initialize for options.



19
20
# File 'doclib/msgpack/factory.rb', line 19

def packer(*args)
end

- (Object) register_type(type, klass, options = {})

Register a type and Class to be registered for packer and/or unpacker. If options are not speicified, factory will use :to_msgpack_ext for packer, and :from_msgpack_ext for unpacker.

Supported options:

  • :packer specify symbol or proc object for packer

  • :unpacker specify symbol or proc object for unpacker

Parameters:

  • type (Fixnum)

    type id of registered Class (0-127)

  • klass (Class)

    Class to be associated with type id

  • options (Hash) (defaults to: {})

    specify method name or Proc which are used by packer/unpacker

Returns:

  • nil



79
80
# File 'doclib/msgpack/factory.rb', line 79

def register_type(type, klass, options={})
end

- (Object) registered_types(selector = :both)

Returns a list of registered types, ordered by type id.

Parameters:

  • selector (Symbol) (defaults to: :both)

    specify to list types registered for :packer, :unpacker or :both (default)

Returns:

  • Array



88
89
# File 'doclib/msgpack/factory.rb', line 88

def registered_types(selector=:both)
end

- (Boolean) type_registered?(klass_or_type, selector = :both)

Returns true/false which indicate specified class or type id is registered or not.

Parameters:

  • klass_or_type (Class or Fixnum)

    Class or type id (0-127) to be checked

  • selector (Symbol) (defaults to: :both)

    specify to check for :packer, :unpacker or :both (default)

Returns:

  • (Boolean)

    true or false



98
99
# File 'doclib/msgpack/factory.rb', line 98

def type_registered?(klass_or_type, selector=:both)
end

- (Object) unpacker(*args)

Creates a MessagePack::Unpacker instance, which has ext types already registered. Options are passed to MessagePack::Unpacker#initialized.

See also Unpacker#initialize for options.



44
45
# File 'doclib/msgpack/factory.rb', line 44

def unpacker(*args)
end