我正在尝试解码来自服务的原始zlib流。 API文档说我应该维护数据包之间的状态。我正在尝试使用
if(!init_zlib_)
{
infstream_.zalloc = Z_NULL;
infstream_.zfree = Z_NULL;
infstream_.opaque = Z_NULL;
infstream_.avail_in = 0;
infstream_.next_in = Z_NULL;
inflateInit2(&infstream_, -MAX_WBITS);
init_zlib_ = true;
}
do
{
infstream_.avail_in = message_size - ptr;
infstream_.next_in = (Bytef *)(buffer + ptr);
infstream_.avail_out = bufsize;
infstream_.next_out = (Bytef *)outbuffer_;
int status = inflate(&infstream_, Z_SYNC_FLUSH);
switch(status)
{
case Z_OK:
case Z_STREAM_END:
case Z_BUF_ERROR:
break;
default:
fprintf (stderr, "zlib error %d %s\n",
status, infstream_.msg);
}
} while(infstream_.avail_out == 0);
我只能正确收到第一条消息。发布后,我得到zlib error -3 invalid stored block lengths
。我在做什么错了?