Skip to main content

Create structured binary data easily.

Project description

Coverage Pytest

BitFactory

A module designed to facilitate quick and easy structured binary data creation allowing for the automatic adjustments of types such as lengths, checksums, etc of the modeled data.

Install

pip install bitfactory

Usage

An example for data strucured as follows:

  • Type: Unsigned Byte
  • Length: Unsigned Big-Endian Short that encompasses the Data and Checksum
  • Data:
    • Unsigned 32 bit Int
    • Unsigned Byte
  • Checksum: Unsigned Short that is calculated over the above Data portion only
def csum(data: bytes) -> int:
    checksum = 0
    for value in data:
        checksum += value
    return checksum

data = BFContainer()
data.type = BFUInt8(1)
data.body = BFLength(BFUInt16(endian=BFEndian.BIG), BFContainer())
data.body.checksumed = BFContainer()
data.body.checksumed.data = BFUInt32(0xAABBCCDD)
data.body.checksumed.data2 = BFUInt8(10)
data.body.checksum = BFCallableRef(BFUInt16(), csum, "checksumed")
assert b"\x01\x00\x07\xdd\xcc\xbb\xaa\n\x18\x03" == data.pack()

>>> print(data)
+None
| |- Unsigned Byte 0x01 : type
| +body length: 0x7
|  +checksumed
|   |- Unsigned Long 0xAABBCCDD : data
|   |- Unsigned Byte 0x0A : data2
|  +checksum value: 0x318

Project details


Download files

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

Source Distribution

bitfactory-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

bitfactory-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file bitfactory-0.1.0.tar.gz.

File metadata

  • Download URL: bitfactory-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for bitfactory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87efa54355b12d9d4e0fac8a213fb99f6acb64f44408cecdc3efc542aeb9c2d6
MD5 b8b925362b775505d29444b718761373
BLAKE2b-256 914697786489bce05ec695d193a650b6496faf70572118c830ac2f2b1035acd8

See more details on using hashes here.

File details

Details for the file bitfactory-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bitfactory-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for bitfactory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0e3e8c11d3369155538ce2ee171c1df4c134169c57b54159c5086041af86850
MD5 ac1d1df2ca7390d833644b25f293ed56
BLAKE2b-256 2cb329bf161a64d55273cff95d122a04594aaf60ca13cda3954013aeda5683b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page