Class: Synapse::Serialization::MessageSerializer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/synapse/serialization/message/serializer.rb

Overview

Serializer that provides convenience methods for serializing messages and adds support for optimizing the serialization process

Instance Method Summary collapse

Constructor Details

#initialize(serializer) ⇒ undefined

Parameters:



10
11
12
# File 'lib/synapse/serialization/message/serializer.rb', line 10

def initialize(serializer)
  @serializer = serializer
end

Instance Method Details

#serialize_metadata(message, expected_type) ⇒ SerializedObject

Returns the serialized metadata for the given message in the expected type, optimizing the serialization, if possible

Parameters:

  • message (Message)
  • expected_type (Class)

Returns:



20
21
22
23
24
25
26
# File 'lib/synapse/serialization/message/serializer.rb', line 20

def (message, expected_type)
  if message.is_a? SerializationAware
    message. @serializer, expected_type
  else
    serialize message., expected_type
  end
end

#serialize_payload(message, expected_type) ⇒ SerializedObject

Returns the serialized payload for the given message in the expected type, optimizing the serialization, if possible

Parameters:

  • message (Message)
  • expected_type (Class)

Returns:



34
35
36
37
38
39
40
# File 'lib/synapse/serialization/message/serializer.rb', line 34

def serialize_payload(message, expected_type)
  if message.is_a? SerializationAware
    message.serialize_payload @serializer, expected_type
  else
    serialize message.payload, expected_type
  end
end