Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / xdr-unpacker-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="xdr-exceptions.html" />
<link rel="prev" href="xdr-packer-objects.html" />
<link rel="parent" href="module-xdrlib.html" />
<link rel="next" href="xdr-exceptions.html" />
<meta name='aesop' content='information' />
<title>12.17.2 Unpacker Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.17.1 Packer Objects"
href="xdr-packer-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12.17 xdrlib "
href="module-xdrlib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.17.3 Exceptions"
href="xdr-exceptions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="xdr-packer-objects.html">12.17.1 Packer Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xdrlib.html">12.17 xdrlib </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="xdr-exceptions.html">12.17.3 Exceptions</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION00141720000000000000000"></A><A NAME="xdr-unpacker-objects"></A>
<BR>
12.17.2 Unpacker Objects
</H2>
<P>
The <tt class="class">Unpacker</tt> class offers the following methods:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4177' xml:id='l2h-4177' class="method">reset</tt></b>(</nobr></td>
<td><var>data</var>)</td></tr></table></dt>
<dd>
Resets the string buffer with the given <var>data</var>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4178' xml:id='l2h-4178' class="method">get_position</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Returns the current unpack position in the data buffer.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4179' xml:id='l2h-4179' class="method">set_position</tt></b>(</nobr></td>
<td><var>position</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4180' xml:id='l2h-4180' class="method">get_buffer</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Returns the current unpack data buffer as a string.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4181' xml:id='l2h-4181' class="method">done</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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 <code>unpack_<var>type</var>()</code>, and take no arguments. They return the
unpacked object.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4182' xml:id='l2h-4182' class="method">unpack_float</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Unpacks a single-precision floating point number.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4183' xml:id='l2h-4183' class="method">unpack_double</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4184' xml:id='l2h-4184' class="method">unpack_fstring</tt></b>(</nobr></td>
<td><var>n</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4185' xml:id='l2h-4185' class="method">unpack_fopaque</tt></b>(</nobr></td>
<td><var>n</var>)</td></tr></table></dt>
<dd>
Unpacks and returns a fixed length opaque data stream, similarly to
<tt class="method">unpack_fstring()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4186' xml:id='l2h-4186' class="method">unpack_string</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4187' xml:id='l2h-4187' class="method">unpack_opaque</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Unpacks and returns a variable length opaque data string, similarly to
<tt class="method">unpack_string()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4188' xml:id='l2h-4188' class="method">unpack_bytes</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4189' xml:id='l2h-4189' class="method">unpack_list</tt></b>(</nobr></td>
<td><var>unpack_item</var>)</td></tr></table></dt>
<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 <code>1</code>,
then the item is unpacked and appended to the list. A flag of
<code>0</code> indicates the end of the list. <var>unpack_item</var> is the
function that is called to unpack the items.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4190' xml:id='l2h-4190' class="method">unpack_farray</tt></b>(</nobr></td>
<td><var>n, unpack_item</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4191' xml:id='l2h-4191' class="method">unpack_array</tt></b>(</nobr></td>
<td><var>unpack_item</var>)</td></tr></table></dt>
<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>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.17.1 Packer Objects"
href="xdr-packer-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12.17 xdrlib "
href="module-xdrlib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.17.3 Exceptions"
href="xdr-exceptions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="xdr-packer-objects.html">12.17.1 Packer Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xdrlib.html">12.17 xdrlib </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="xdr-exceptions.html">12.17.3 Exceptions</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>