How to convert a binary data into c_ubyte_Array_64 in python
Solution 1:
Listing [Python.Docs]: ctypes - A foreign function library for Python.
>>> import ctypes as ct >>> >>> messages = { ... "RESET": b"\x00\x00\x00\x00\x00\x00\x00\x01", ... } >>> >>> UByteArr64 = ct.c_ubyte * 64 # Create the array type >>> >>> arr = UByteArr64(*messages["RESET"]) # Create an array instance (by unpacking the byte sequence) >>> >>> arr <__main__.c_ubyte_Array_64 object at 0x0000015C81D74C40> >>> arr[0:16] [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] >>> >>> >>> # Or, in one line: >>> (ct.c_ubyte * 64)(*messages["RESET"]) <__main__.c_ubyte_Array_64 object at 0x0000015C81DBA240>