class my_struct(ctypes.Structure):
    _fields_ = [('_buffer', ctypes.c_byte * BUFSIZE), ('size', ctypes.c_int)]

def buffer():

    def fget(self):
        return ctypes.string_at(self._buffer, self.size)

def fset(self, value):
    size = len(value)
if size > BUFSIZE:
    raise ValueError('value %s too large for buffer', repr(value))
How do I build a python string from a ctype struct?