Skip to content

protoMESG

David O'Rourke edited this page Jun 8, 2018 · 1 revision

MESG protocol

The MESG protocol sends a UTF-8 string along with an address comprising two slugs. By convention you should use your manufacture slug for the first, and this should ensure that there are no conflicts. Avoiding conflicts in the second slug is then your responsibility. The received method delivers both slugs as parameters, so you can examine these to determine if you understand and choose to handle any given message.

Structure

The payload of the MESG protocol is a json encoded object comprising the two slugs and the message

    {
      "plugin": "ManufacturerSlug",
      "module": "ModuleSlug",
      "message": "MessageText"
    }

Sending

You can send in the MESG protocol using a MessageOutputPort

    Torpedo::MessageOutputPort outPort = Torpedo::MessageOutputPort(module, OUTPUT_TOR);

    std::string message = std::string("This is my message");
    outPort.send(std::string(TOSTRING(SLUG)), std::string("MyModule"), message);

Receiving

You can receive the MESG protocol using a MessageInputPort

    void mySubclassedInputPort::received(std::string pluginName, std::string moduleName, std::string message) {
      if (pluginName.compare(TOSTRING(SLUG))) return;
      if (pluginName.compare("MyModule")) return;
      // handle message
      return;
    }
Clone this wiki locally