Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;zLib字节数组压缩_C++_Zlib - Fatal编程技术网

C++ C++;zLib字节数组压缩

C++ C++;zLib字节数组压缩,c++,zlib,C++,Zlib,在解决了第一个问题后,我又遇到了另一个问题 void CGGCBotDlg::OnBnClickedButtonCompress() { // TODO: Add your 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

在解决了第一个问题后,我又遇到了另一个问题

void CGGCBotDlg::OnBnClickedButtonCompress()
{
// TODO: Add your 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;

    for (int i = 0 ; i <= 10240 ; i++)
    {
        if (YourByte[i] == PKT_END && YourByte[i+1] == PKT_END && YourByte[i+2] == PKT_END)
            {
                Len = i - 1;
                break;
            }
    }

uLong Length = (uLong)(sizeof(YourByte) * 1.0001) + 12;

zReturnCode = compress2(Compressed, &Length, (const Bytef*)YourByte, Len,CompressionLevel);

return zReturnCode;

 }
void CGGCBotDlg::OnBnClickedButtonCompress()
{
//TODO:在此处添加控件通知处理程序代码
z_const char hello[256];
您好[0]=0x0A;
您好[1]=0x0A;
您好[2]=0x0A;
您好[3]=0x0A;
您好[4]=0x0A;
您好[5]=PKT_END;
您好[6]=PKT_END;
您好[7]=PKT_END;
字节压缩[256];
uLong complen=尺寸of(compr);
返回码;
ReturnCode=Compress(压缩、压缩、hello、Z_默认压缩);
g_CS.发送(和压缩、压缩);
}
int CGGCBotDlg::Compress(字节压缩[],uLong CompressedLength,CHAR YourByte[],int压缩级别)
{
int-zReturnCode;
内伦;
对于(int i=0;i这条线是错误的:

Len = i - 1;
因为当i为5时,您需要Len=i-1;因此Len将为4,但您需要压缩5个字节。只需使用:

Len = i;
另一个问题CompressLen从未被赋值。在Compress(Byte Compressed[],uLong CompressedLength..)中,未使用itCompressedLength。我假设您想要回它的值。您应该这样定义:

Compress(Byte Compressed[], uLong& CompressedLength..)
并将行更改为使用CompressedLength,而不是使用length:

zReturnCode = compress2(Compressed, &CompressedLength, (const Bytef*)YourByte, Len,CompressionLevel);

好的,现在前6个字节与预期结果相同,但接下来的6个字节对您的工作来说是其他的,在编辑完所有您说的内容后,这是我在压缩“78 9C E3 E2 02 00 00 9B 00 33”后得到的结果。这是11个字节,但它应该是12个,直到02它很好,但剩余的(00 00 9B 00 33)我不太确定剩下的问题,但是你可以尝试使用Len=i+1;