Registry / serialization / cbitstruct

cbitstruct

JSON →
library1.2.0pypypi✓ verified 35d ago

cbitstruct is a Python library providing a faster C implementation of `bitstruct`. It offers API compatibility with `bitstruct`, allowing for efficient packing and unpacking of bitfields from and to Python data types. The current version is 1.2.0, and releases primarily focus on Python version support and bug fixes, with a focus on stability and performance.

serialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from cbitstruct import pack
from cbitstruct import unpack
from cbitstruct import byteswap

This quickstart demonstrates packing and unpacking bitfields using `cbitstruct`. It's designed to be API compatible with the original `bitstruct` library, allowing for a drop-in replacement for performance-critical applications.

from cbitstruct import pack, unpack # Pack 8 single-bit unsigned integers into a byte data = pack('u1u1u1u1u1u1u1u1', 1, 0, 1, 0, 1, 0, 1, 0) print(f"Packed data: {data!r}") # Expected: b'\xaa' # Unpack the data back into a tuple of integers unpacked_data = unpack('u1u1u1u1u1u1u1u1', data) print(f"Unpacked data: {unpacked_data}") # Expected: (1, 0, 1, 0, 1, 0, 1, 0) # Example with different format string value = pack('u4u4', 0xA, 0x5) print(f"Packed nibbles: {value!r}") # Expected: b'\xa5'
Debug
Known footguns
gotchaIncorrect usage of format strings or input values can lead to segmentation faults due to `cbitstruct` being a C extension. This was particularly prevalent in early versions (1.0.0 - 1.0.3).
gotchaWhile `cbitstruct` aims for full API compatibility with `bitstruct`, subtle differences in edge cases or error handling might exist. Always test thoroughly when replacing `bitstruct` with `cbitstruct` in critical paths.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources