Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Compression / zlib / ZlibCompressor.cpp
blob8145ac06a61ade665b52d41488d69813b54880c4
1 #include "ZlibCompressor.h"
2 #include "zlib.h"
4 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
6 namespace TAO
8 ZlibCompressor::ZlibCompressor (
9 ::Compression::CompressorFactory_ptr compressor_factory,
10 ::Compression::CompressionLevel compression_level) :
11 BaseCompressor (compressor_factory, compression_level)
15 void
16 ZlibCompressor::compress (
17 const ::Compression::Buffer & source,
18 ::Compression::Buffer & target)
20 // Ensure maximum is at least a bit bigger than input length.
21 target.length(static_cast<CORBA::ULong>((source.length() * 1.001) + 12));
23 uLongf max_length = static_cast <uLongf>(target.maximum());
25 int const retval = ::compress2 (reinterpret_cast <Bytef*>(target.get_buffer ()),
26 &max_length,
27 reinterpret_cast <const Bytef*>(source.get_buffer ()),
28 source.length (),
29 this->compression_level ());
31 if (retval != Z_OK)
33 throw ::Compression::CompressionException (retval, ::zError (retval));
35 else
37 target.length (static_cast <CORBA::ULong> (max_length));
40 // Update statistics for this compressor
41 this->update_stats (source.length (), target.length ());
44 void
45 ZlibCompressor::decompress (
46 const ::Compression::Buffer & source,
47 ::Compression::Buffer & target)
49 uLongf max_length = static_cast <uLongf> (target.maximum ());
50 int const retval = uncompress (reinterpret_cast <Bytef*>(target.get_buffer ()),
51 &max_length,
52 reinterpret_cast <const Bytef*>(source.get_buffer ()),
53 source.length ());
55 if (retval != Z_OK)
57 throw ::Compression::CompressionException (retval, "");
59 else
61 target.length (static_cast <CORBA::ULong> (max_length));
66 TAO_END_VERSIONED_NAMESPACE_DECL