Class: DjiMqttConnect::Thing::Product::OsdMarshal

Inherits:
MessageMarshal show all
Includes:
Utils::MessageParsing
Defined in:
lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb

Defined Under Namespace

Classes: OsdTransformer

Instance Method Summary collapse

Methods inherited from MessageMarshal

#dump

Instance Method Details

#load(raw_message) ⇒ Object

Parse message from Device > Cloud Server



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb', line 40

def load(raw_message)
  parsed_message = parse_json(raw_message)

  message_data = parsed_message.fetch("data", {})

  message_class = if drone_osd_data_attributes.all? { |attribute| message_data.key?(attribute.to_s) }
    DroneOsdMessage
  elsif required_remote_osd_data_attributes.all? { |attribute| message_data.key?(attribute.to_s) } &&
      optional_remote_osd_data_attributes.any? { |attribute| message_data.key?(attribute.to_s) }
    RemoteOsdMessage
  elsif dock_osd_data_attributes.any? { |attribute| message_data.key?(attribute.to_s) }
    DockOsdMessage
  else
    OsdMessage
  end

  transformed_message = osd_transformer.call(parsed_message)

  build_message(message_class, transformed_message)
end