OverSim
cNetCommBuffer Class Reference

Communication buffer that packs data into a memory buffer without any transformation. More...

#include <cnetcommbuffer.h>

Public Member Functions

 cNetCommBuffer ()
 Constructor.
virtual ~cNetCommBuffer ()
 Destructor.
size_t getRemainingMessageSize ()
 return the length of the remaining buffer in bytes
virtual void packObject (cObject *obj)
 Packs an object.
virtual cObject * unpackObject ()
 Unpacks and returns an object.
Pack basic types
virtual void pack (char d)
virtual void pack (unsigned char d)
virtual void pack (bool d)
virtual void pack (short d)
virtual void pack (unsigned short d)
virtual void pack (int d)
virtual void pack (unsigned int d)
virtual void pack (long d)
virtual void pack (unsigned long d)
virtual void pack (opp_long_long d)
virtual void pack (opp_unsigned_long_long d)
virtual void pack (float d)
virtual void pack (double d)
virtual void pack (long double d)
virtual void pack (const char *d)
virtual void pack (const opp_string &d)
virtual void pack (SimTime d)
Pack arrays of basic types
virtual void pack (const char *d, int size)
virtual void pack (const unsigned char *d, int size)
virtual void pack (const bool *d, int size)
virtual void pack (const short *d, int size)
virtual void pack (const unsigned short *d, int size)
virtual void pack (const int *d, int size)
virtual void pack (const unsigned int *d, int size)
virtual void pack (const long *d, int size)
virtual void pack (const unsigned long *d, int size)
virtual void pack (const opp_long_long *d, int size)
virtual void pack (const opp_unsigned_long_long *d, int size)
virtual void pack (const float *d, int size)
virtual void pack (const double *d, int size)
virtual void pack (const long double *d, int size)
virtual void pack (const char **d, int size)
virtual void pack (const opp_string *d, int size)
virtual void pack (const SimTime *d, int size)
Unpack basic types
virtual void unpack (char &d)
virtual void unpack (unsigned char &d)
virtual void unpack (bool &d)
virtual void unpack (short &d)
virtual void unpack (unsigned short &d)
virtual void unpack (int &d)
virtual void unpack (unsigned int &d)
virtual void unpack (long &d)
virtual void unpack (unsigned long &d)
virtual void unpack (opp_long_long &d)
virtual void unpack (opp_unsigned_long_long &d)
virtual void unpack (float &d)
virtual void unpack (double &d)
virtual void unpack (long double &d)
virtual void unpack (const char *&d)
void unpack (char *&d)
 Unpacks a string – storage will be allocated for it via new char[].
virtual void unpack (opp_string &d)
virtual void unpack (SimTime &)
Unpack arrays of basic types
virtual void unpack (char *d, int size)
virtual void unpack (unsigned char *d, int size)
virtual void unpack (bool *d, int size)
virtual void unpack (short *d, int size)
virtual void unpack (unsigned short *d, int size)
virtual void unpack (int *d, int size)
virtual void unpack (unsigned int *d, int size)
virtual void unpack (long *d, int size)
virtual void unpack (unsigned long *d, int size)
virtual void unpack (opp_long_long *d, int size)
virtual void unpack (opp_unsigned_long_long *d, int size)
virtual void unpack (float *d, int size)
virtual void unpack (double *d, int size)
virtual void unpack (long double *d, int size)
virtual void unpack (const char **d, int size)
virtual void unpack (opp_string *d, int size)
virtual void unpack (SimTime *d, int size)

Detailed Description

Communication buffer that packs data into a memory buffer without any transformation.

Definition at line 31 of file cnetcommbuffer.h.

Constructor & Destructor Documentation

cNetCommBuffer::cNetCommBuffer ( )

Constructor.

Definition at line 48 of file cnetcommbuffer.cc.

{
}
cNetCommBuffer::~cNetCommBuffer ( )
virtual

Destructor.

Definition at line 52 of file cnetcommbuffer.cc.

{
}

Member Function Documentation

size_t cNetCommBuffer::getRemainingMessageSize ( )

return the length of the remaining buffer in bytes

Definition at line 527 of file cnetcommbuffer.cc.

Referenced by OverSimMessage::parsimUnpack().

{
return (mMsgSize - mPosition);
}
void cNetCommBuffer::pack ( char  d)
virtual

Definition at line 57 of file cnetcommbuffer.cc.

Referenced by pack(), and packObject().

{
extendBufferFor(sizeof(char));
STORE(char,d);
}
void cNetCommBuffer::pack ( unsigned char  d)
virtual

Definition at line 64 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(unsigned char));
STORE(unsigned char,d);
}
void cNetCommBuffer::pack ( bool  d)
virtual

Definition at line 71 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(bool));
STORE(bool,d);
}
void cNetCommBuffer::pack ( short  d)
virtual

Definition at line 78 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(short));
short d_buf = htons(d);
STORE(short,d_buf);
}
void cNetCommBuffer::pack ( unsigned short  d)
virtual

Definition at line 86 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(unsigned short));
unsigned short d_buf = htons(d);
STORE(unsigned short,d_buf);
}
void cNetCommBuffer::pack ( int  d)
virtual

Definition at line 94 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(int));
int d_buf = htonl(d);
STORE(int,d_buf);
}
void cNetCommBuffer::pack ( unsigned int  d)
virtual

Definition at line 102 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(unsigned int));
unsigned int d_buf = htonl(d);
STORE(unsigned int,d_buf);
}
void cNetCommBuffer::pack ( long  d)
virtual

Definition at line 110 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(long));
long d_buf = htonl(d);
STORE(long,d_buf);
}
void cNetCommBuffer::pack ( unsigned long  d)
virtual

Definition at line 118 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(unsigned long));
unsigned long d_buf = htonl(d);
STORE(unsigned long,d_buf);
}
void cNetCommBuffer::pack ( opp_long_long  d)
virtual

Definition at line 126 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(opp_long_long));
STORE(opp_long_long,d);
}
void cNetCommBuffer::pack ( opp_unsigned_long_long  d)
virtual

Definition at line 133 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(opp_unsigned_long_long));
STORE(opp_unsigned_long_long,d);
}
void cNetCommBuffer::pack ( float  d)
virtual

Definition at line 140 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(float));
STORE(float,d);
}
void cNetCommBuffer::pack ( double  d)
virtual

Definition at line 147 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(double));
STORE(double,d);
}
void cNetCommBuffer::pack ( long double  d)
virtual

Definition at line 154 of file cnetcommbuffer.cc.

{
extendBufferFor(sizeof(long double));
STORE(long double,d);
}
void cNetCommBuffer::pack ( const char *  d)
virtual

Definition at line 163 of file cnetcommbuffer.cc.

{
int len = d ? strlen(d) : 0;
pack(len);
extendBufferFor(len*sizeof(char));
STOREARRAY(char,d,len);
}
void cNetCommBuffer::pack ( const opp_string &  d)
virtual

Definition at line 172 of file cnetcommbuffer.cc.

{
pack(d.c_str());
}
void cNetCommBuffer::pack ( SimTime  d)
virtual

Definition at line 299 of file cnetcommbuffer.cc.

{
pack((opp_long_long)d.raw());
}
void cNetCommBuffer::pack ( const char *  d,
int  size 
)
virtual

Definition at line 183 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(char));
STOREARRAY(char,d,size);
}
void cNetCommBuffer::pack ( const unsigned char *  d,
int  size 
)
virtual

Definition at line 190 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(unsigned char));
STOREARRAY(unsigned char,d,size);
}
void cNetCommBuffer::pack ( const bool *  d,
int  size 
)
virtual

Definition at line 197 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(bool));
STOREARRAY(bool,d,size);
}
void cNetCommBuffer::pack ( const short *  d,
int  size 
)
virtual

Definition at line 204 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(short));
STOREARRAY(short,d,size);
}
void cNetCommBuffer::pack ( const unsigned short *  d,
int  size 
)
virtual

Definition at line 212 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(unsigned short));
STOREARRAY(unsigned short,d,size);
}
void cNetCommBuffer::pack ( const int *  d,
int  size 
)
virtual

Definition at line 220 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(int));
STOREARRAY(int,d,size);
}
void cNetCommBuffer::pack ( const unsigned int *  d,
int  size 
)
virtual

Definition at line 228 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(unsigned int));
STOREARRAY(unsigned int,d,size);
}
void cNetCommBuffer::pack ( const long *  d,
int  size 
)
virtual

Definition at line 236 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(long));
STOREARRAY(long,d,size);
}
void cNetCommBuffer::pack ( const unsigned long *  d,
int  size 
)
virtual

Definition at line 244 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(unsigned long));
STOREARRAY(unsigned long,d,size);
}
void cNetCommBuffer::pack ( const opp_long_long *  d,
int  size 
)
virtual

Definition at line 251 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(opp_long_long));
STOREARRAY(opp_long_long,d,size);
}
void cNetCommBuffer::pack ( const opp_unsigned_long_long *  d,
int  size 
)
virtual

Definition at line 258 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(opp_unsigned_long_long));
STOREARRAY(opp_unsigned_long_long,d,size);
}
void cNetCommBuffer::pack ( const float *  d,
int  size 
)
virtual

Definition at line 265 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(float));
STOREARRAY(float,d,size);
}
void cNetCommBuffer::pack ( const double *  d,
int  size 
)
virtual

Definition at line 272 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(double));
STOREARRAY(double,d,size);
}
void cNetCommBuffer::pack ( const long double *  d,
int  size 
)
virtual

Definition at line 279 of file cnetcommbuffer.cc.

{
extendBufferFor(size*sizeof(long double));
STOREARRAY(long double,d,size);
}
void cNetCommBuffer::pack ( const char **  d,
int  size 
)
virtual

Definition at line 287 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
pack(d[i]);
}
void cNetCommBuffer::pack ( const opp_string *  d,
int  size 
)
virtual

Definition at line 293 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
pack(d[i]);
}
void cNetCommBuffer::pack ( const SimTime *  d,
int  size 
)
virtual

Definition at line 177 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
pack(d[i]);
}
void cNetCommBuffer::packObject ( cObject *  obj)
virtual

Packs an object.

Definition at line 532 of file cnetcommbuffer.cc.

Referenced by GenericPacketParser::encapsulatePayload(), and BinaryValue::packObject().

{
pack(obj->getClassName());
obj->parsimPack(this);
}
void cNetCommBuffer::unpack ( char &  d)
virtual

Definition at line 306 of file cnetcommbuffer.cc.

Referenced by unpack(), and unpackObject().

{
EXTRACT(char,d);
}
void cNetCommBuffer::unpack ( unsigned char &  d)
virtual

Definition at line 312 of file cnetcommbuffer.cc.

{
EXTRACT(unsigned char,d);
}
void cNetCommBuffer::unpack ( bool &  d)
virtual

Definition at line 317 of file cnetcommbuffer.cc.

{
EXTRACT(bool,d);
}
void cNetCommBuffer::unpack ( short &  d)
virtual

Definition at line 322 of file cnetcommbuffer.cc.

{
EXTRACT(short,d);
d = ntohs(d);
}
void cNetCommBuffer::unpack ( unsigned short &  d)
virtual

Definition at line 329 of file cnetcommbuffer.cc.

{
EXTRACT(unsigned short,d);
d = ntohs(d);
}
void cNetCommBuffer::unpack ( int &  d)
virtual

Definition at line 336 of file cnetcommbuffer.cc.

{
EXTRACT(int,d);
d = ntohl(d);
}
void cNetCommBuffer::unpack ( unsigned int &  d)
virtual

Definition at line 343 of file cnetcommbuffer.cc.

{
EXTRACT(unsigned int,d);
d = ntohl(d);
}
void cNetCommBuffer::unpack ( long &  d)
virtual

Definition at line 350 of file cnetcommbuffer.cc.

{
EXTRACT(long,d);
d = ntohl(d);
}
void cNetCommBuffer::unpack ( unsigned long &  d)
virtual

Definition at line 357 of file cnetcommbuffer.cc.

{
EXTRACT(unsigned long,d);
d = ntohl(d);
}
void cNetCommBuffer::unpack ( opp_long_long &  d)
virtual

Definition at line 364 of file cnetcommbuffer.cc.

{
EXTRACT(opp_long_long,d);
}
void cNetCommBuffer::unpack ( opp_unsigned_long_long &  d)
virtual

Definition at line 370 of file cnetcommbuffer.cc.

{
EXTRACT(opp_unsigned_long_long,d);
}
void cNetCommBuffer::unpack ( float &  d)
virtual

Definition at line 376 of file cnetcommbuffer.cc.

{
EXTRACT(float,d);
}
void cNetCommBuffer::unpack ( double &  d)
virtual

Definition at line 382 of file cnetcommbuffer.cc.

{
EXTRACT(double,d);
}
void cNetCommBuffer::unpack ( long double &  d)
virtual

Definition at line 388 of file cnetcommbuffer.cc.

{
EXTRACT(long double,d);
}
void cNetCommBuffer::unpack ( const char *&  d)
virtual

Definition at line 395 of file cnetcommbuffer.cc.

{
int len;
unpack(len);
char *tmp = new char[len+1];
EXTRACTARRAY(char,tmp,len);
tmp[len] = '\0';
d = tmp;
}
void cNetCommBuffer::unpack ( char *&  d)
inline

Unpacks a string – storage will be allocated for it via new char[].

Definition at line 106 of file cnetcommbuffer.h.

Referenced by unpack().

{unpack((const char *&)d);}
void cNetCommBuffer::unpack ( opp_string &  d)
virtual

Definition at line 407 of file cnetcommbuffer.cc.

{
int len;
unpack(len);
d.reserve(len+1);
EXTRACTARRAY(char,d.buffer(),len);
d.buffer()[len] = '\0';
}
void cNetCommBuffer::unpack ( SimTime &  d)
virtual

Definition at line 418 of file cnetcommbuffer.cc.

{
opp_long_long raw;
unpack(raw);
d.setRaw(raw);
}
void cNetCommBuffer::unpack ( char *  d,
int  size 
)
virtual

Definition at line 426 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(char,d,size);
}
void cNetCommBuffer::unpack ( unsigned char *  d,
int  size 
)
virtual

Definition at line 431 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(unsigned char,d,size);
}
void cNetCommBuffer::unpack ( bool *  d,
int  size 
)
virtual

Definition at line 437 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(bool,d,size);
}
void cNetCommBuffer::unpack ( short *  d,
int  size 
)
virtual

Definition at line 442 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(short,d,size);
}
void cNetCommBuffer::unpack ( unsigned short *  d,
int  size 
)
virtual

Definition at line 448 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(unsigned short,d,size);
}
void cNetCommBuffer::unpack ( int *  d,
int  size 
)
virtual

Definition at line 454 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(int,d,size);
}
void cNetCommBuffer::unpack ( unsigned int *  d,
int  size 
)
virtual

Definition at line 460 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(unsigned,d,size);
}
void cNetCommBuffer::unpack ( long *  d,
int  size 
)
virtual

Definition at line 466 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(long,d,size);
}
void cNetCommBuffer::unpack ( unsigned long *  d,
int  size 
)
virtual

Definition at line 472 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(unsigned long,d,size);
}
void cNetCommBuffer::unpack ( opp_long_long *  d,
int  size 
)
virtual

Definition at line 478 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(opp_long_long,d,size);
}
void cNetCommBuffer::unpack ( opp_unsigned_long_long *  d,
int  size 
)
virtual

Definition at line 484 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(opp_unsigned_long_long,d,size);
}
void cNetCommBuffer::unpack ( float *  d,
int  size 
)
virtual

Definition at line 490 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(float,d,size);
}
void cNetCommBuffer::unpack ( double *  d,
int  size 
)
virtual

Definition at line 496 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(double,d,size);
}
void cNetCommBuffer::unpack ( long double *  d,
int  size 
)
virtual

Definition at line 502 of file cnetcommbuffer.cc.

{
EXTRACTARRAY(long double,d,size);
}
void cNetCommBuffer::unpack ( const char **  d,
int  size 
)
virtual

Definition at line 507 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
unpack(d[i]);
}
void cNetCommBuffer::unpack ( opp_string *  d,
int  size 
)
virtual

Definition at line 513 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
unpack(d[i]);
}
void cNetCommBuffer::unpack ( SimTime *  d,
int  size 
)
virtual

Definition at line 520 of file cnetcommbuffer.cc.

{
for (int i = 0; i < size; i++)
unpack(d[i]);
}
cObject * cNetCommBuffer::unpackObject ( )
virtual

Unpacks and returns an object.

Definition at line 538 of file cnetcommbuffer.cc.

Referenced by GenericPacketParser::decapsulatePayload(), and BinaryValue::unpackObject().

{
char *classname = NULL;
cObject *obj = NULL;
try {
unpack(classname);
obj = createOne(classname);
obj->parsimUnpack(this);
} catch (...) {
delete [] classname;
delete obj;
throw std::invalid_argument("Failed to parse received packet");
}
delete [] classname;
return obj;
}

The documentation for this class was generated from the following files: