90 lines
7.3 KiB
HTML
90 lines
7.3 KiB
HTML
|
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><title>Python: module sstruct</title>
|
|
</head><body bgcolor="#f0f0f8">
|
|
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
|
<tr bgcolor="#7799ee">
|
|
<td valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>sstruct</strong></big></big> (version 1.2)</font></td
|
|
><td align=right valign=bottom
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/code/fontTools/Lib/sstruct.py">/code/fontTools/Lib/sstruct.py</a></font></td></tr></table>
|
|
<p><tt>sstruct.py -- SuperStruct<br>
|
|
<br>
|
|
Higher level layer on top of the struct module, enabling to <br>
|
|
bind names to struct elements. The interface is similar to <br>
|
|
struct, except the objects passed and returned are not tuples <br>
|
|
(or argument lists), but dictionaries or instances. <br>
|
|
<br>
|
|
Just like struct, we use format strings to describe a data <br>
|
|
structure, except we use one line per element. Lines are <br>
|
|
separated by newlines or semi-colons. Each line contains <br>
|
|
either one of the special struct characters ('@', '=', '<', <br>
|
|
'>' or '!') or a 'name:formatchar' combo (eg. 'myFloat:f'). <br>
|
|
Repetitions, like the struct module offers them are not useful <br>
|
|
in this context, except for fixed length strings (eg. 'myInt:5h' <br>
|
|
is not allowed but 'myString:5s' is). The 'x' format character <br>
|
|
(pad byte) is treated as 'special', since it is by definition <br>
|
|
anonymous. Extra whitespace is allowed everywhere.<br>
|
|
<br>
|
|
The sstruct module offers one feature that the "normal" struct<br>
|
|
module doesn't: support for fixed point numbers. These are spelled<br>
|
|
as "n.mF", where n is the number of bits before the point, and m<br>
|
|
the number of bits after the point. Fixed point numbers get <br>
|
|
converted to floats.<br>
|
|
<br>
|
|
<a href="#-pack">pack</a>(format, object):<br>
|
|
'object' is either a dictionary or an instance (or actually<br>
|
|
anything that has a __dict__ attribute). If it is a dictionary, <br>
|
|
its keys are used for names. If it is an instance, it's <br>
|
|
attributes are used to grab struct elements from. Returns<br>
|
|
a string containing the data.<br>
|
|
<br>
|
|
<a href="#-unpack">unpack</a>(format, data, object=None)<br>
|
|
If 'object' is omitted (or None), a new dictionary will be <br>
|
|
returned. If 'object' is a dictionary, it will be used to add <br>
|
|
struct elements to. If it is an instance (or in fact anything<br>
|
|
that has a __dict__ attribute), an attribute will be added for <br>
|
|
each struct element. In the latter two cases, 'object' itself <br>
|
|
is returned.<br>
|
|
<br>
|
|
<a href="#-unpack2">unpack2</a>(format, data, object=None)<br>
|
|
Convenience function. Same as unpack, except data may be longer <br>
|
|
than needed. The returned value is a tuple: (object, leftoverdata).<br>
|
|
<br>
|
|
<a href="#-calcsize">calcsize</a>(format)<br>
|
|
like struct.<a href="#-calcsize">calcsize</a>(), but uses our own format strings:<br>
|
|
it returns the size of the data in bytes.</tt></p>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#aa55cc">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="re.html">re</a><br>
|
|
</td><td width="25%" valign=top><a href="struct.html">struct</a><br>
|
|
</td><td width="25%" valign=top><a href="types.html">types</a><br>
|
|
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#eeaa77">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl><dt><a name="-calcsize"><strong>calcsize</strong></a>(format)</dt></dl>
|
|
<dl><dt><a name="-getformat"><strong>getformat</strong></a>(format)</dt></dl>
|
|
<dl><dt><a name="-pack"><strong>pack</strong></a>(format, object)</dt></dl>
|
|
<dl><dt><a name="-unpack"><strong>unpack</strong></a>(format, data, object<font color="#909090">=None</font>)</dt></dl>
|
|
<dl><dt><a name="-unpack2"><strong>unpack2</strong></a>(format, data, object<font color="#909090">=None</font>)</dt></dl>
|
|
</td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#55aa55">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
|
|
<td width="100%"><strong>__copyright__</strong> = 'Copyright 1998, Just van Rossum <just@letterror.com>'<br>
|
|
<strong>__version__</strong> = '1.2'<br>
|
|
<strong>error</strong> = 'sstruct.error'</td></tr></table>
|
|
</body></html> |