#ifndef CLAM_ADC_H
#define CLAM_ADC_H

struct adc_stream {
    uint8_t *next_in;
    size_t avail_in;
    size_t total_in;

    uint8_t *next_out;
    size_t avail_out;
    size_t total_out;

    /* internals */
    uint8_t *buffer;
    uint8_t *curr;

    uint32_t buffered;
    uint16_t state;
    uint16_t length;
    uint32_t offset;
};
typedef struct adc_stream adc_stream;

#define ADC_BUFF_SIZE 65536

#define    ADC_MEM_ERROR -1
#define    ADC_DATA_ERROR -2
#define    ADC_IO_ERROR -3
#define    ADC_OK 0
#define    ADC_STREAM_END 1

enum adc_state {
    ADC_STATE_UNINIT = 0,
    ADC_STATE_GETTYPE = 1,
    ADC_STATE_RAWDATA = 2,
    ADC_STATE_SHORTOP = 3,
    ADC_STATE_LONGOP2 = 4,
    ADC_STATE_LONGOP1 = 5,
    ADC_STATE_SHORTLOOK = 6,
    ADC_STATE_LONGLOOK = 7
};

/* Compression phrases
 * store phrase - 1 byte header + data, first byte 0x80-0xFF, max length 0x80 (7 bits + 1), no offset
 * short phrase - 2 byte header + data, first byte 0x00-0x3F, max length 0x12 (4 bits + 3), max offset 0x3FF (10 bits)
 * long phrase  - 3 byte header + data, first byte 0x40-0x7F, max length 0x43 (6 bits + 4), max offset 0xFFFF (16 bits)
 */

int adc_decompressInit(adc_stream *strm);
int adc_decompress(adc_stream *strm);
int adc_decompressEnd(adc_stream *strm);

#endif