I started writing a Python 3.x client application. The server application already exists and is written in C. The server provides a C header file with the definition of two structures used to send and receive data via UDP (I use the Python module socket). The problem is that C structures are quite large (about 200 elements each). If I use the Python module structfor packing / unpacking data, a not-so-elegant solution would be to pack / unpack 200 elements manually, for example:
struct.pack('H...I', data1, ..., data200)
Also, I want to have access to the received / sent items in Python using type C syntax. For example, if I do C server side
send.data.pos = pos;
it would be nice (most natural) if I can access the variable poson the Python client side as follows:
pos = recv.data.pos
Please note that the question is not how to automatically write the structure in Python from the header file, as in this thread (I have no problem writing each field of the structure one by one in Python), but rather what would be the best way organize data in Python (for example, in classes, using dictionaries, etc.), which will allow me to use Python functions and make the code simpler, and the data is easy (I would prefer to use only standard Python modules, without external software). What would be the most elegant way to achieve this?
jpmz source
share