I'm currently working on implementing caching for the build/
folder. Based on the latest commit in main, it looks like I should be serializing the canonicalize.IR struct, but I it doesn't seem like there's a built in way to serialize structs in zig.
Before I try and write this logic on my own, I want to double check that this is indeed the case and I'm not just missing something obvious.
I don't have a link at the moment. Can share once back at my computer, but Andrew shared an example from one of his apps.
But yeah, it is manual. Basically write out the offsets and lengths of each array then write out the bytes of the data.
Thanks! It’s probably more maintainable writing it out manually anyway.
Here is an example of loading: https://codeberg.org/andrewrk/groovebasin/src/commit/9022521c445c2ba398f2f646aa24241ecd1a715a/shared/Db.zig#L576-L634
Note the file header type at the bottom of the file. Basically saving is making an equivalent of that, writing it out, then writing out all of the arrays as raw bytes.
Found the saving code too: https://codeberg.org/andrewrk/groovebasin/src/commit/9022521c445c2ba398f2f646aa24241ecd1a715a/server/main.zig#L1311-L1342
thanks to https://ziglang.org/download/0.14.0/release-notes.html#ptrCast-Allows-Changing-Slice-Length you can use @ptrCast
there instead of sliceAsBytes / bytesAsSlice
Last updated: Jul 06 2025 at 12:14 UTC