ByteEnum

class bpod_core.misc.ByteEnum

Bases: IntEnum

An IntEnum restricted to single-byte values (0–255).

Subclass this to define enums whose integer values fit in one unsigned byte. Each member additionally exposes its value as a bytes object via byte_value for zero-allocation wire encoding.

Raises:

OverflowError – If a member’s value is outside the range of a single, unsigned byte.

Examples

Subclass ByteEnum to create a custom enum type:

>>> class Color(ByteEnum):
...     RED = 1
...     GREEN = 2

It can be used like a regular IntEnum:

>>> Color.RED.value
1

Additionally, you can access it’s values as bytes objects:

>>> Color.RED.byte_value
b'\x01'
property byte_value: bytes

The member’s value as a bytes object.