return ntohl(*(bitreservoir_fill_t*)(source));
}
-static const unsigned bitreservoir_size = 8 * sizeof(bitreservoir_t);
-static const unsigned bitreservoir_fill_size = 8 * sizeof(bitreservoir_fill_t);
-static const unsigned bytereservoir_size = 4096;
+static const unsigned BITRESERVOIR_SIZE = 8 * sizeof(bitreservoir_t);
+static const unsigned BITRESERVOIR_FILL_SIZE = 8 * sizeof(bitreservoir_fill_t);
+static const unsigned BYTERESERVOIR_SIZE = 4096;
// A function to read bytes from some input source. The bytes should be
// already unstuffed (and thus without markers).
// refill A+B, read A, read B than refill A, read A, refill B, read B.
static inline void possibly_refill(struct bit_source* source, unsigned num_bits)
{
- assert(num_bits <= bitreservoir_fill_size + 1);
+ assert(num_bits <= BITRESERVOIR_FILL_SIZE + 1);
if (source->bits_available >= num_bits) {
// Fast path (~90% of invocations?)
}
// Slower path (~99% of remaining invocations?)
- assert(source->bits_available + bitreservoir_fill_size < bitreservoir_size);
+ assert(source->bits_available + BITRESERVOIR_FILL_SIZE < BITRESERVOIR_SIZE);
if (source->bytes_available >= sizeof(bitreservoir_fill_t)) {
bitreservoir_fill_t fill = read_bitreservoir_fill(source->bytes);
source->bytes += sizeof(bitreservoir_fill_t);
source->bytes_available -= sizeof(bitreservoir_fill_t);
- source->bits |= (bitreservoir_t)fill << (bitreservoir_size - bitreservoir_fill_size - source->bits_available);
- source->bits_available += bitreservoir_fill_size;
+ source->bits |= (bitreservoir_t)fill << (BITRESERVOIR_SIZE - BITRESERVOIR_FILL_SIZE - source->bits_available);
+ source->bits_available += BITRESERVOIR_FILL_SIZE;
return;
}
static inline unsigned read_bits(struct bit_source* source, unsigned num_bits)
{
assert(source->bits_available >= num_bits);
- unsigned ret = (source->bits >> (bitreservoir_size - num_bits));
+ unsigned ret = (source->bits >> (BITRESERVOIR_SIZE - num_bits));
source->bits <<= num_bits;
source->bits_available -= num_bits;
return ret;
}
+static inline unsigned peek_bits(struct bit_source* source, unsigned num_bits)
+{
+ assert(source->bits_available >= num_bits);
+ return (source->bits >> (BITRESERVOIR_SIZE - num_bits));
+}
+
#endif /* !defined(_INPUT_H) */