3.2.2.5. Bit-field Extensions#

The introduced Bitfield class is special in many different ways. One key attribute is its fixed size. To determine the size of a struct, it leverages a special member, which can be either a function or an attribute.

object.__bits__(self)#

Called to measure the bit count of the current object. __bits__() serves as the sole requirement for the defined fields in the current implementation of the Bitfield class.

Note

This class member can also be expressed as an attribute. The library automatically adapts to the appropriate representation based on the context.

object.__signed__(self)#

Proposed for future use - currently unused

Derived Protocols#

class _SupportsBits#
__bits__(self) int#
class _ContainsBits#
__bits__: int#