static const unsigned bitreservoir_fill_size = 8 * sizeof(bitreservoir_fill_t);
static const unsigned bytereservoir_size = 4096;
static const unsigned bitreservoir_fill_size = 8 * sizeof(bitreservoir_fill_t);
static const unsigned bytereservoir_size = 4096;
// A return value of -1 indicates error, a return value of 0 indicates EOF.
typedef ssize_t (input_func_t)(void*, uint8_t*, size_t);
// A return value of -1 indicates error, a return value of 0 indicates EOF.
typedef ssize_t (input_func_t)(void*, uint8_t*, size_t);
// Short-term bit reservoir; holds up to 64 bits. When it's empty,
// it needs to get refilled from the medium-term bit reservoir.
bitreservoir_t bits;
// Short-term bit reservoir; holds up to 64 bits. When it's empty,
// it needs to get refilled from the medium-term bit reservoir.
bitreservoir_t bits;
// Make sure there's at least NUM_BITS available in the short-term bit reservoir.
// You usually want to call this before read_bits(). The reason it's separate
// is that if you want two reads and you know the size of both, it's faster to
// refill A+B, read A, read B than refill A, read A, refill B, read B.
// Make sure there's at least NUM_BITS available in the short-term bit reservoir.
// You usually want to call this before read_bits(). The reason it's separate
// is that if you want two reads and you know the size of both, it's faster to
// refill A+B, read A, read B than refill A, read A, refill B, read B.
{
assert(source->bits_available >= num_bits);
unsigned ret = (source->bits >> (bitreservoir_size - num_bits));
{
assert(source->bits_available >= num_bits);
unsigned ret = (source->bits >> (bitreservoir_size - num_bits));