Module: Pio::MessageTypeSelector

Defined in:
lib/pio/message_type_selector.rb

Overview

Macros for defining message types.

Instance Method Summary collapse

Instance Method Details

#message_type(options) ⇒ Object



9
10
11
# File 'lib/pio/message_type_selector.rb', line 9

def message_type(options)
  const_set(:MESSAGE_TYPE, options)
end

#read(raw_data) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/pio/message_type_selector.rb', line 13

def read(raw_data)
  format = const_get(:Format).read(raw_data)
  message = const_get(:MESSAGE_TYPE)[format.message_type].allocate
  message.instance_variable_set :@format, format
  message
rescue
  raise Pio::ParseError, $ERROR_INFO.message
end