pystructtype.bitstype

BitsType: Base class for bitfield structs.

Classes

BitsType

Base class for bitfield structs. Subclasses must define __bits_type__ and __bits_definition__.

Module Contents

class pystructtype.bitstype.BitsType[source]

Bases: pystructtype.structdataclass.StructDataclass

Base class for bitfield structs. Subclasses must define __bits_type__ and __bits_definition__.

__bits_type__: ClassVar[type][source]
__bits_definition__: ClassVar[dict[str, int | list[int]] | collections.abc.Mapping[str, int | list[int]]][source]
_raw: int[source]
_meta: dict[str, int | list[int]][source]
classmethod __init_subclass__(**kwargs: object) None[source]

Initialize subclass by setting up bitfield attributes and type annotations. Ensures __bits_type__ and __bits_definition__ are present, wraps definition in MappingProxyType, and sets up class-level fields and annotations for each bitfield.

__post_init__() None[source]

Post-initialization to set up the _meta attribute from the class definition.

_decode(data: list[int]) None[source]

Decode the bitfield from a list of integers, updating the boolean attributes according to the bit positions defined in _meta.

_encode() list[int][source]

Encode the boolean attributes into a list of integers representing the bitfield. Updates _raw and returns the encoded list for further processing.