Module: Messaging::Message::Transform::MessageData

Defined in:
lib/messaging/message/transform.rb

Class Method Summary collapse

Class Method Details

.read(message_data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/messaging/message/transform.rb', line 44

def self.read(message_data)
  data = message_data.to_h

  if data[:metadata].nil?
    data[:metadata] = {}
  else
    data[:metadata] = data[:metadata].clone
  end

   = data[:metadata]

  [:stream_name] = data[:stream_name]
  [:position] = data[:position]

  [:global_position] = data[:global_position]
  [:time] = data[:time]

  [:properties] ||= {}
  [:local_properties] ||= {}

  data
end

.write(message) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/messaging/message/transform.rb', line 19

def self.write(message)
  message_data = MessageStore::MessageData::Write.build

  message_data.id = message.id
  message_data.type = message.message_type

  message_data.data = message.to_h

   = message..to_h

  if [:properties].empty?
    .delete(:properties)
  end

  if [:local_properties].empty?
    .delete(:local_properties)
  end

  .delete_if { |k, v| v.nil? }

  message_data. = 

  message_data
end