next up previous contents index
Next: 16.3.3 The Packed-Message Functions Up: 16.3 High-Level Primitives Previous: 16.3.1 Invoices

16.3.2 Packing and Unpacking

Packing is done when one wishes to copy the variables into the communications buffer space prior to transmission; to access the contents of a packed buffer, one must unpack it first.

    int zip_pack(ZIP_MAILER *mailer, Zip_Invoice *inv, 
                        int buffer_type, char **ptr, int len)

This command packs the invoice. The meaning of buffer_type is either ``ZIP_BUFFER'' or ``ZIP_LETTER,'' indicating whether we are packing into a buffer (say for a combine or fanout) or a letter (for sends/receives).

If one is packing a buffer and has preallocated the buffer space, then len must be set to the size of this allocated buffer space. If the invoice is too large to fit in this buffer space, an error occurs. By specifying *ptr = NULL and len = ZIP_IGNORE, the pack routine will allocate the space for the buffer based on the size of the invoice to be packed. Alternatively, if a preallocated letter is being packed, then pack will fill in the letter by using the invoice. If the letter provided is not large enough, then an error will occur. If no preallocated letter is available, the pack routine can create one automatically, provided *ptr = NULL. Note that len is ignored when letters are involved, as the size of letters can be determined with Zip_length(); len should always be ZIP_IGNORE when packing letters. For either case, zip_pack() returns the number of bytes that the data from the invoice occupies in the communication space (letter or buffer).

To unpack a letter, use

    
int zip_unpack(ZIP_MAILER *mailer, Zip_Invoice *inv, 
               int buffer_type, char *ptr)

As in zip_pack(), inv is the invoice to unpack. The buffer_type parameter indicates the type of communication space being used; that is, whether we are unpacking a letter (buffer_type = ZIP_LETTER) or a buffer (buffer_type = ZIP_BUFFER). The parameter ptr is a pointer to the communication space. Unlike zip_pack(), we pass a pointer to the communication space to zip_unpack(), not a pointer to a pointer. The communication space must be freed by the caller after it is unpacked.



next up previous contents index
Next: 16.3.3 The Packed-Message Functions Up: 16.3 High-Level Primitives Previous: 16.3.1 Invoices



Guy Robinson
Wed Mar 1 10:19:35 EST 1995