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/>`_
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 | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ezstruct-0.1.0.tar.gz
(13.9 kB
view details)
Built Distribution
File details
Details for the file ezstruct-0.1.0.tar.gz
.
File metadata
- Download URL: ezstruct-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2776974ac5328d5a82267ec6b8c49d5d6fb26580dec656e93ec54146401d0f |
|
MD5 | fc49082f6ffb99f5533e4b70dfbaaec6 |
|
BLAKE2b-256 | 6682edb807b2622082b15c56400fbe88301c238b5777aef86baab06bfabbd58e |
File details
Details for the file ezstruct-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: ezstruct-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86dcc03a4f784a0b7095e610e58409dced8a83fa1e27fcf8dd0c90c838413a6c |
|
MD5 | 3d991789eb8ec6036a02b0b37c1917ef |
|
BLAKE2b-256 | 4bee2c5c5773aa5023fc940e9504f71dee7f28b6d81dbc3e593b466da66b8bd4 |