Creating a structure from bytes with ctypes and IronPython
- by Adal
I have the following CPython code which I now try to run in IronPython:
import ctypes
class BarHeader(ctypes.Structure):
_fields_ = [
("id", ctypes.c_char * 4),
("version", ctypes.c_uint32)]
bar_file = open("data.bar", "rb")
header_raw = bar_file.read(ctypes.sizeof(BarHeader))
header = BarHeader.from_buffer_copy(header_raw)
The last line raises this exception: TypeError: expected array, got str
I tried BarHeader.from_buffer_copy(bytes(header_raw)) instead of the above, but then the exception message changes to TypeError: expected array, got bytes.
Any idea what I'm doing wrong?