20 #include <platdep/sockets.h>
30 #define STOREARRAY(type,d,size) {memcpy(mBuffer+mMsgSize,d,size*sizeof(type)); mMsgSize+=size*sizeof(type);}
31 #define EXTRACTARRAY(type,d,size) {\
32 if ((mPosition + size*sizeof(type)) <= (uint32_t)mBufferSize) {\
33 memcpy(d,mBuffer+mPosition,size*sizeof(type)); mPosition+=size*sizeof(type);\
35 throw cRuntimeError("OverSim cnetcommbuffer.cc: EXTRACTARRAY buffer overflow!");\
39 #define STORE(type,d) {memcpy(mBuffer+mMsgSize,(void*)&d,sizeof(type)); mMsgSize+=sizeof(type);}
40 #define EXTRACT(type,d) {\
41 if ((mPosition + sizeof(type)) <= (uint32_t)mBufferSize) {\
42 memcpy((void*)&d,mBuffer+mPosition,sizeof(type)); mPosition+=sizeof(type);\
44 throw cRuntimeError("OverSim cnetcommbuffer.cc: EXTRACT buffer overflow!");\
59 extendBufferFor(
sizeof(
char));
66 extendBufferFor(
sizeof(
unsigned char));
67 STORE(
unsigned char,d);
73 extendBufferFor(
sizeof(
bool));
80 extendBufferFor(
sizeof(
short));
81 short d_buf = htons(d);
88 extendBufferFor(
sizeof(
unsigned short));
89 unsigned short d_buf = htons(d);
90 STORE(
unsigned short,d_buf);
96 extendBufferFor(
sizeof(
int));
104 extendBufferFor(
sizeof(
unsigned int));
105 unsigned int d_buf = htonl(d);
106 STORE(
unsigned int,d_buf);
112 extendBufferFor(
sizeof(
long));
113 long d_buf = htonl(d);
120 extendBufferFor(
sizeof(
unsigned long));
121 unsigned long d_buf = htonl(d);
122 STORE(
unsigned long,d_buf);
128 extendBufferFor(
sizeof(opp_long_long));
129 STORE(opp_long_long,d);
135 extendBufferFor(
sizeof(opp_unsigned_long_long));
136 STORE(opp_unsigned_long_long,d);
142 extendBufferFor(
sizeof(
float));
149 extendBufferFor(
sizeof(
double));
156 extendBufferFor(
sizeof(
long double));
157 STORE(
long double,d);
165 int len = d ? strlen(d) : 0;
168 extendBufferFor(len*
sizeof(
char));
179 for (
int i = 0; i < size; i++)
185 extendBufferFor(size*
sizeof(
char));
192 extendBufferFor(size*
sizeof(
unsigned char));
199 extendBufferFor(size*
sizeof(
bool));
206 extendBufferFor(size*
sizeof(
short));
214 extendBufferFor(size*
sizeof(
unsigned short));
222 extendBufferFor(size*
sizeof(
int));
230 extendBufferFor(size*
sizeof(
unsigned int));
238 extendBufferFor(size*
sizeof(
long));
246 extendBufferFor(size*
sizeof(
unsigned long));
253 extendBufferFor(size*
sizeof(opp_long_long));
260 extendBufferFor(size*
sizeof(opp_unsigned_long_long));
267 extendBufferFor(size*
sizeof(
float));
274 extendBufferFor(size*
sizeof(
double));
281 extendBufferFor(size*
sizeof(
long double));
289 for (
int i = 0; i < size; i++)
295 for (
int i = 0; i < size; i++)
301 pack((opp_long_long)d.raw());
372 EXTRACT(opp_unsigned_long_long,d);
400 char *tmp =
new char[len+1];
414 d.buffer()[len] =
'\0';
509 for (
int i = 0; i < size; i++)
515 for (
int i = 0; i < size; i++)
522 for (
int i = 0; i < size; i++)
529 return (mMsgSize - mPosition);
534 pack(obj->getClassName());
535 obj->parsimPack(
this);
540 char *classname = NULL;
544 obj = createOne(classname);
545 obj->parsimUnpack(
this);
549 throw std::invalid_argument(
"Failed to parse received packet");