Go to the documentation of this file.00001 #include "LzoCompressor.h"
00002
00003 ACE_RCSID (LZO,
00004 LzoCompressor,
00005 "$Id: LzoCompressor.cpp 84757 2009-03-09 07:11:58Z johnnyw $")
00006
00007 #include <lzo1x.h>
00008 #include <lzoutil.h>
00009
00010 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace TAO
00013 {
00014 LzoCompressor::LzoCompressor (
00015 ::Compression::CompressionLevel compression_level,
00016 ::Compression::CompressorFactory_ptr compressor_factory) :
00017 BaseCompressor (compression_level, compressor_factory)
00018 {
00019 }
00020
00021 void
00022 LzoCompressor::compress (
00023 const ::Compression::Buffer & source,
00024 ::Compression::Buffer & target
00025 )
00026 {
00027 void* wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS);
00028 lzo_uint max_length = static_cast <lzo_uint> (source.length () * 1.1) + 12;
00029 target.length (static_cast <CORBA::ULong> (max_length));
00030
00031 int const retval = ::lzo1x_1_compress (
00032 reinterpret_cast <const unsigned char*>(source.get_buffer ()),
00033 source.length (),
00034 reinterpret_cast <unsigned char*>(target.get_buffer ()),
00035 &max_length,
00036 wrkmem);
00037
00038 lzo_free(wrkmem);
00039
00040 if (retval != LZO_E_OK)
00041 {
00042 throw ::Compression::CompressionException (retval, "");
00043 }
00044 else
00045 {
00046 target.length (static_cast <CORBA::ULong> (max_length));
00047 }
00048
00049
00050 this->update_stats (source.length (), target.length ());
00051 }
00052
00053 void
00054 LzoCompressor::decompress (
00055 const ::Compression::Buffer & source,
00056 ::Compression::Buffer & target)
00057 {
00058 lzo_uint max_length = static_cast <lzo_uint> (target.length ());
00059
00060 int const retval = ::lzo1x_decompress (
00061 reinterpret_cast <const unsigned char*>(source.get_buffer ()),
00062 source.length (),
00063 reinterpret_cast <unsigned char*>(target.get_buffer ()),
00064 &max_length,
00065 0);
00066
00067 if (retval != LZO_E_OK)
00068 {
00069 throw ::Compression::CompressionException (retval, "");
00070 }
00071 else
00072 {
00073 target.length (static_cast <CORBA::ULong> (max_length));
00074 }
00075 }
00076 }
00077
00078 TAO_END_VERSIONED_NAMESPACE_DECL