Class: Synapse::Serialization::SerializedMessage

Inherits:
Object
  • Object
show all
Includes:
SerializationAware
Defined in:
lib/synapse/serialization/message/serialized_message.rb

Overview

Serialized representation of a message

Direct Known Subclasses

SerializedEventMessage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, metadata, payload, timestamp) ⇒ undefined

Parameters:



24
25
26
27
28
29
# File 'lib/synapse/serialization/message/serialized_message.rb', line 24

def initialize(id, , payload, timestamp)
  @id = id
  @serialized_metadata = 
  @serialized_payload = payload
  @timestamp = timestamp
end

Instance Attribute Details

#idString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/synapse/serialization/message/serialized_message.rb', line 8

def id
  @id
end

#serialized_metadataLazyObject (readonly)

Returns:



11
12
13
# File 'lib/synapse/serialization/message/serialized_message.rb', line 11

def 
  @serialized_metadata
end

#serialized_payloadLazyObject (readonly)

Returns:



14
15
16
# File 'lib/synapse/serialization/message/serialized_message.rb', line 14

def serialized_payload
  @serialized_payload
end

#timestampTime (readonly)

Returns:

  • (Time)


17
18
19
# File 'lib/synapse/serialization/message/serialized_message.rb', line 17

def timestamp
  @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

.builderClass

Returns the type of builder that can be used to build this type of message

Returns:

  • (Class)


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

Parameters:

  • additional_metadata (Hash)

Returns:

See Also:



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

#metadataHash

Returns The deserialized metadata for this message.

Returns:

  • (Hash)

    The deserialized metadata for this message



32
33
34
# File 'lib/synapse/serialization/message/serialized_message.rb', line 32

def 
  @serialized_metadata.deserialized
end

#payloadObject

Returns The deserialized payload for this message.

Returns:

  • (Object)

    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_typeClass

Returns The type of payload for this message.

Returns:

  • (Class)

    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

Parameters:

Returns:

See Also:



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

Parameters:

Returns:

See Also:



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

Parameters:

  • replacement_metadata (Hash)

Returns:

See Also:



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