-
Notifications
You must be signed in to change notification settings - Fork 1
protoMESG
David O'Rourke edited this page Jun 8, 2018
·
1 revision
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.
The payload of the MESG protocol is a json encoded object comprising the two slugs and the message
{
"plugin": "ManufacturerSlug",
"module": "ModuleSlug",
"message": "MessageText"
}
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);
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;
}