#ifndef ka_buffer_h
#define ka_buffer_h

#include "inttypes.h"
#include "ka_error.h"

typedef struct ka_buffer_s ka_buffer_t;

ka_buffer_t* ka_new_buffer(ka_error_t* pErrorBlock, int windowsize, int size, int blocksize);
void ka_delete_buffer(ka_buffer_t**);

void ka_buffer_clear(ka_buffer_t*);
int ka_buffer_getByteCount(const ka_buffer_t*);
int ka_buffer_getUnstackedCount(const ka_buffer_t*);
int ka_buffer_getFreeCount(const ka_buffer_t*);

int ka_buffer_getUnstackedBlock(const ka_buffer_t*, const uint8_t** ppstart, const uint8_t** ppend);
int ka_buffer_getFreeBlock(const ka_buffer_t*, uint8_t** ppstart, uint8_t** ppend);

const uint8_t* ka_buffer_firstBlock(const ka_buffer_t*, const uint8_t* p1, const uint8_t* p2);
void ka_buffer_setRead(ka_buffer_t*, const uint8_t* pread /* use NULL for done */);
void ka_buffer_setStacked(ka_buffer_t*, const uint8_t* pparsed);
void ka_buffer_setWritten(ka_buffer_t*, uint8_t* pwrite);
int ka_buffer_compressUnstacked(ka_buffer_t*, ka_error_t* pErrorBlock, const uint8_t* end);

#endif
