NEWS:
* Switching endianness mid-byte no longer potentially re-reads bytes.
* bit_offset now consistently refers to the number of bits already
  read.
* HParsedTokens now have a bit_length field; this is a size_t.  This
  may be removed for memory reasons.

The bit writer has not yet been updated to match; the result of
switching bit writer endianness in the middle of a byte remains
undefined.
This commit is contained in:
TQ Hirsch 2015-01-04 04:00:09 +01:00
parent 58af99ae40
commit af73181cf4
12 changed files with 86 additions and 48 deletions

View file

@ -11,19 +11,9 @@ static void switch_bit_order(HInputStream *input)
{
assert(input->bit_offset <= 8);
if((input->bit_offset % 8) != 0) {
// switching bit order in the middle of a byte
// we leave bit_offset untouched. this means that something like
// le(bits(5)),le(bits(3))
// is equivalent to
// le(bits(5),bits(3)) .
// on the other hand,
// le(bits(5)),be(bits(5))
// will read the same 5 bits twice and discard the top 3.
} else {
// flip offset (0 <-> 8)
input->bit_offset = 8 - input->bit_offset;
}
char tmp = input->bit_offset;
input->bit_offset = input->margin;
input->margin = tmp;
}
static HParseResult *parse_endianness(void *env, HParseState *state)