I have a simple struct (nested struct of primitive types/enum) and want to load from/save to large file in chunks, sometimes in time-critical region. Right now I'm exploring my options.
I could use
Codable, but JSON doesn't seem to support random access (you have to parse the entire file). I don't want to load the entire file into memory. I could separate each chunk and encode/decode them independently, but then I don't know the upper limit of the encoded data size.
I could implement
BinaryEncoder/Decoderbut it is a lot of work for a single-use code.
I can make use of the new SE-0245 to load data from outside storage. The only problem is that I don't know how to make sure that the memory layout is fixed across version (post ABI stability is fine, I want to use SE-0245 after all). I suppose I can use
@frozen, but I'm not too sure how it works.
I think 3. looks promising. I suppose my question is Is there a way to fix a struct memory layout?. I don't need to know the layout, only that it doesn't change moving forward.
Any suggestion would be appreciated.