Class: Synapse::Serialization::SerializedMessage
- Inherits:
-
Object
- Object
- Synapse::Serialization::SerializedMessage
- Includes:
- SerializationAware
- Defined in:
- lib/synapse/serialization/message/serialized_message.rb
Overview
Serialized representation of a message
Direct Known Subclasses
Instance Attribute Summary collapse
- #id ⇒ String readonly
- #serialized_metadata ⇒ LazyObject readonly
- #serialized_payload ⇒ LazyObject readonly
- #timestamp ⇒ Time readonly
Class Method Summary collapse
-
.build {|SerializedMessageBuilder| ... } ⇒ SerializedMessage
Yields a message builder that can be used to produce a message.
-
.builder ⇒ Class
Returns the type of builder that can be used to build this type of message.
Instance Method Summary collapse
-
#and_metadata(additional_metadata) ⇒ SerializedMessage
Returns a copy of this message with the given metadata merged in.
- #initialize(id, metadata, payload, timestamp) ⇒ undefined constructor
-
#metadata ⇒ Hash
The deserialized metadata for this message.
-
#payload ⇒ Object
The deserialized payload for this message.
-
#payload_type ⇒ Class
The type of payload for this message.
- #serialize_metadata(serializer, expected_type) ⇒ SerializedObject
- #serialize_payload(serializer, expected_type) ⇒ SerializedObject
-
#with_metadata(replacement_metadata) ⇒ SerializedMessage
Returns a copy of this message with the metadata replaced with the given metadata.
Constructor Details
#initialize(id, metadata, payload, timestamp) ⇒ undefined
24 25 26 27 28 29 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 24 def initialize(id, , payload, ) @id = id @serialized_metadata = @serialized_payload = payload @timestamp = end |
Instance Attribute Details
#id ⇒ String (readonly)
8 9 10 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 8 def id @id end |
#serialized_metadata ⇒ LazyObject (readonly)
11 12 13 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 11 def @serialized_metadata end |
#serialized_payload ⇒ LazyObject (readonly)
14 15 16 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 14 def serialized_payload @serialized_payload end |
#timestamp ⇒ Time (readonly)
17 18 19 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 17 def @timestamp end |
Class Method Details
.build {|SerializedMessageBuilder| ... } ⇒ SerializedMessage
Yields a message builder that can be used to produce a message
99 100 101 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 99 def self.build(&block) builder.build(&block) end |
.builder ⇒ Class
Returns the type of builder that can be used to build this type of message
90 91 92 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 90 def self.builder SerializedMessageBuilder end |
Instance Method Details
#and_metadata(additional_metadata) ⇒ SerializedMessage
Returns a copy of this message with the given metadata merged in
51 52 53 54 55 56 57 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 51 def () return self if .empty? self.class.build do |builder| build_duplicate builder, .merge() end end |
#metadata ⇒ Hash
Returns The deserialized metadata for this message.
32 33 34 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 32 def @serialized_metadata.deserialized end |
#payload ⇒ Object
Returns The deserialized payload for this message.
37 38 39 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 37 def payload @serialized_payload.deserialized end |
#payload_type ⇒ Class
Returns The type of payload for this message.
42 43 44 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 42 def payload_type @serialized_payload.type end |
#serialize_metadata(serializer, expected_type) ⇒ SerializedObject
76 77 78 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 76 def (serializer, expected_type) serialize @serialized_metadata, serializer, expected_type end |
#serialize_payload(serializer, expected_type) ⇒ SerializedObject
84 85 86 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 84 def serialize_payload(serializer, expected_type) serialize @serialized_payload, serializer, expected_type end |
#with_metadata(replacement_metadata) ⇒ SerializedMessage
Returns a copy of this message with the metadata replaced with the given metadata
64 65 66 67 68 69 70 |
# File 'lib/synapse/serialization/message/serialized_message.rb', line 64 def () return self if @serialized_metadata.deserialized == self.class.build do |builder| build_duplicate builder, end end |