Skip to content

Ctypes

On-the-fly endianness switching for ctypes structures.

We cannot make use of ctypes.LittleEndianStructure and ctypes.BigEndianStructure, since these use metaclass hooks to catch fields being set when the class is declared.

We need to catch on the fly. We do this by swapping out the base classes of the Structure type, and incurring a performance penalty for foreign-endianness targets.

Structure = ctypes.LittleEndianStructure module-attribute

module = sys.modules[__name__] module-attribute

update()