Closed mvdan closed 6 years ago
I'll consider a read_u24le method. It (and/or the big-endian variant) might be useful when reading RGB (red, green, blue) triples, not just for zstd...
Appreciation commit :) https://github.com/mvdan/zstd/commit/9f48d9aba0c5a6f71164d625e96e2b889d36354e
This is just another question that has popped in my mind. Not necessarily a bug report.
It's quite common to have to read numbers from any number of bits or bytes, not just the power-of-two sizes like u8, u16, and u32.
For example, when implementing zstd, in a couple of places I need to read a three-byte little endian number. At the moment, I am doing something like:
Is there a better way? Or rather, should there be a better way?
I realise that this isn't strictly necessary, and that languages like Go with their
encoding/binary
packages don't support such a thing either out of the box. But this language being precisely for encoders and decoders, I wonder if such an "arbitrary byte length" or even "arbitrary bit length" functionality would be possible.Ideally, I'd instead write something like: