class CAVERNnet_datapack_c Data packing class
|
| Datapack class return values
|
Data packing class. It is basically a glorified memcpy(). The idea is that you create an object to help you pack data for transmission over networks.Sending and packing data: First you create a CAVERNnet_datapack_c object. Then using the InitPack() method, assign to it a pre-allocated memory buffer (SEE BELOW FOR IMPORTANT NOTES.) Then using the various CAVERNnet_datapack_c::pack*() member functions, you can pack integers, chars, floats, and doubles into the buffer. The buffer is now ready for big-endian to little-endian transmission. (And vice-versa).
Receiving and unpacking data: Similarly if you receive a buffer of data from the network, you assign this buffer to a CAVERNnet_datapack_c object using the InitUnpack() method. Finally, we unpack its constituent components using the CAVERNnet_datapack_c::unpack*() member functions.
IMPORTANT NOTES:
It is important to compute the length of the buffer using the various CAVERNnet_datapack_c::sizeof_*() methods where possible as additional buffer space is needed to encode platform-specific information. If in doubt always allocate 1 more byte than necessary. The sizeof_() calls will make sure that extra byte is included.
To make your application as portable as possible, please take a look at packInt32 and packInt64 and counter functions that unpacks the data. These functions should be more portable than packInt and packLong functions since there is not specification about the size of int and lont int types in C or C++ language reference manual.
For example, on SGI, int is going to be treated as 32bits no matter what kind of binary format you are using. However, long int is going to be treated as 32bits if you use 32 or n32 for your binary format, whereas it would take 64bits if you use 64 as your binary format. On Win32 and linux running on Intel processors, both int and long takes 32bit space.
Finally remember the order in which you packed your data. You need to use the same order to unpack them correctly.
void initUnpack(char *buffer, int buffersize)
buffersize -
The size in bytes of the buffer above
char* getBuffer()
int getBufferMaxSize()
int getBufferFilledSize()
int packFloat(float val)
int packInt(int val)
int packInt32(int32 val)
int packLong(long val)
int packInt64(int64 val)
int packDouble(double val)
int packChar(TCHAR val)
int packChar(char val)
int pack(TCHAR* val, int sz)
sz -
Num chars to pack
int pack(char* val, int sz)
sz -
Num chars to pack
int packFloatArray(float* val, int sz)
sz -
Num floats in the array
int packDoubleArray(double* val, int sz)
sz -
Num doubles in the array
int packIntArray(int* val, int sz)
sz -
Num int values in the array
int packInt32Array(int32* val, int sz)
sz -
Num int32 values in the array
int packInt64Array(int64* val, int sz)
sz -
Num int64 values in the array
int packLongArray(long* val, int sz)
sz -
Num long values in the array
int packUnsignedLong(unsigned long val)
int unpackFloat(float *Answer)
int unpackInt(int *Answer)
int unpackInt32(int32 *Answer)
int unpackLong(long *Answer)
int unpackUnsignedLong(unsigned long *Answer)
int unpackInt64(int64 *Answer)
int unpackDouble(double *Answer)
int unpackChar(TCHAR *Answer)
int unpackChar(char *Answer)
int unpack(TCHAR *Answer, int sz)
int unpack(char *Answer, int sz)
int unpackFloatArray(float* Answer, int sz)
sz -
The size of the array in which the extracted floats are stored
int unpackDoubleArray(double* Answer, int sz)
sz -
The size of the array in which the extracted doubles are stored
int unpackIntArray(int* Answer, int sz)
sz -
The size of the array in which the extracted int values are stored
int unpackInt32Array(int32* Answer, int sz)
sz -
The size of the array in which the extracted int32 values are stored
int unpackInt64Array(int64* Answer, int sz)
sz -
The size of the array in which the extracted int64 values are stored
int unpackLongArray(long* Answer, int sz)
sz -
The size of the array in which the extracted long values are stored
int checkspace(unsigned int incoming_size)
static int sizeof_float(unsigned int cnt=1)
static int sizeof_int(unsigned int cnt=1)
static int sizeof_int64(unsigned int cnt=1)
static int sizeof_int32(unsigned int cnt=1)
static int sizeof_long(unsigned int cnt=1)
static int sizeof_unsignedLong(unsigned int cnt=1)
static int sizeof_char(unsigned int cnt=1)
static int sizeof_double(unsigned int cnt=1)
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de