I have a structure defined like so in C++ :
typedef struct __attribute__((packed)){
uint16_t nb_elements; //2 bytes
struct __attribute__((packed)){ // 6 bytes
uint8_t identifier1; // 1 byte
uint8_t identifier2; // 1 byte
float my_data; // 4 bytes
} element[];
} sElements;
(notice that element structures are nested in sElements structure).
I want to do the same thing in Python (using ctypes), and I am struggling at this point :
from ctypes import *
class element(Structure):
_fields_ = [("identifier1", c_uint, 8),
("identifier2", c_uint, 8),
("my_data", c_float, 64)]
class sElements(Structure):
_fields_ = [("nb_elements", c_uint, 16)
#I don't know what to put here !
]
How could I reproduce this nested structure array in Python ?
classwould be way easier...Serialwhat you need to know is how the bytes will be arranged on the wire, not how they will appear in memory. They are not the necessarily the same.