Python: Extracting data from buffer with ctypes -


I am able to call a function successfully with ctypes in Python. I now have a buffer that is full of data structure that I want to remove. What is the best strategy for this?

Function:

  class list (): def __init __ (self): # [...] def getdirentries (self, path): self.load_c () Self.fd = os.open (path, os.O_RDONLY) self.statinfo = os.fstat (self.fd) self.buffer = ctypes.create_string_buffer (self.statinfo.st_size) nbytes = self.statinfo .st_size transferred_bytes = self .libc.getdirentries (self.fd, ctypes.byref (self.buffer), nbytes, ctypes.byref (self.basep)) # [...]  

structure:

  class dirent (ctypes.Structure): _fields_ = [("d_fileno", ctypes.c_uint32), # / * file number of entry / ("d_reclen", ctypes.c_uint16), this record The length of the string in the # / * length * / ("d_type", ctypes.c_uint8), # / * file type * / ("d_namlen", ctypes.c_uint8), # / * d_name * / ("D_name", ctype S.c_char * (MAXNAMELEN + 1))]  

Some output:
transferred bytes: 156
sizeof buffer: 272
buffer: & lt; Ctypes.c_char_Array_272 0x8c3f0 on Object & gt;

I wonder why you are using generally, when you have data There are buffers that you want to pass in and out of C, if you have to call STATINFO and OS path.walk () instead of OSSAT To do this, use the composition module pack and unpack.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -