#ifndef buffer_h
#define buffer_h

typedef struct
{
	int	bitindex;
	char*	start;
	char*	free;
	char*	data;
	char*	last; // data + size - 1
	int	size;
	int	count;
} bytebuf;

// for use by mp3b. hbuff
//unsigned int	bs_bitcount(const bytebuf*);
#define bs_bitcount(x) ((x)->count)
unsigned int	bs_bytecount(const bytebuf* bs);
void		bs_init(bytebuf*, char*, int size);
void		bs_fixcount(bytebuf*);
unsigned int	bs_get1bit(bytebuf*);
unsigned int	bs_getbits8(bytebuf*, int);
unsigned int	bs_getbits(bytebuf*, int);
int		bs_peekBytes(const bytebuf* bs, char* p, int N);

// for use by hbuff
void		bs_buildmask(bytebuf* bs, unsigned int* pval, int* pnum);
void		bs_refreshmask(bytebuf* bs, unsigned int* pval, int* pnum);
void		bs_transferBytes(bytebuf*, bytebuf*, int);
void		bs_adjustNbits(bytebuf*, int);
int		bs_keepBytes(bytebuf*, int);
void		bs_skipBytes(bytebuf*, unsigned int);

#endif
