sinbad / SPUD

Steve's Persistent Unreal Data library
MIT License
308 stars 45 forks source link

Custom structure which contain arrays of structures or not supported data types #21

Closed shoooxz closed 2 years ago

shoooxz commented 2 years ago

Hello, Is it a good approach to save custom structures with arrays of custom structures or even with maps? I am wondering how it actually works with versioning. I was testing a bit and data is preserved. Regards

sinbad commented 2 years ago

For your own custom data storage for things not supported by SPUD, best practice to support breaking changes to the data would be to use FSpudChunk to add a wrapper of metadata around your own data - this provides you with a "magic" identifier of the chunk of data and also the length of that data, which are both useful in upgrade scenarios. You can change magic ID when you make breaking changes, and detect the previous one to upgrade it. Or if you want to ignore outdated chunks, you can skip over them because it knows the length.

You can either subclass FSpudChunk for each section of data, where the subclass provides the magic ID, which is what SPUD does most of the time, or use FSpudAdhocWrapperChunk which means you don't need a specialised struct of your own and just provide the magic ID as an argument.

sinbad commented 2 years ago

FYI this approach is loosely based on the IFF format