A message parser using the cMemCommBuffer to serialize cmessages. More...
#include <GenericPacketParser.h>
Public Member Functions | |
char * | encapsulatePayload (cPacket *msg, unsigned int *length) |
serializes messages in a buffer | |
cPacket * | decapsulatePayload (char *buf, unsigned int length) |
deserializes messages from a char[] of size length | |
Private Attributes | |
cNetCommBuffer | commBuffer |
the buffer used to encapsulate and decapsulate messages |
A message parser using the cMemCommBuffer to serialize cmessages.
Definition at line 37 of file GenericPacketParser.h.
cPacket * GenericPacketParser::decapsulatePayload | ( | char * | buf, | |
unsigned int | length | |||
) | [virtual] |
deserializes messages from a char[] of size length
buf | the buffer to extract the message from | |
length | the length of the buffer |
Implements PacketParser.
Definition at line 41 of file GenericPacketParser.cc.
{ cPacket *msg = NULL; commBuffer.reset(); commBuffer.allocateAtLeast(length); memcpy(commBuffer.getBuffer(), buf, length); commBuffer.setMessageSize(length); try { msg = check_and_cast<cPacket*>(commBuffer.unpackObject()); if (!commBuffer.isBufferEmpty()) { ev << "[GenericPacketParser::decapsulatePayload()]\n" << " Parsing of payload failed: buffer size mismatch" << endl; delete msg; return NULL; } // } catch (cRuntimeError err) { // FIXME: // the above does, for some reason, not work. So we catch everything, // which may prevent the simulation from terminating correctly while // parsing a message. } catch (...) { ev << "[GenericPacketParser::decapsulatePayload()]\n" << " Parsing of payload failed" << endl; delete msg; return NULL; } return msg; }
char * GenericPacketParser::encapsulatePayload | ( | cPacket * | msg, | |
unsigned int * | length | |||
) | [virtual] |
serializes messages in a buffer
msg | the message to serialize | |
length | the length of the message |
Implements PacketParser.
Definition at line 29 of file GenericPacketParser.cc.
{ commBuffer.reset(); commBuffer.packObject(msg); *length = commBuffer.getMessageSize(); char* byte_buf = new char[*length]; memcpy(byte_buf, commBuffer.getBuffer(), *length); return byte_buf; }
the buffer used to encapsulate and decapsulate messages
Definition at line 59 of file GenericPacketParser.h.
Referenced by decapsulatePayload(), and encapsulatePayload().