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_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;
}
実際には 5 バイトである hello[] を圧縮しようとしています (最初の 5 バイトを圧縮したい)
圧縮後の予想される結果は次のとおりです: 0x33
しかし、圧縮後に得られるのは、期待される結果の最初の 4 バイトだけであり、別のバイトは別のものです。
そして私の2番目の問題は、元のバッファを解凍した後、Byte compr [256]の256を正確なバイト数でreplcaeしたいことです(私の場合は12です)
誰かが私を訂正してくれたら素晴らしいだろう
ありがとう