2
Copyright (C) 2010 Red Hat, Inc.
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public
15
License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
#include "zlib_decoder.h"
22
static void op_decode(SpiceZlibDecoder *decoder,
28
ZlibDecoder* _decoder = static_cast<ZlibDecoder*>(decoder);
29
_decoder->decode(data, data_size, dest, dest_size);
32
ZlibDecoder::ZlibDecoder()
36
_z_strm.zalloc = Z_NULL;
37
_z_strm.zfree = Z_NULL;
38
_z_strm.opaque = Z_NULL;
39
_z_strm.next_in = Z_NULL;
41
z_ret = inflateInit(&_z_strm);
43
THROW("zlib decoder init failed, error %d", z_ret);
46
static SpiceZlibDecoderOps decoder_ops = {
53
ZlibDecoder::~ZlibDecoder()
59
void ZlibDecoder::decode(uint8_t *data, int data_size, uint8_t *dest, int dest_size)
63
inflateReset(&_z_strm);
64
_z_strm.next_in = data;
65
_z_strm.avail_in = data_size;
66
_z_strm.next_out = dest;
67
_z_strm.avail_out = dest_size;
69
z_ret = inflate(&_z_strm, Z_FINISH);
71
if (z_ret != Z_STREAM_END) {
72
THROW("zlib inflate failed, error %d", z_ret);