Packer Objects

Packer is the class for packing data into XDR representation. The Packer class is instantiated with no arguments.


\begin{funcdesc}{get_buffer}{}
Returns the current pack buffer as a string.
\end{funcdesc}


\begin{funcdesc}{reset}{}
Resets the pack buffer to the empty string.
\end{funcdesc}

In general, you can pack any of the most common XDR data types by calling the appropriate pack_type method. Each method takes a single argument, the value to pack. The following simple data type packing methods are supported: pack_uint, pack_int, pack_enum, pack_bool, pack_uhyper, and pack_hyper.

The following methods pack floating point numbers, however they require C library support. Without the optional C built-in module, both of these methods will raise an xdrlib.ConversionError exception. See the note at the end of this chapter for details.


\begin{funcdesc}{pack_float}{value}
Packs the single-precision floating point number \var{value}.
\end{funcdesc}


\begin{funcdesc}{pack_double}{value}
Packs the double-precision floating point number \var{value}.
\end{funcdesc}

The following methods support packing strings, bytes, and opaque data:


\begin{funcdesc}{pack_fstring}{n\, s}
Packs a fixed length string, \var{s}. \var...
...dded with null bytes if necessary to guaranteed 4 byte alignment.
\end{funcdesc}


\begin{funcdesc}{pack_fopaque}{n\, data}
Packs a fixed length opaque data stream, similarly to
\code{pack_fstring}.
\end{funcdesc}


\begin{funcdesc}{pack_string}{s}
Packs a variable length string, \var{s}. The le...
...integer, then the string data is packed
with \code{pack_fstring}.
\end{funcdesc}


\begin{funcdesc}{pack_opaque}{data}
Packs a variable length opaque data string, similarly to
\code{pack_string}.
\end{funcdesc}


\begin{funcdesc}{pack_bytes}{bytes}
Packs a variable length byte stream, similarly to \code{pack_string}.
\end{funcdesc}

The following methods support packing arrays and lists:


\begin{funcdesc}{pack_list}{list\, pack_item}
Packs a \var{list} of homogeneous ...
.... At the end of the list, an unsigned integer
\code{0} is packed.
\end{funcdesc}


\begin{funcdesc}{pack_farray}{n\, array\, pack_item}
Packs a fixed length list (...
...above, \var{pack_item} is the function used to
pack each element.
\end{funcdesc}


\begin{funcdesc}{pack_array}{list\, pack_item}
Packs a variable length \var{list...
...eger, then each element
is packed as in \code{pack_farray} above.
\end{funcdesc}