#ifndef __bitbuffer_H
#define __bitbuffer_H

#include <stdint.h>

typedef struct
{
	uint8_t* start;
	uint8_t* free;
	uint8_t* data;
	uint8_t* last;
	int32_t  size;
	int32_t  count;
	int32_t  bitindex;
} bytebuf;

unsigned int bs_get1bit(bytebuf* bs);
unsigned int bs_getbits(bytebuf* bs, int N);
int bs_getsbits(bytebuf* bs, int N);
unsigned int bs_peekbits(const bytebuf* bs, int N);
unsigned int bs_bitcount(const bytebuf* bs);
void bs_align(bytebuf* bs);
void bs_skipbits(bytebuf* bs, int N);
unsigned int bs_skipBytes(bytebuf* bs, unsigned int N);
bool bs_peekBytes(const bytebuf* bs, uint8_t* p, int N);
bool bs_getBytes(bytebuf* bs, uint8_t* p, int N);
bool bs_getInt(bytebuf* bs, uint32_t* val, int N);
int bs_getUnary(bytebuf* bs, bool b);

#endif
