class CAVERNnet_datapack_c

Data packing class

Public Methods

void initPack (char *buffer, int buffersize)
Before we do any actual packing, we first call this method to attach the datapack object to some buffer

void initUnpack (char *buffer, int buffersize)
Before we do any actual unpacking, we first call this method to attach the datapack object to some buffer

char* getBuffer ()
Given a datapack class, this method gives us a pointer to the buffer where the packed data is stored

int getBufferMaxSize ()
Gives us the size of the buffer attached to this datapack object

int getBufferFilledSize ()
Gives us the size in bytes of available space left in the attached buffer

int packFloat (float val)
Insert a variable of type float into the buffer

int packInt (int val)
Insert a variable of type int into the buffer

int packInt32 (int32 val)
Insert a variable of type 32-bit integer into the buffer

int packLong (long val)
Insert a variable of type long into the buffer
int packInt64 (int64 val)
Insert a variable of type 64-bit integer into the buffer

int packDouble (double val)
Insert a variable of type double into the buffer

int packChar (TCHAR val)
Insert a variable of type char into the buffer

int packChar (char val)
Insert a variable of type char into the buffer

int pack (TCHAR* val, int sz)
Pack raw characters into the buffer

int pack (char* val, int sz)
Pack raw characters into the buffer

int packFloatArray (float* val, int sz)
Pack floats of a float array into the buffer

int packDoubleArray (double* val, int sz)
Pack doubles of a double array into the buffer

int packIntArray (int* val, int sz)
Pack an array with int type values into the buffer

int packInt32Array (int32* val, int sz)
Pack an array with int32 type values into the buffer

int packInt64Array (int64* val, int sz)
Pack an array with int64 type values into the buffer

int packLongArray (long* val, int sz)
Pack an array with long type values into the buffer

int packUnsignedLong (unsigned long val)
Insert a variable of type unsigned long into the buffer
int unpackFloat (float *Answer)
Extract a variable of type float from the buffer

int unpackInt (int *Answer)
Extract a variable of type int from the buffer

int unpackInt32 (int32 *Answer)
Extract a variable of type 32bit integer from the buffer

int unpackLong (long *Answer)
Extract a variable of type long from the buffer

int unpackUnsignedLong (unsigned long *Answer)
Extract a variable of type unsigned long from the buffer

int unpackInt64 (int64 *Answer)
Extract a variable of type 64-bit integer from the buffer

int unpackDouble (double *Answer)
Extract a variable of type double from the buffer

int unpackChar (TCHAR *Answer)
Extract a variable of type char from the buffer

int unpackChar (char *Answer)
Extract a variable of type char from the buffer

int unpack (TCHAR *Answer, int sz)
Extract the packed chars from the buffer

int unpack (char *Answer, int sz)
Extract the packed chars from the buffer

int unpackFloatArray (float* Answer, int sz)
Extract the packed float array from the buffer

int unpackDoubleArray (double* Answer, int sz)
Extract the packed double array from the buffer

int unpackIntArray (int* Answer, int sz)
Extract the packed int array from the buffer

int unpackInt32Array (int32* Answer, int sz)
Extract the packed int32 array from the buffer

int unpackInt64Array (int64* Answer, int sz)
Extract the packed int64 array from the buffer

int unpackLongArray (long* Answer, int sz)
Extract the packed long array from the buffer

int checkspace (unsigned int incoming_size)
This function tells us if there is enough incoming_size bytes in the buffer to perform the operation
static int sizeof_float (unsigned int cnt=1)
Gives us a cross-platform safe float size

static int sizeof_int (unsigned int cnt=1)
Gives us a cross-platform safe int size

static int sizeof_int64 (unsigned int cnt=1)
Gives us a cross-platform safe 64-bit int size

static int sizeof_int32 (unsigned int cnt=1)
Gives us a cross-platform safe 32-bit int size

static int sizeof_long (unsigned int cnt=1)
Gives us a cross-platform safe long size

static int sizeof_unsignedLong (unsigned int cnt=1)
Gives us a cross-platform safe unsigned long size

static int sizeof_char (unsigned int cnt=1)
Gives us a cross-platform safe char size

static int sizeof_double (unsigned int cnt=1)
Gives us a cross-platform safe double size

Public


Datapack class return values
static const int OK
Operation went ok
static const int FAILED
Operation failed

Documentation

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 initPack(char *buffer, int buffersize)
Before we do any actual packing, we first call this method to attach the datapack object to some buffer

Parameters:
buffer - This buffer provided by the API user is where the packed data will be stored
buffersize - The size in bytes of the buffer above

void initUnpack(char *buffer, int buffersize)
Before we do any actual unpacking, we first call this method to attach the datapack object to some buffer

Parameters:
buffer - This buffer where the packed data is stored
buffersize - The size in bytes of the buffer above

char* getBuffer()
Given a datapack class, this method gives us a pointer to the buffer where the packed data is stored

Returns:
A pointer to the beginning of the packed data stream

int getBufferMaxSize()
Gives us the size of the buffer attached to this datapack object

Returns:
Size in bytes of the attached buffer

int getBufferFilledSize()
Gives us the size in bytes of available space left in the attached buffer

Returns:
Size in bytes of the remaining space available in the attached buffer

int packFloat(float val)
Insert a variable of type float into the buffer

Returns:
OK or FAILED
Parameters:
val - The float variable to be packed

int packInt(int val)
Insert a variable of type int into the buffer

Returns:
OK or FAILED
Parameters:
val - The int variable to be packed

int packInt32(int32 val)
Insert a variable of type 32-bit integer into the buffer

Returns:
OK or FAILED
Parameters:
val - The 32bit integer variable to be packed

int packLong(long val)
Insert a variable of type long into the buffer. Note that long takes 8 bytes when it is compiled with 64-bit compiler on SGI.

Returns:
OK or FAILED
Parameters:
val - The long variable to be packed

int packInt64(int64 val)
Insert a variable of type 64-bit integer into the buffer

Returns:
OK or FAILED
Parameters:
val - The 64-bit integer variable to be packed

int packDouble(double val)
Insert a variable of type double into the buffer

Returns:
OK or FAILED
Parameters:
val - The double variable to be packed

int packChar(TCHAR val)
Insert a variable of type char into the buffer

Returns:
OK or FAILED
Parameters:
val - The Unicode char variable to be packed

int packChar(char val)
Insert a variable of type char into the buffer

Returns:
OK or FAILED
Parameters:
val - The char variable to be packed

int pack(TCHAR* val, int sz)
Pack raw characters into the buffer

Returns:
OK or FAILED
Parameters:
val - The Unicode char array to be packed
sz - Num chars to pack

int pack(char* val, int sz)
Pack raw characters into the buffer

Returns:
OK or FAILED
Parameters:
val - The char array to be packed
sz - Num chars to pack

int packFloatArray(float* val, int sz)
Pack floats of a float array into the buffer

Returns:
OK or FAILED
Parameters:
val - The float array to be packed
sz - Num floats in the array

int packDoubleArray(double* val, int sz)
Pack doubles of a double array into the buffer

Returns:
OK or FAILED
Parameters:
val - The double array to be packed
sz - Num doubles in the array

int packIntArray(int* val, int sz)
Pack an array with int type values into the buffer

Returns:
OK or FAILED
Parameters:
val - The int array to be packed
sz - Num int values in the array

int packInt32Array(int32* val, int sz)
Pack an array with int32 type values into the buffer

Returns:
OK or FAILED
Parameters:
val - The int32 array to be packed
sz - Num int32 values in the array

int packInt64Array(int64* val, int sz)
Pack an array with int64 type values into the buffer

Returns:
OK or FAILED
Parameters:
val - The int64 array to be packed
sz - Num int64 values in the array

int packLongArray(long* val, int sz)
Pack an array with long type values into the buffer

Returns:
OK or FAILED
Parameters:
val - The long array to be packed
sz - Num long values in the array

int packUnsignedLong(unsigned long val)
Insert a variable of type unsigned long into the buffer. Note that long takes 8 bytes when it is compiled with 64-bit compiler on SGI.

Returns:
OK or FAILED
Parameters:
val - The unsigned long variable to be packed

int unpackFloat(float *Answer)
Extract a variable of type float from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided float variable where we store the extracted value

int unpackInt(int *Answer)
Extract a variable of type int from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided int variable where we store the extracted value

int unpackInt32(int32 *Answer)
Extract a variable of type 32bit integer from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided 32bit integer variable where we store the extracted value

int unpackLong(long *Answer)
Extract a variable of type long from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided long variable where we store the extracted value

int unpackUnsignedLong(unsigned long *Answer)
Extract a variable of type unsigned long from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided unsigned long variable where we store the extracted value

int unpackInt64(int64 *Answer)
Extract a variable of type 64-bit integer from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided 64-bit integer variable where we store the extracted value

int unpackDouble(double *Answer)
Extract a variable of type double from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided double variable where we store the extracted value

int unpackChar(TCHAR *Answer)
Extract a variable of type char from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided Unicode char variable where we store the extracted value

int unpackChar(char *Answer)
Extract a variable of type char from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided char variable where we store the extracted value

int unpack(TCHAR *Answer, int sz)
Extract the packed chars from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided Unicode char array where we store the extracted value

int unpack(char *Answer, int sz)
Extract the packed chars from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided char array where we store the extracted value

int unpackFloatArray(float* Answer, int sz)
Extract the packed float array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided float array where the extracted floats are stored
sz - The size of the array in which the extracted floats are stored

int unpackDoubleArray(double* Answer, int sz)
Extract the packed double array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided double array where the extracted doubles are stored
sz - The size of the array in which the extracted doubles are stored

int unpackIntArray(int* Answer, int sz)
Extract the packed int array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided int array where the extracted int values are stored
sz - The size of the array in which the extracted int values are stored

int unpackInt32Array(int32* Answer, int sz)
Extract the packed int32 array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided array where the extracted int32 values are stored
sz - The size of the array in which the extracted int32 values are stored

int unpackInt64Array(int64* Answer, int sz)
Extract the packed int64 array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided array where the extracted int64 values are stored
sz - The size of the array in which the extracted int64 values are stored

int unpackLongArray(long* Answer, int sz)
Extract the packed long array from the buffer

Returns:
OK or FAILED
Parameters:
Answer - A user provided array where the extracted long values are stored
sz - The size of the array in which the extracted long values are stored

int checkspace(unsigned int incoming_size)
This function tells us if there is enough incoming_size bytes in the buffer to perform the operation.

Returns:
OK or FAILED
Parameters:
incoming_size - The size in bytes of to be tested.

static int sizeof_float(unsigned int cnt=1)
Gives us a cross-platform safe float size

Returns:
The number of bytes in an int (+ 1 byte for machine code storage)

static int sizeof_int(unsigned int cnt=1)
Gives us a cross-platform safe int size

Returns:
The number of bytes in an int (+ 1 byte for machine code storage)

static int sizeof_int64(unsigned int cnt=1)
Gives us a cross-platform safe 64-bit int size

Returns:
The number of bytes in an 64-bit int

static int sizeof_int32(unsigned int cnt=1)
Gives us a cross-platform safe 32-bit int size

Returns:
The number of bytes in an 32-bit int

static int sizeof_long(unsigned int cnt=1)
Gives us a cross-platform safe long size

Returns:
The number of bytes in a long (+ 1 byte for machine code storage)

static int sizeof_unsignedLong(unsigned int cnt=1)
Gives us a cross-platform safe unsigned long size

Returns:
The number of bytes in unsigned long (+ 1 byte for machine code storage)

static int sizeof_char(unsigned int cnt=1)
Gives us a cross-platform safe char size

Returns:
The number of bytes in a char 1 byte for machine code storage)

static int sizeof_double(unsigned int cnt=1)
Gives us a cross-platform safe double size

Returns:
The number of bytes in a double (+ 1 byte for machine code storage)


This class has no child classes.
Version:
: 12/1/1999

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