Closed hadronzoo closed 8 years ago
Gloss, in its current form, isn't too great at these, but you can do it by defining a byte header, examining the bit, and defining the body according to what the bit tells you.
Wouldn't the header consume the entire byte? Unfortunately, nothing is aligned to byte boundaries, so one would need to specify codecs lengths in bits rather than bytes. It makes sense that gloss wouldn't handle these non-byte aligned formats, since they're rare and seem to be inefficient to parse.
The byte formats I'm familiar with that resemble this are variable-length integers, which use a bit in the current byte to indicate whether the next byte should be read in. That would work okay with the approach I suggest, something where a bit indicates that the byte that contains it shouldn't be read in would be difficult to handle.
Is there a way to handle codecs which are not byte-aligned? I'm trying to read a format which represents a vector using a 1-bit header before each value. The header determines whether there is another value to read.