#include <CAVERNnet_datapack_c.hxx>
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 |
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
|
This function tells us if there is enough incoming_size bytes in the buffer to perform the operation.
|
|
Given a datapack class, this method gives us a pointer to the buffer where the packed data is stored
|
|
Gives us the size in bytes of available space left in the attached buffer
|
|
Gives us the size of the buffer attached to this datapack object
|
|
Before we do any actual packing, we first call this method to attach the datapack object to some buffer
|
|
Before we do any actual unpacking, we first call this method to attach the datapack object to some buffer
|
|
Pack raw characters into the buffer
|
|
Insert a variable of type char into the buffer
|
|
Insert a variable of type double into the buffer
|
|
Pack doubles of a double array into the buffer
|
|
Insert a variable of type float into the buffer
|
|
Pack floats of a float array into the buffer
|
|
Insert a variable of type int into the buffer
|
|
Insert a variable of type 32-bit integer into the buffer
|
|
Pack an array with int32 type values into the buffer
|
|
Insert a variable of type 64-bit integer into the buffer
|
|
Pack an array with int64 type values into the buffer
|
|
Pack an array with int type values into the buffer
|
|
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.
|
|
Pack an array with long type values into the buffer
|
|
Gives us a cross-platform safe char size
|
|
Gives us a cross-platform safe double size
|
|
Gives us a cross-platform safe float size
|
|
Gives us a cross-platform safe int size
|
|
Gives us a cross-platform safe 32-bit int size
|
|
Gives us a cross-platform safe 64-bit int size
|
|
Gives us a cross-platform safe long size
|
|
Extract the packed chars from the buffer
|
|
Extract a variable of type char from the buffer
|
|
Extract a variable of type double from the buffer
|
|
Extract the packed double array from the buffer
|
|
Extract a variable of type float from the buffer
|
|
Extract the packed float array from the buffer
|
|
Extract a variable of type int from the buffer
|
|
Extract a variable of type 32bit integer from the buffer
|
|
Extract the packed int32 array from the buffer
|
|
Extract a variable of type 64-bit integer from the buffer
|
|
Extract the packed int64 array from the buffer
|
|
Extract the packed int array from the buffer
|
|
Extract a variable of type long from the buffer
|
|
Extract the packed long array from the buffer
|