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.
00042 { 00043 cPacket *msg = NULL; 00044 00045 commBuffer.reset(); 00046 commBuffer.allocateAtLeast(length); 00047 memcpy(commBuffer.getBuffer(), buf, length); 00048 commBuffer.setMessageSize(length); 00049 00050 try { 00051 msg = check_and_cast<cPacket*>(commBuffer.unpackObject()); 00052 if (!commBuffer.isBufferEmpty()) { 00053 ev << "[GenericPacketParser::decapsulatePayload()]\n" 00054 << " Parsing of payload failed: buffer size mismatch" 00055 << endl; 00056 delete msg; 00057 return NULL; 00058 } 00059 // } catch (cRuntimeError err) { 00060 // FIXME: 00061 // the above does, for some reason, not work. So we catch everything, 00062 // which may prevent the simulation from terminating correctly while 00063 // parsing a message. 00064 } catch (...) { 00065 ev << "[GenericPacketParser::decapsulatePayload()]\n" 00066 << " Parsing of payload failed" 00067 << endl; 00068 delete msg; 00069 return NULL; 00070 } 00071 00072 return msg; 00073 }
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.
00030 { 00031 commBuffer.reset(); 00032 commBuffer.packObject(msg); 00033 00034 *length = commBuffer.getMessageSize(); 00035 char* byte_buf = new char[*length]; 00036 memcpy(byte_buf, commBuffer.getBuffer(), *length); 00037 00038 return byte_buf; 00039 }
the buffer used to encapsulate and decapsulate messages
Definition at line 59 of file GenericPacketParser.h.
Referenced by decapsulatePayload(), and encapsulatePayload().