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.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bitfactory-0.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bitfactory-0.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bitfactory-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1decaea64cb43d91c6673554b6a84a6c264bf6870772e2f95bf573bb97b91790
MD5 93853ce7ecbfe5f56cc445eed0b313a0
BLAKE2b-256 cb0b7941294d4cb3e37114ae599f9a770d69aeb6249e82eeb051dd960f216d5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bitfactory-0.2.0.tar.gz:

Publisher: release.yml on bearswithsaws/bitfactory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: bitfactory-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bitfactory-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 560f449c5b4d49e2176a70fc39a32468154a2d74e1f38c4157ca2f3a37077ca8
MD5 03b89026bdb01dec6ea2559c7c8ed784
BLAKE2b-256 3997e6c729e7dafbbe1de2023c6c2a6a04fa53bb5b1b07f326bea10341367c0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bitfactory-0.2.0-py3-none-any.whl:

Publisher: release.yml on bearswithsaws/bitfactory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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