#include <GenericPacketParser.h>

Definition at line 37 of file 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 | |
| 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 }
| 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; 00044 00045 commBuffer.reset(); 00046 //commBuffer.pack(buf, length); 00047 commBuffer.allocateAtLeast(length); 00048 memcpy(commBuffer.getBuffer(), buf, length); 00049 commBuffer.setMessageSize(length); 00050 00051 try { 00052 msg = check_and_cast<cPacket*>(commBuffer.unpackObject()); 00053 commBuffer.assertBufferEmpty(); 00054 // } catch (cRuntimeError err) { 00055 // FIXME: 00056 // the above does, for some reason, not work. So we catch everyting, 00057 // which may prevent the simulation from terminating corectly while 00058 // parsing a message. 00059 } catch (...) { 00060 ev << "[GenericPacketParser::decapsulatePayload()]\n" 00061 << " Parsing of payload failed" 00062 << endl; 00063 return NULL; 00064 } 00065 00066 return msg; 00067 }
the buffer used to encapsulate and decapsulate messages
Definition at line 59 of file GenericPacketParser.h.
Referenced by decapsulatePayload(), and encapsulatePayload().
1.5.5