I’m getting close to finishing my classic game remake, and I have to start thinking about a stable save file format. So far, I’ve just dumped parts of the state to a JSON file using ppx_deriving_yojson, and obviously that doesn’t provide any backwards compatibility, which is necessary post 1.0.
Since handling serialization formats is painful (and duplicated work), I had the idea of making a serialization ppx that allows for annotating different fields with versions. For example, suppose that a label of my record only appeared at version 1.1. By annotating this label with the version number (e.g. [@version "1.1"]) it would know to use a default value function when loading this field. Of course, this could only tolerate minor adjustments rather than complete modifications, but one could imagine a few other minor instructions like renames, deletions etc. The point is not to destroy save files on every minor change.
Does anyone know of such a feature, or of something similar?
Alternative option. Always assume the latest format of your save-file, but have a separate upgrade_save_file function that will convert v1 to v2,3,4 and run that at startup.
Won’t really work if people share files around a lot, but if you just want to handle upgrades it keeps all the “fiddly stuff” in one place and only requires one version number at the top-level.
Otherwise most of the versioned-format stuff I can think of is protocol-related (protobuf, flatbuf etc) - lots of alternatives in that space.