Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_datapack_c Class Reference

#include <CAVERNnet_datapack_c.hxx>

List of all members.

Public Methods

 CAVERNnet_datapack_c ()
void initPack (char *buffer, int buffersize)
void initUnpack (char *buffer, int buffersize)
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 (char val)
int pack (char *val, int sz)
int packFloatArray (float *val, int sz)
int packDoubleArray (double *val, int sz)
int packIntArray (int *val, int sz)
int packInt32Array (int32 *val, int sz)
int packInt64Array (int64 *val, int sz)
int packLongArray (long *val, int sz)
int unpackFloat (float *Answer)
int unpackInt (int *Answer)
int unpackInt32 (int32 *Answer)
int unpackLong (long *Answer)
int unpackInt64 (int64 *Answer)
int unpackDouble (double *Answer)
int unpackChar (char *Answer)
int unpack (char *Answer, int sz)
int unpackFloatArray (float *Answer, int sz)
int unpackDoubleArray (double *Answer, int sz)
int unpackIntArray (int *Answer, int sz)
int unpackInt32Array (int32 *Answer, int sz)
int unpackInt64Array (int64 *Answer, int sz)
int unpackLongArray (long *Answer, int sz)
int checkspace (unsigned int incoming_size)

Static Public Methods

int sizeof_float (unsigned int cnt=1)
int sizeof_int (unsigned int cnt=1)
int sizeof_int64 (unsigned int cnt=1)
int sizeof_int32 (unsigned int cnt=1)
int sizeof_long (unsigned int cnt=1)
int sizeof_char (unsigned int cnt=1)
int sizeof_double (unsigned int cnt=1)

Static Public Attributes

const int OK
 Operation went ok.

const int FAILED
 Operation failed.


Private Attributes

unsigned long size
unsigned char* running
unsigned char* start


Detailed Description

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.

@version: 12/1/1999


Member Function Documentation

int CAVERNnet_datapack_c::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.

char * CAVERNnet_datapack_c::getBuffer ( ) [inline]
 

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 CAVERNnet_datapack_c::getBufferFilledSize ( ) [inline]
 

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 CAVERNnet_datapack_c::getBufferMaxSize ( ) [inline]
 

Gives us the size of the buffer attached to this datapack object

Returns:
Size in bytes of the attached buffer

void CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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

int CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::sizeof_char ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe char size

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

int CAVERNnet_datapack_c::sizeof_double ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe double size

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

int CAVERNnet_datapack_c::sizeof_float ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe float size

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

int CAVERNnet_datapack_c::sizeof_int ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe int size

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

int CAVERNnet_datapack_c::sizeof_int32 ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe 32-bit int size

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

int CAVERNnet_datapack_c::sizeof_int64 ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe 64-bit int size

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

int CAVERNnet_datapack_c::sizeof_long ( unsigned int cnt = 1 ) [inline, static]
 

Gives us a cross-platform safe long size

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

int CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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 CAVERNnet_datapack_c::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


The documentation for this class was generated from the following file:
Generated at Mon Jul 2 14:24:43 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001