in this example output buffer is sized exactly as the input buffer: program remain il loop.
if i resize the output buffer as sizeof(data)+1 it work, and leftover 1 byte
`
const char data[] = "Cappuccetto Rosso, chiamata anche Cappuccetto, e' una bambina che vive con la sua mamma in una casetta vicino al bosco. Un giorno la mamma le consegna un cestino pieno di cose buone da portare alla nonna malata, che vive al di la' della foresta. La mamma "; //256byte data
char compress[1500];
char out[sizeof(data)];
int Encode() {
heatshrink_encoder hse; //512byte in stack
heatshrink_encoder_reset(&hse);
size_t copied;
size_t tot_copied = 0;
const char* in=data;
size_t remaining = sizeof(data);
size_t srclen = remaining;
size_t readed;
do
{
heatshrink_encoder_sink(&hse, (uint8_t*)in, remaining, &readed);
in += readed;
remaining -= readed;
//printf("readed:%lu\n",readed);
heatshrink_encoder_poll(&hse, (uint8_t*)compress + tot_copied, sizeof(compress)- tot_copied,&copied);
tot_copied += copied;
//printf("copied:%lu tot:%lu\n",copied,tot_copied);
} while (remaining);
heatshrink_encoder_finish(&hse);
HSE_poll_res pres;
do
{
pres = heatshrink_encoder_poll(&hse, (uint8_t*)compress + tot_copied, sizeof(compress)- tot_copied,&copied);
tot_copied += copied;
} while (pres != HSER_POLL_EMPTY);
Uart_Printf(">>>>>>>>>>>>src:%lu dst:%lu\n", srclen, tot_copied);
return tot_copied;
}
int Decode(size_t remaining) {
HSD_sink_res sres;
HSD_poll_res pres;
HSD_finish_res fres;
heatshrink_decoder hsd;
heatshrink_decoder_reset(&hsd);
size_t tot_copied = 0;
size_t readed;
size_t copied;
const uint8_t* in = (const uint8_t*)compress;
do
{
sres =
heatshrink_decoder_sink(&hsd, in, remaining, &readed);
in += readed;
remaining -= readed;
//printf("readed:%lu\n",readed);
pres =heatshrink_decoder_poll(&hsd, (uint8_t*)out + tot_copied,sizeof(out)- tot_copied, &copied);
tot_copied += copied;
//printf("copied:%lu tot:%lu\n",copied,tot_copied);
} while (remaining);
fres = heatshrink_decoder_finish(&hsd);
do //REMAIN ON THIS LOOP FOREVER !!!
{
pres =heatshrink_decoder_poll(&hsd, (uint8_t*)out + tot_copied, sizeof(out) - tot_copied, &copied);
tot_copied += copied;
//printf("src:%lu dst:%lu\n",srclen,tot_copied);
} while (pres != HSER_POLL_EMPTY);
Uart_Printf(">>>>>>>>>>>>decompress:%lu\n", tot_copied);
return tot_copied;
}
void main() {
SysTimer_Init();
Uart_Init(Uart_STDOUT, 0); //console
int n=Encode();
Decode(n);
Uart_Println(out);
Uart_Println("end");
while (1);
}
`
in this example output buffer is sized exactly as the input buffer: program remain il loop.
if i resize the output buffer as sizeof(data)+1 it work, and leftover 1 byte
`
const char data[] = "Cappuccetto Rosso, chiamata anche Cappuccetto, e' una bambina che vive con la sua mamma in una casetta vicino al bosco. Un giorno la mamma le consegna un cestino pieno di cose buone da portare alla nonna malata, che vive al di la' della foresta. La mamma "; //256byte data
char compress[1500];
char out[sizeof(data)];
int Encode() {
heatshrink_encoder hse; //512byte in stack
heatshrink_encoder_reset(&hse);
size_t copied;
size_t tot_copied = 0;
const char* in=data;
size_t remaining = sizeof(data);
size_t srclen = remaining;
size_t readed;
do
{
heatshrink_encoder_sink(&hse, (uint8_t*)in, remaining, &readed);
in += readed;
remaining -= readed;
//printf("readed:%lu\n",readed);
heatshrink_encoder_poll(&hse, (uint8_t*)compress + tot_copied, sizeof(compress)- tot_copied,&copied);
tot_copied += copied;
//printf("copied:%lu tot:%lu\n",copied,tot_copied);
} while (remaining);
heatshrink_encoder_finish(&hse);
HSE_poll_res pres;
do
{
pres = heatshrink_encoder_poll(&hse, (uint8_t*)compress + tot_copied, sizeof(compress)- tot_copied,&copied);
tot_copied += copied;
} while (pres != HSER_POLL_EMPTY);
Uart_Printf(">>>>>>>>>>>>src:%lu dst:%lu\n", srclen, tot_copied);
return tot_copied;
}
int Decode(size_t remaining) {
HSD_sink_res sres;
HSD_poll_res pres;
HSD_finish_res fres;
heatshrink_decoder hsd;
heatshrink_decoder_reset(&hsd);
size_t tot_copied = 0;
size_t readed;
size_t copied;
const uint8_t* in = (const uint8_t*)compress;
do
{
sres =
heatshrink_decoder_sink(&hsd, in, remaining, &readed);
in += readed;
remaining -= readed;
//printf("readed:%lu\n",readed);
pres =heatshrink_decoder_poll(&hsd, (uint8_t*)out + tot_copied,sizeof(out)- tot_copied, &copied);
tot_copied += copied;
//printf("copied:%lu tot:%lu\n",copied,tot_copied);
} while (remaining);
fres = heatshrink_decoder_finish(&hsd);
do //REMAIN ON THIS LOOP FOREVER !!!
{
pres =heatshrink_decoder_poll(&hsd, (uint8_t*)out + tot_copied, sizeof(out) - tot_copied, &copied);
tot_copied += copied;
//printf("src:%lu dst:%lu\n",srclen,tot_copied);
} while (pres != HSER_POLL_EMPTY);
Uart_Printf(">>>>>>>>>>>>decompress:%lu\n", tot_copied);
return tot_copied;
}
void main() {
SysTimer_Init();
Uart_Init(Uart_STDOUT, 0); //console
int n=Encode();
Decode(n);
Uart_Println(out);
Uart_Println("end");
while (1);
}
`