Construct-dataclasses

Latest version: v1.1.10

Safety actively analyzes 706267 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 2

1.1.2

With this patch release you will be able to parse structures even with optional field declarations. Here's an example:
python
dataclass_struct
class Theme:
magic: bytes = csfield(cs.Const(b"THM"))
flags: int = csfield(cs.Int32ul)
compression: CompressionMagic = tfield(
CompressionMagic, cs.Enum(cs.Int32ul, CompressionMagic)
)
Optional sub dataclass struct
theme_cbck: ThemeCBCK = subcsfield(
ThemeCBCK, cs.Optional(ThemeCBCK.struct)
)
length: int = csfield(cs.Int32ul)
data: bytes = csfield(cs.Bytes(cs.this.length))


**Full Changelog**: https://github.com/MatrixEditor/construct-dataclasses/compare/v1.1.1...v1.1.2

1.1.1

Now, using this compact Python package (consisting of just a single file), you have the capability to define Python classes and effortlessly parse binary streams into those classes. For instance:

python
import construct as cs
from construct_dataclasses import dataclass_struct, csfield

dataclass_struct
class Image:
width: int = csfield(cs.Int8ub)
height: int = csfield(cs.Int8ub)
pixels: list[int] = csfield(cs.Array(cs.this.width * cs.this.height, cs.int8ul))

Parse binary stream
i = Image.parser.parse(b"\x02\x03\x00\x01\x00\x01\x00\x01")
returns: Image(width=2, width=3, pixels=[0,1,0,1,0,1])

Page 2 of 2

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.