<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>12.12.2 Unpacker Objects </TITLE>
<META NAME="description" CONTENT="12.12.2 Unpacker Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="xdr-exceptions.html">
<LINK REL="previous" HREF="xdr-packer-objects.html">
<LINK REL="up" HREF="module-xdrlib.html">
<LINK REL="next" HREF="xdr-exceptions.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="xdr-exceptions.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-xdrlib.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="xdr-packer-objects.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="xdr-exceptions.html">12.12.3 Exceptions</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-xdrlib.html">12.12 xdrlib  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="xdr-packer-objects.html">12.12.1 Packer Objects</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00141220000000000000000"></A>
<BR>
12.12.2 Unpacker Objects 
</H2>

<P>
The <tt class=class>Unpacker</tt> class offers the following methods:

<P>
<dl><dt><b><a name="l2h-2071"><tt class=method>reset</tt></a></b> (<var>data</var>)
<dd>
Resets the string buffer with the given <var>data</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-2072"><tt class=method>get_position</tt></a></b> ()
<dd>
Returns the current unpack position in the data buffer.
</dl>

<P>
<dl><dt><b><a name="l2h-2073"><tt class=method>set_position</tt></a></b> (<var>position</var>)
<dd>
Sets the data buffer unpack position to <var>position</var>.  You should be
careful about using <tt class=method>get_position()</tt> and <tt class=method>set_position()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-2074"><tt class=method>get_buffer</tt></a></b> ()
<dd>
Returns the current unpack data buffer as a string.
</dl>

<P>
<dl><dt><b><a name="l2h-2075"><tt class=method>done</tt></a></b> ()
<dd>
Indicates unpack completion.  Raises an <tt class=exception>Error</tt> exception
if all of the data has not been unpacked.
</dl>

<P>
In addition, every data type that can be packed with a <tt class=class>Packer</tt>,
can be unpacked with an <tt class=class>Unpacker</tt>.  Unpacking methods are of the
form <tt>unpack_<var>type</var>()</tt>, and take no arguments.  They return the
unpacked object.

<P>
<dl><dt><b><a name="l2h-2076"><tt class=method>unpack_float</tt></a></b> ()
<dd>
Unpacks a single-precision floating point number.
</dl>

<P>
<dl><dt><b><a name="l2h-2077"><tt class=method>unpack_double</tt></a></b> ()
<dd>
Unpacks a double-precision floating point number, similarly to
<tt class=method>unpack_float()</tt>.
</dl>

<P>
In addition, the following methods unpack strings, bytes, and opaque
data:

<P>
<dl><dt><b><a name="l2h-2078"><tt class=method>unpack_fstring</tt></a></b> (<var>n</var>)
<dd>
Unpacks and returns a fixed length string.  <var>n</var> is the number of
characters expected.  Padding with null bytes to guaranteed 4 byte
alignment is assumed.
</dl>

<P>
<dl><dt><b><a name="l2h-2079"><tt class=method>unpack_fopaque</tt></a></b> (<var>n</var>)
<dd>
Unpacks and returns a fixed length opaque data stream, similarly to
<tt class=method>unpack_fstring()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-2080"><tt class=method>unpack_string</tt></a></b> ()
<dd>
Unpacks and returns a variable length string.  The length of the
string is first unpacked as an unsigned integer, then the string data
is unpacked with <tt class=method>unpack_fstring()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-2081"><tt class=method>unpack_opaque</tt></a></b> ()
<dd>
Unpacks and returns a variable length opaque data string, similarly to
<tt class=method>unpack_string()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-2082"><tt class=method>unpack_bytes</tt></a></b> ()
<dd>
Unpacks and returns a variable length byte stream, similarly to
<tt class=method>unpack_string()</tt>.
</dl>

<P>
The following methods support unpacking arrays and lists:

<P>
<dl><dt><b><a name="l2h-2083"><tt class=method>unpack_list</tt></a></b> (<var>unpack_item</var>)
<dd>
Unpacks and returns a list of homogeneous items.  The list is unpacked
one element at a time
by first unpacking an unsigned integer flag.  If the flag is <tt>1</tt>,
then the item is unpacked and appended to the list.  A flag of
<tt>0</tt> indicates the end of the list.  <var>unpack_item</var> is the
function that is called to unpack the items.
</dl>

<P>
<dl><dt><b><a name="l2h-2084"><tt class=method>unpack_farray</tt></a></b> (<var>n, unpack_item</var>)
<dd>
Unpacks and returns (as a list) a fixed length array of homogeneous
items.  <var>n</var> is number of list elements to expect in the buffer.
As above, <var>unpack_item</var> is the function used to unpack each element.
</dl>

<P>
<dl><dt><b><a name="l2h-2085"><tt class=method>unpack_array</tt></a></b> (<var>unpack_item</var>)
<dd>
Unpacks and returns a variable length <var>list</var> of homogeneous items.
First, the length of the list is unpacked as an unsigned integer, then
each element is unpacked as in <tt class=method>unpack_farray()</tt> above.
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="xdr-exceptions.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-xdrlib.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="xdr-packer-objects.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="xdr-exceptions.html">12.12.3 Exceptions</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-xdrlib.html">12.12 xdrlib  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="xdr-packer-objects.html">12.12.1 Packer Objects</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
