Python is not able to do this automatically for you: you will need to create code to independently select all the data you need, placing them in a suitable Python data structure (or simply adding data to a unique byte string, where you will be knoe, where each element by its offset) - and they save this object to disk.
This is not a "Python" problem - this is exactly the problem that Python solves for you when you use Python objects and data. When encoding to C or lower, you are responsible for knowing not only your data, but also the length of each piece of data (and allocating memory for each chnk, as well as freeing it when this is done, etc. ) And this is what you need to do in this case.
Your data structure should give you not only pointers, but also the length of the data in each pointed location (in a sense or in a different way - if the pointer refers to another structure, "size_of" will work for you)
source share