Class: Serialization::Simple::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rswim/serialization/simple/serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Serializer

Returns a new instance of Serializer.



6
7
8
# File 'lib/rswim/serialization/simple/serializer.rb', line 6

def initialize(directory)
  @directory = directory
end

Instance Method Details

#serialize(message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rswim/serialization/simple/serializer.rb', line 10

def serialize(message)
  l1 = message.type.to_s.gsub(/_/, '-')
  l1 << " #{@directory.host(message.payload[:target_id])}" if message.type == :ping_req

  message.payload[:updates].to_a.each do |update|
    # host status incarnation_number
    l1 << "\n#{@directory.host(update.member_id)} #{update.status} #{update.incarnation_number}"
    l1 << " #{serialize_custom_state(update.custom_state)}" unless update.custom_state.empty?
  end
  l1
end