(De)serializing a multiarraylist

Twice I have ran into this but have been using suboptimal solutions that require unnecessary allocations as I know the length of the MultiArrayList.

The current problem is actually a std.array_hash_map but it’s the same principle because it’s essentially the only interesting part to mostly deserialize.

Last time I tried this I ran into trouble due to the fact that MultiArrayList.sizes is private.

Here’s the current trash solution:

try deck.note_map.ensureTotalCapacity(gpa, note_count);

const ids = try gpa.alloc(Note.Id, note_count);
defer gpa.free(ids);
const indices = try gpa.alloc(u32, note_count);
defer gpa.free(indices);

var data = [_][]u8{
   mem.sliceAsBytes(ids),
   mem.sliceAsBytes(indices),
};
try r.readVecAll(&data);

for (ids, indices) |id, index| {
   deck.note_map.putAssumeCapacity(id, index);
}