Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 1554:89ab71a68fcf
New function OrthancPluginBufferCompression() to (un)compress memory buffers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Aug 2015 11:56:42 +0200 |
parents | 7c4b487b3b4a |
children | 3232f1c995a5 |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Thu Aug 20 10:32:43 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Aug 20 11:56:42 2015 +0200 @@ -41,6 +41,8 @@ #include "../../OrthancServer/OrthancInitialization.h" #include "../../OrthancServer/ServerContext.h" #include "../../OrthancServer/ServerToolbox.h" +#include "../../Core/Compression/ZlibCompressor.h" +#include "../../Core/Compression/GzipCompressor.h" #include <boost/regex.hpp> @@ -854,6 +856,64 @@ } + void OrthancPlugins::BufferCompression(const void* parameters) + { + const _OrthancPluginBufferCompression& p = + *reinterpret_cast<const _OrthancPluginBufferCompression*>(parameters); + + std::string result; + + { + std::auto_ptr<DeflateBaseCompressor> compressor; + + switch (p.compression) + { + case OrthancPluginCompressionType_Zlib: + { + compressor.reset(new ZlibCompressor); + compressor->SetPrefixWithUncompressedSize(false); + break; + } + + case OrthancPluginCompressionType_ZlibWithSize: + { + compressor.reset(new ZlibCompressor); + compressor->SetPrefixWithUncompressedSize(true); + break; + } + + case OrthancPluginCompressionType_Gzip: + { + compressor.reset(new GzipCompressor); + compressor->SetPrefixWithUncompressedSize(false); + break; + } + + case OrthancPluginCompressionType_GzipWithSize: + { + compressor.reset(new GzipCompressor); + compressor->SetPrefixWithUncompressedSize(true); + break; + } + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + if (p.uncompress) + { + compressor->Uncompress(result, p.source, p.size); + } + else + { + compressor->Compress(result, p.source, p.size); + } + } + + CopyToMemoryBuffer(*p.target, result); + } + + bool OrthancPlugins::InvokeService(_OrthancPluginService service, const void* parameters) { @@ -891,6 +951,10 @@ return true; } + case _OrthancPluginService_BufferCompression: + BufferCompression(parameters); + return true; + case _OrthancPluginService_RegisterRestCallback: RegisterRestCallback(parameters); return true;