I’m attempting to find an optimal way of implementing “byte interleaving” from the RBXM specification in Luau, if you want a TLDR and dont want to read technical details, the operation im trying to implement is a matrix transposition
Assume an array of 4 u32 numbers, (little endian), 20, 30, 50 and 80, usually, in a byte stream this would be stored as.
20 00 00 00 30 00 00 00 50 00 00 00 80 00 00 00
However, with the interleaving, in the RBXM spec, this will be stored as
20 30 50 80 00 00 00 00 00 00 00 00 00 00 00 00
Another way to look at this, is a matrix where the columns are each byte in the u32, and the rows are each number, the size of the matrix would be (sizeof type)x(number of numbers), for example, 10 u64 objects would have a matrix size of 8x10
| n1 | n2 | n3 | n4 |
|---|---|---|---|
| 20 | 00 | 00 | 00 |
| 30 | 00 | 00 | 00 |
| 50 | 00 | 00 | 00 |
| 80 | 00 | 00 | 00 |
,and after the transposition this would appear as
| n1 | n2 | n3 | n4 |
|---|---|---|---|
| 20 | 30 | 50 | 80 |
| 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 |
As I sated before, this operation is a matrix transposition, so I’m curious what an optimal way of doing this in Lua is (or even if a matrix transposition is the best thing to do since the sequence is linear)