Skip to main content

Expressive syntax for working with binary data formats and network protocols.

Project description

========
EzStruct
========

:copyright: 2013 by Matthew Sachs
:license: Apache License v2.0

Expressive syntax for working with binary data formats and network
protocols. Like the :py:mod:`struct` module, but with a more readable
syntax, especially if your format has:

* Length-prefixed variable-length byte sequences or strings
* Count-prefixed variable-count repeated fields
* Terminated (null or otherwise) strings
* String encodings
* Numbers which represent enumeration members

Example::

tcp = ezstruct.Struct(
"NET_ENDIAN",
ezstruct.Field("UINT16", name="sport"),
ezstruct.Field("UINT16", name="dport"),
ezstruct.Field("UINT32", name="seqno"),
ezstruct.Field("UINT32", name="ackno"),
ezstruct.Field("UINT16",
name="flags",
value_transform=ezstruct.FieldTransform(
pack_flags_bitfield,
unpack_flags_bitfield)),
ezstruct.Field("UINT16", name="window_size"),
ezstruct.Field("UINT16", name="checksum"),
ezstruct.Field("UINT16", name="urg"),
ezstruct.Field("BYTES",
name="options",
default_pack_value={},
length=lambda data: data["offset"] - 5,
value_transform=ezstruct.FieldTransform(
pack_and_pad_options,
unpack_options)))

header_data = {"sport": 123,
"dport": 456,
"seqno": 1,
"ackno": 0,
"flags": {"offset": 5,
"syn": 1},
"window_size": 100,
"checksum": 0,
"urg": 0}
header_bytes = tcp.pack_bytes(header_data)
assert tcp.unpack_bytes(header_bytes) == header_data


History
=======

v0.1.0, 2014-01-15
Initial release.


Authors
=======

* `Matthew Sachs <http://github.com/matthewg/>`_

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ezstruct-0.1.0-py2.py3-none-any.whl (11.6 kB) Copy SHA256 hash SHA256 Wheel py2.py3
ezstruct-0.1.0.tar.gz (13.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page