VistaIOPackData(3) | Library Functions Manual | VistaIOPackData(3) |
VistaIOPackData, VistaIOUnpackData - pack or unpack a vector of values
typedef enum { VistaIOLsbFirst, VistaIOMsbFirst } VistaIOPackOrder;
void VistaIOPackData (repn, nels, unpacked, order, plength, ppacked, palloced)
VistaIORepnKind repn; size_t nels, *plength; VistaIOPointer unpacked, *ppacked; VistaIOPackOrder order; VistaIOBoolean *palloced;
void VistaIOUnpackData (repn, nels, packed, order, plength, punpacked, palloced)
VistaIORepnKind repn; size_t nels, *plength; VistaIOPointer packed, *punpacked; VistaIOPackOrder order; VistaIOBoolean *palloced;
VistaIOPackData packs a vector of values into a block of contiguous bytes. Typically, it is used when preparing to output a series of values to a Vista data file. VistaIOUnpackData performs the inverse, unpacking a vector of values from a block of contiguous bytes. It is used when decoding a series of values read from a Vista data file.
Unpacked values reside in memory in a form dependent upon machine architecture. Packed values, on the other hand, are represented in a machine-independent manner using the fewest bits possible. If the values are of type VistaIOBit, for example, they might occupy one byte each in unpacked form, but in packed form each occupies a single bit. The types of values that can be (un)packed, and their form when packed, is as follows:
The values to be (un)packed must all have one of these types, as specified by the repn argument.
The order argument specifies the order with which bits are packed into a byte, or multi-byte, packed values are separated into bytes. If the packed values each require a single bit, order specifies whether successive values are to be packed into a byte from least-significant bit to most significant (VistaIOLsbFirst), or vice versa (VistaIOMsbFirst). If the packed values each require multiple bytes, order specifies whether those bytes are to be packed from least-significant byte to most significant (VistaIOLsbFirst), or vice versa (VistaIOMsbFirst). Data in Vista data files is packed with order = VistaIOMsbFirst.
For a call to VistaIOPackData, nels specifies the number of values to be packed and unpacked points to a vector containing them. You can specify where to place the packed values in either of two ways:
VistaIOUnpackData is called in an analogous manner. The nels argument specifies the number of values to be unpacked and packed points to a vector containing them. As for VistaIOPackData, you can specify where to place the unpacked values in either of two ways indicated by palloced.
Both routines return TRUE if successful, and FALSE otherwise. In addition, they may set *plength, *ppacked, *punpacked, and *palloced as described above.
Here we pack a vector of bits, write the packed bits to a file, and free any storage used to represent the packed bits:
size_t nbits, length; VistaIOBit *bits; VistaIOPointer packed; VistaIOBoolean alloced; FILE *file;
... VistaIOPackData (VistaIOBitRepn, nbits, bits, VistaIOMsbFirst, & length, & packed, & alloced); fwrite ((char *) packed, 1, length, file); if (alloced)
VistaIOFree (packed);
Packing or unpacking can be done in place. For example, in a call to VistaIOPackData, unpacked and *ppacked can point to the same storage.
The present implementation cannot pack values of type VistaIOUByte, VistaIOSByte, VistaIOShort, VistaIOLong, VistaIOFloat, or VistaIODouble if their packed and unpacked sizes differ.
Art Pope <pope@cs.ubc.ca>
Adaption to vistaio: Gert Wollny <gw.fossdev@gmail.com>
21 January 1994 | VistaIO Version 1.2.14 |