Class: Lobster::Serialization::UuidSerializer

Inherits:
Serializer
  • Object
show all
Defined in:
lib/lobster/serialization/uuid_serializer.rb

Overview

Transforms a UUID to and from its marshaled format.

Instance Method Summary collapse

Instance Method Details

#add_to(engine) ⇒ nil

This method is abstract.

Adds the serializer to an engine.

Parameters:

Returns:

  • (nil)

14
15
16
# File 'lib/lobster/serialization/uuid_serializer.rb', line 14

def add_to(engine)
  engine.add_serializer(self, Lobster::Uuid)
end

#deserialize(data, type, engine, *args) ⇒ Object

Creates a UUID from its marshaled format.

Parameters:

  • data (Object)

    UUID in its marshaled format.

  • type (Class)

    Type of object that should be created.

  • engine (SerializationEngine)

    Engine performing the serialization. Use this to de-serialize other types of objects.

  • args

    Extra information that might be need for de-serializing.

Returns:

  • (Object)

    Newly created instance of the UUID representative of its marshaled format.


34
35
36
37
38
39
40
# File 'lib/lobster/serialization/uuid_serializer.rb', line 34

def deserialize(data, type, engine, *args)
  fail FormatError unless data.is_a?(String)

  uuid = Lobster::Uuid.parse(data)
  fail FormatError if uuid.nil? # Did not parse correctly.
  uuid # Return converted UUID.
end

#serialize(obj, engine) ⇒ Object

Converts a UUID to its marshaled format.

Parameters:

  • obj (Uuid)

    UUID to serialize.

  • engine (SerializationEngine)

    Engine performing the serialization. Use this to serialize other types of objects.

Returns:

  • (Object)

    UUID marshaled to its simplest form.


23
24
25
# File 'lib/lobster/serialization/uuid_serializer.rb', line 23

def serialize(obj, engine)
  obj.to_s
end