I'm trying to pack some unsigned int data into a string buffer created using ctypes.create_string_buffer.
Here is the following code segment, and a running example showing the error on codepad:
import struct
import ctypes
import binascii
buf = ctypes.create_string_buffer(16)
struct.pack_into("=I=I=I", buf, 0, 1, 2, 3)
print binascii.hexlify(buf)
This yields the following error:
...
struct.error: bad char in struct format
The documentation doesn't allude to whether you can pack data of different types if the underlying buffer is of a specific C type. In this case, trying to pack unsigned int data into a string buffer with an underlying c_char type. Anyone know of a solution to do this, or is there a specific way to create a buffer that can pack any type of data?