diff options
Diffstat (limited to 'TAO/tao/Compression/zlib/ZlibCompressor.cpp')
-rw-r--r-- | TAO/tao/Compression/zlib/ZlibCompressor.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/TAO/tao/Compression/zlib/ZlibCompressor.cpp b/TAO/tao/Compression/zlib/ZlibCompressor.cpp new file mode 100644 index 00000000000..1f2ba5b5080 --- /dev/null +++ b/TAO/tao/Compression/zlib/ZlibCompressor.cpp @@ -0,0 +1,67 @@ +#include "ZlibCompressor.h" + +ACE_RCSID (ZLIB, + ZlibCompressor, + "$Id$") + +#include "zlib.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +namespace TAO +{ +ZlibCompressor::ZlibCompressor ( + ::Compression::CompressionLevel compression_level, + ::Compression::CompressorFactory_ptr compressor_factory) : + BaseCompressor (compression_level, compressor_factory) +{ +} + +void +ZlibCompressor::compress ( + const ::CORBA::OctetSeq & source, + ::CORBA::OctetSeq & target + ) +{ + ::CORBA::ULong max_length = static_cast <CORBA::ULong> (source.length () * 1.1) + 12; + target.length (max_length); + + int const retval = ::compress2 (reinterpret_cast <Bytef*>(target.get_buffer ()), + reinterpret_cast <uLongf *>(&max_length), + reinterpret_cast <const Bytef*>(source.get_buffer ()), + source.length (), + this->compression_level ()); + + if (retval != Z_OK) + { + throw ::Compression::CompressionException (); + } + else + { + target.length (max_length); + } +} + +void +ZlibCompressor::decompress ( + const ::CORBA::OctetSeq & source, + ::CORBA::OctetSeq & target) +{ + CORBA::ULong max_length = target.length (); + int const retval = uncompress (reinterpret_cast <Bytef*>(target.get_buffer ()), + reinterpret_cast <uLongf *>(&max_length), + reinterpret_cast <const Bytef*>(source.get_buffer ()), + source.length ()); + + if (retval != Z_OK) + { + throw ::Compression::CompressionException (); + } + else + { + target.length (max_length); + } +} +} + +TAO_END_VERSIONED_NAMESPACE_DECL |