Creating a structure from bytes with ctypes and IronPython
Posted
by Adal
on Stack Overflow
See other posts from Stack Overflow
or by Adal
Published on 2010-05-08T21:52:51Z
Indexed on
2010/05/08
21:58 UTC
Read the original article
Hit count: 284
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?
© Stack Overflow or respective owner