I recently inherited a project where we deserialize a bunch of data written out by a system that I cannot change (wish they used a standard serializer, but I cannot change this). For the most part, I was able to use ctypes to represent the structures and cast the data right into Python, but we have some cases where the underlying data structures are a mess (again, something I cannot change no matter how much I have tried). The 2 cases that are driving me nuts trying to find an efficient way are when the c structures are defined like this:
Simple Case:
struct b{
int data;
int more_data;
};
struct a{
int num_entries;
b* data;
};
Which, when it was serialized, packed the b* data into memory as if it were a static array deceleration.
And here comes the most horrible case I have to deal with:
struct c{
int a;
int b;
};
struct b{
int random_data;
c* data;
int more_data;
};
struct a{
int len; // This actually defines the length in struct b for "data" array size
b nested_data;
c why_not_it_is_this_poorly_organized;
}
Any help would sure be appreciated!