Class: Utopia::Session::Serialization

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/session/serialization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSerialization

Returns a new instance of Serialization.



14
15
16
17
18
19
20
21
22
# File 'lib/utopia/session/serialization.rb', line 14

def initialize
	@factory = MessagePack::Factory.new
	
	@factory.register_type(0x00, Symbol, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
	
	@factory.register_type(0x01, Time, packer: :iso8601, unpacker: :parse)
	@factory.register_type(0x02, Date, packer: :iso8601, unpacker: :parse)
	@factory.register_type(0x03, DateTime, packer: :iso8601, unpacker: :parse)
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



24
25
26
# File 'lib/utopia/session/serialization.rb', line 24

def factory
  @factory
end

Instance Method Details

#dump(object) ⇒ Object



30
31
32
# File 'lib/utopia/session/serialization.rb', line 30

def dump(object)
	@factory.pack(object)
end

#load(data) ⇒ Object



26
27
28
# File 'lib/utopia/session/serialization.rb', line 26

def load(data)
	@factory.unpack(data)
end