I am writing a compression algorithm in Rust.
I have a "conversion table" which maps input bytes to outputs (each output is a u64 which is the code, and a u8 which is the length of the code, which need not be a multiple of 8). For each input byte, I find the corresponding output and bit-shift the code into a large contiguous array of u64s. I then want to write this array of u64s to a file.
What would be the best way to convert the [u64; WRITE_CHUNK_SIZE] to a [u8; 8 * WRITE_CHUNK_SIZE]?
Is looping through [u64; WRITE_CHUNK_SIZE], calling to_be_bytes() on each u64, writing each byte of this to the [u8; 8*WRITE_CHUNK_SIZE] the best I can do?
I saw examples of align_to which required unsafe, which seems excessive just to convert data types. I also saw this which outputs a Vec. I think this just pushes the problem down the road, though, because I still have to convert that Vec<u8> into an [u8] to write to the file. Am I wrong?