I have a ctypes structure (for example):
from ctypes import *
class Foo(Structure):
_fields_ = [('f1',c_uint),
('f2',c_uint)]
I would like to copy an instance of that structure in to a buffer that was created from create_string_buffer (that is larger in size than needed for a single instance of Foo).
Example:
f = Foo()
f.f1=1; f.f2=2;
buf = create_string_buffer(100)
buf[0:sizeof(f)] = f
I know you can read and write data to/from structures on file objects (i.e. open('bar','rb').readinto(f) ), so it seems that there should be some way to do this easily too...