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])