void init_bit_source(struct bit_source* source, input_func_t* input_func, void* userdata)
{
memset(source, 0, sizeof(*source));
void init_bit_source(struct bit_source* source, input_func_t* input_func, void* userdata)
{
memset(source, 0, sizeof(*source));
void possibly_refill_slow_path(struct bit_source* source, unsigned num_bits)
{
// First, make sure there's stuff in the byte reservoir if we can.
void possibly_refill_slow_path(struct bit_source* source, unsigned num_bits)
{
// First, make sure there's stuff in the byte reservoir if we can.
// Read data from the source until we have enough to satisfy the request.
while (source->bits_available + 8 * source->bytes_available < num_bits) {
// Read data from the source until we have enough to satisfy the request.
while (source->bits_available + 8 * source->bytes_available < num_bits) {
const ssize_t bytes_read =
(*source->input_func)(source->userdata,
source->bytes + source->bytes_available,
const ssize_t bytes_read =
(*source->input_func)(source->userdata,
source->bytes + source->bytes_available,
// Fill the bit reservoir one by one byte until we have enough.
while (source->bits_available < num_bits) {
assert(source->bytes_available > 0);
// Fill the bit reservoir one by one byte until we have enough.
while (source->bits_available < num_bits) {
assert(source->bytes_available > 0);