Skip to content
Snippets Groups Projects
Commit 480ceca5 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

deflate: return number of bytes written to output

parent 9a8071e7
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define DEFLATE_ERR_FCHECK (-7) #define DEFLATE_ERR_FCHECK (-7)
#define DEFLATE_ERR_NLEN (-8) #define DEFLATE_ERR_NLEN (-8)
int8_t deflate(unsigned char *input_buf, uint16_t input_len, int16_t deflate(unsigned char *input_buf, uint16_t input_len,
unsigned char *output_buf, uint16_t output_len); unsigned char *output_buf, uint16_t output_len);
int8_t deflate_zlib(unsigned char *input_buf, uint16_t input_len, int16_t deflate_zlib(unsigned char *input_buf, uint16_t input_len,
unsigned char *output_buf, uint16_t output_len); unsigned char *output_buf, uint16_t output_len);
...@@ -51,7 +51,7 @@ int main(void) ...@@ -51,7 +51,7 @@ int main(void)
for (uint8_t i = 0; i < 5; i++) { for (uint8_t i = 0; i < 5; i++) {
counter.start(); counter.start();
int8_t ret = deflate_zlib((unsigned char*)deflate_input, sizeof(deflate_input), deflate_output, sizeof(deflate_output)); int16_t ret = deflate_zlib((unsigned char*)deflate_input, sizeof(deflate_input), deflate_output, sizeof(deflate_output));
counter.stop(); counter.stop();
kout << "deflate returned " << ret << endl; kout << "deflate returned " << ret << endl;
kout << "Output: " << (char*)deflate_output << endl; kout << "Output: " << (char*)deflate_output << endl;
......
...@@ -400,11 +400,12 @@ static int8_t deflate_dynamic_huffman() ...@@ -400,11 +400,12 @@ static int8_t deflate_dynamic_huffman()
deflate_lld_lengths + hlit, hdist); deflate_lld_lengths + hlit, hdist);
} }
int8_t deflate(unsigned char *input_buf, uint16_t input_len, int16_t deflate(unsigned char *input_buf, uint16_t input_len,
unsigned char *output_buf, uint16_t output_len) unsigned char *output_buf, uint16_t output_len)
{ {
uint8_t is_final = input_buf[0] & 0x01; uint8_t is_final = input_buf[0] & 0x01;
uint8_t block_type = (input_buf[0] & 0x06) >> 1; uint8_t block_type = (input_buf[0] & 0x06) >> 1;
int8_t ret;
#ifdef DEFLATE_DEBUG #ifdef DEFLATE_DEBUG
kout << "is_final=" << is_final << " block_type=" << block_type << endl; kout << "is_final=" << is_final << " block_type=" << block_type << endl;
#endif #endif
...@@ -416,20 +417,28 @@ int8_t deflate(unsigned char *input_buf, uint16_t input_len, ...@@ -416,20 +417,28 @@ int8_t deflate(unsigned char *input_buf, uint16_t input_len,
deflate_output_now = output_buf; deflate_output_now = output_buf;
deflate_output_end = output_buf + output_len; deflate_output_end = output_buf + output_len;
if (block_type == 0) { switch (block_type) {
return deflate_uncompressed(); case 0:
ret = deflate_uncompressed();
break;
case 1:
ret = deflate_static_huffman();
break;
case 2:
ret = deflate_dynamic_huffman();
break;
default:
return DEFLATE_ERR_BLOCK;
} }
if (block_type == 1) {
return deflate_static_huffman(); if (ret < 0) {
} return ret;
if (block_type == 2) {
return deflate_dynamic_huffman();
} }
return DEFLATE_ERR_BLOCK; return deflate_output_now - output_buf;
} }
int8_t deflate_zlib(unsigned char *input_buf, uint16_t input_len, int16_t deflate_zlib(unsigned char *input_buf, uint16_t input_len,
unsigned char *output_buf, uint16_t output_len) unsigned char *output_buf, uint16_t output_len)
{ {
if (input_len < 4) { if (input_len < 4) {
...@@ -457,11 +466,11 @@ int8_t deflate_zlib(unsigned char *input_buf, uint16_t input_len, ...@@ -457,11 +466,11 @@ int8_t deflate_zlib(unsigned char *input_buf, uint16_t input_len,
return DEFLATE_ERR_FCHECK; return DEFLATE_ERR_FCHECK;
} }
uint8_t ret = int16_t ret =
deflate(input_buf + 2, input_len - 2, output_buf, output_len); deflate(input_buf + 2, input_len - 2, output_buf, output_len);
#ifdef DEFLATE_CHECKSUM #ifdef DEFLATE_CHECKSUM
if (ret == 0) { if (ret >= 0) {
uint16_t deflate_s1 = 1; uint16_t deflate_s1 = 1;
uint16_t deflate_s2 = 0; uint16_t deflate_s2 = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment