Reputation: 423
I want to read data from my received message in OMNeT++ and store it.
This is what my message format looks like:
packet ServerMsg
{
String code;
String text;
}
I know how to build and send it, but not how to disassemble it at the receiving point.
Now I want to store 'code' in 'a' and 'text' in 'b'.
void Server::handleMessage(cMessage *msg) {
String a;
String b;
}
What's the way to go here?
Upvotes: 1
Views: 303
Reputation: 6681
You need to cast the incoming message to the appropriate type and then can access all the member variables of the message class:
#include "ServerMsg_m.h"
...
void Server::handleMessage(cMessage *msg) {
String a;
String b;
ServerMsg *pkt = check_and_cast<ServerMsg *>(msg);
a = pkt->a;
b = pkt->b;
}
Upvotes: 1