diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-13 13:46:02 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-13 13:46:02 +0200 |
commit | 024f86caf8031731f24054688a4c783b493eb116 (patch) | |
tree | 5d282cdc35bd43d0129a3d2a72d2812ee371c706 /document | |
parent | 3b6a3b0f4beafa3ea9baec7e17197042d947767d (diff) |
Move to separate compression namespace to avoid pollution.
Diffstat (limited to 'document')
8 files changed, 26 insertions, 12 deletions
diff --git a/document/src/vespa/document/fieldvalue/serializablearray.cpp b/document/src/vespa/document/fieldvalue/serializablearray.cpp index c8beea5e79c..0fb85a2aaf2 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.cpp +++ b/document/src/vespa/document/fieldvalue/serializablearray.cpp @@ -2,14 +2,15 @@ #include "serializablearray.h" #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/util/bytebuffer.h> +#include <vespa/document/util/compressor.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/data/databuffer.h> -#include <vespa/document/util/compressor.h> #include <vespa/log/log.h> LOG_SETUP(".document.serializable-array"); using std::vector; +using vespalib::make_string; namespace document { @@ -179,6 +180,7 @@ SerializableArray::clear(int id) void SerializableArray::deCompress() // throw (DeserializeException) { + using document::compression::decompress; // will only do this once LOG_ASSERT(_compSerData); @@ -201,15 +203,14 @@ SerializableArray::deCompress() // throw (DeserializeException) false); } catch (const std::runtime_error & e) { throw DeserializeException( - vespalib::make_string( "Document was compressed with code unknown code %d", _serializedCompression), + make_string( "Document was compressed with code unknown code %d", _serializedCompression), VESPA_STRLOC); } if (unCompressed.getDataLen() != (size_t)_uncompressedLength) { throw DeserializeException( - vespalib::make_string( - "Did not decompress to the expected length: had %" PRIu64 ", wanted %d, got %" PRIu64, - _compSerData->getRemaining(), _uncompressedLength, unCompressed.getDataLen()), + make_string("Did not decompress to the expected length: had %zu, wanted %d, got %zu", + _compSerData->getRemaining(), _uncompressedLength, unCompressed.getDataLen()), VESPA_STRLOC); } assert(newSerialization->getBuffer() == unCompressed.getData()); diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index 1f6a4a4f0b0..a95dd092f20 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -263,6 +263,7 @@ vespalib::ConstBufferRef compressStream(const CompressionConfig &config, nbostream &stream, vespalib::DataBuffer & compressed_data) { + using compression::compress; vespalib::ConstBufferRef buf(stream.c_str(), stream.size()); if (config.useCompression() && bigEnough(stream.size(), config)) { CompressionConfig::Type compressedType = compress(config, vespalib::ConstBufferRef(stream.c_str(), stream.size()), compressed_data, false); diff --git a/document/src/vespa/document/util/compressor.cpp b/document/src/vespa/document/util/compressor.cpp index c9fac4cf4b0..6ada9bca3db 100644 --- a/document/src/vespa/document/util/compressor.cpp +++ b/document/src/vespa/document/util/compressor.cpp @@ -11,7 +11,7 @@ using vespalib::ConstBufferRef; using vespalib::DataBuffer; using vespalib::make_string; -namespace document { +namespace document::compression { CompressionConfig::Type compress(ICompressor & compressor, const CompressionConfig & compression, const ConstBufferRef & org, DataBuffer & dest) @@ -127,4 +127,15 @@ decompress(const CompressionConfig::Type & type, size_t uncompressedLen, const C } } +size_t computeMaxCompressedsize(CompressionConfig::Type type, size_t payloadSize) { + if (type == CompressionConfig::LZ4) { + document::LZ4Compressor lz4; + return lz4.adjustProcessLen(0, payloadSize); + } else if (type == CompressionConfig::ZSTD) { + document::ZStdCompressor zstd; + return zstd.adjustProcessLen(0, payloadSize); + } + return payloadSize; +} + } diff --git a/document/src/vespa/document/util/compressor.h b/document/src/vespa/document/util/compressor.h index 31e265415b7..11103beb93c 100644 --- a/document/src/vespa/document/util/compressor.h +++ b/document/src/vespa/document/util/compressor.h @@ -15,9 +15,10 @@ public: virtual bool process(const CompressionConfig& config, const void * input, size_t inputLen, void * output, size_t & outputLen) = 0; virtual bool unprocess(const void * input, size_t inputLen, void * output, size_t & outputLen) = 0; virtual size_t adjustProcessLen(uint16_t options, size_t len) const = 0; - virtual size_t adjustUnProcessLen(uint16_t options, size_t len) const = 0; }; +namespace compression { + /** * Will try to compress a buffer according to the config. If the criteria can not * be met it will return NONE and dest will get the input buffer. @@ -42,4 +43,9 @@ CompressionConfig::Type compress(const CompressionConfig & compression, const ve */ void decompress(const CompressionConfig::Type & compression, size_t uncompressedLen, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest, bool allowSwap); + +size_t computeMaxCompressedsize(CompressionConfig::Type type, size_t uncompressedSize); + +} + } diff --git a/document/src/vespa/document/util/lz4compressor.cpp b/document/src/vespa/document/util/lz4compressor.cpp index cb2d41269b0..f7e9a443dcc 100644 --- a/document/src/vespa/document/util/lz4compressor.cpp +++ b/document/src/vespa/document/util/lz4compressor.cpp @@ -8,11 +8,9 @@ using vespalib::alloc::Alloc; - namespace document { size_t LZ4Compressor::adjustProcessLen(uint16_t, size_t len) const { return LZ4_compressBound(len); } -size_t LZ4Compressor::adjustUnProcessLen(uint16_t, size_t len) const { return len; } bool LZ4Compressor::process(const CompressionConfig& config, const void * inputV, size_t inputLen, void * outputV, size_t & outputLenV) diff --git a/document/src/vespa/document/util/lz4compressor.h b/document/src/vespa/document/util/lz4compressor.h index 0c3eee82402..aa1726cd639 100644 --- a/document/src/vespa/document/util/lz4compressor.h +++ b/document/src/vespa/document/util/lz4compressor.h @@ -11,7 +11,6 @@ public: bool process(const CompressionConfig& config, const void * input, size_t inputLen, void * output, size_t & outputLen) override; bool unprocess(const void * input, size_t inputLen, void * output, size_t & outputLen) override; size_t adjustProcessLen(uint16_t options, size_t len) const override; - size_t adjustUnProcessLen(uint16_t options, size_t len) const override; }; } diff --git a/document/src/vespa/document/util/zstdcompressor.cpp b/document/src/vespa/document/util/zstdcompressor.cpp index 78ba15884f5..bb13d8009c1 100644 --- a/document/src/vespa/document/util/zstdcompressor.cpp +++ b/document/src/vespa/document/util/zstdcompressor.cpp @@ -10,7 +10,6 @@ using vespalib::alloc::Alloc; namespace document { size_t ZStdCompressor::adjustProcessLen(uint16_t, size_t len) const { return ZSTD_compressBound(len); } -size_t ZStdCompressor::adjustUnProcessLen(uint16_t, size_t len) const { return len; } bool ZStdCompressor::process(const CompressionConfig& config, const void * inputV, size_t inputLen, void * outputV, size_t & outputLenV) diff --git a/document/src/vespa/document/util/zstdcompressor.h b/document/src/vespa/document/util/zstdcompressor.h index 61b238e0bfb..5c52c144651 100644 --- a/document/src/vespa/document/util/zstdcompressor.h +++ b/document/src/vespa/document/util/zstdcompressor.h @@ -11,7 +11,6 @@ public: bool process(const CompressionConfig& config, const void * input, size_t inputLen, void * output, size_t & outputLen) override; bool unprocess(const void * input, size_t inputLen, void * output, size_t & outputLen) override; size_t adjustProcessLen(uint16_t options, size_t len) const override; - size_t adjustUnProcessLen(uint16_t options, size_t len) const override; }; } |