C++ zLib Byte array Compressing -


after getting first problem solved @ c++ zlib compress byte array faced problem

void cggcbotdlg::onbnclickedbuttoncompress() { // todo: add control notification handler code here z_const char hello[256]; hello[0] = 0x0a; hello[1] = 0x0a; hello[2] = 0x0a; hello[3] = 0x0a; hello[4] = 0x0a; hello[5] = pkt_end; hello[6] = pkt_end; hello[7] = pkt_end;  byte compr[256]; ulong comprlen = sizeof(compr);  int returncode;  returncode = compress(compr, comprlen, hello, z_default_compression); g_cs.send(&compr,comprlen);  }    int cggcbotdlg::compress(byte compressed[], ulong compressedlength, char yourbyte[], int compressionlevel)  {  int zreturncode; int len;      (int = 0 ; <= 10240 ; i++)     {         if (yourbyte[i] == pkt_end && yourbyte[i+1] == pkt_end && yourbyte[i+2] == pkt_end)             {                 len = - 1;                 break;             }     }  ulong length = (ulong)(sizeof(yourbyte) * 1.0001) + 12;  zreturncode = compress2(compressed, &length, (const bytef*)yourbyte, len,compressionlevel);  return zreturncode;   } 

im trying compress hello[] wich 5 bytes (i want compress first 5 bytes)
expected result after compressing : 0x78,0x9c,0xe3,0xe2,0x02,0x02,0x06,0x00,0x00,0xce,0x00,0x33
after compressing first 4 bytes of expected result , bytes else.

, second problem want replcae 256 in byte compr[256] exact number of bytes after decompressing original buffer (which 12 in case)

great if correct me
thanks

this line wrong:

len = - 1; 

because when 5, len = - 1; len 4, want compress 5 bytes. use:

len = i; 

another problem comprlen never been assigned value. in compress(byte compressed[], ulong compressedlength..), itcompressedlength not used. assume want value back. should define this:

compress(byte compressed[], ulong& compressedlength..) 

and change line use compressedlength instead of using length:

zreturncode = compress2(compressed, &compressedlength, (const bytef*)yourbyte, len,compressionlevel); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -