Module structrecord
StructRecord -- a binary record packer/unpacker
This module unpacks binary records into objects, and packs objects
into binary records. Similar in spirit to Construct (on the web at
construct.wikispaces.com), but assembles parsed data into objects
instead of construct's unnamed data structures.
Allows conditionals, recursive definition of structures, and custom
pack/unpack classes. A class to store unparsed binary data needs a
class attribute named 'typedef' that is a tuple that defines the
structure of the binary record. The tuple contains a description of
the entities in the binary record, in order that they occur in the
file.
Simple example for parsing 3 32-bit integers of varying endianness:
class TestParse:
typedef=(
FormatField('testi1','<i'),
SLInt32('testi2'),
SBInt32('testi3'),
)
More complicated examples include conditionals, cases, lists, and nested
structures. For more examples, see the unit tests.
|
|
| repr1(name,
value,
indent,
printall=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| LFloat32(name,
default=0) |
|
|
|
|
| BFloat32(name,
default=0) |
|
|
|
|
| LFloat64(name,
default=0) |
|
|
|
|
| BFloat64(name,
default=0) |
|
|
|
|
|
|
|
|
|
|
debug = True
|
|
|
base_indent = ' '
|