diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-20 18:43:08 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-01-10 09:56:23 +0100 |
commit | 45c8e269822dd3522f3f01146d38d6afc6b8b07b (patch) | |
tree | 3cfa9636adf862ab0dc1d214e360e652568cef79 /searchlib/src | |
parent | a2433d41489b18bd2f1e785cd9dd15a30e609857 (diff) |
Add missing file.
Diffstat (limited to 'searchlib/src')
-rw-r--r-- | searchlib/src/vespa/searchlib/transactionlog/ichunk.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/transactionlog/ichunk.cpp b/searchlib/src/vespa/searchlib/transactionlog/ichunk.cpp new file mode 100644 index 00000000000..6a296225ed1 --- /dev/null +++ b/searchlib/src/vespa/searchlib/transactionlog/ichunk.cpp @@ -0,0 +1,69 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "chunks.h" +#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/vespalib/util/crc.h> +#include <vespa/vespalib/xxhash/xxhash.h> +#include <cassert> + +using std::runtime_error; +using std::make_unique; +using vespalib::make_string; +using vespalib::nbostream_longlivedbuf; + +namespace search::transactionlog { + +Encoding::Encoding(Crc crc, Compression compression) + : _raw(crc | (compression >> 2)) +{ + assert(crc <= Crc::xxh64); + assert(compression <= Compression::lz4); +} + +IChunk::~IChunk() = default; + +void +IChunk::add(const Packet::Entry & entry) { + _entries.emplace_back(entry); +} + +void +IChunk::encode(nbostream & ) { + +} + +void +IChunk::decode(nbostream & is) { + onDecode(is); +} + +IChunk::UP +IChunk::create(uint8_t chunkType) { + Encoding encoding(chunkType); + if (encoding.getCrc() == Encoding::Crc::xxh64) { + if (encoding.getCompression() == Encoding::Compression::none) { + return make_unique<XXH64None>(); + } else if (encoding.getCompression() == Encoding::Compression::lz4) { + return make_unique<XXH64LZ4>(); + } else { + throw runtime_error(make_string("Unhandled compression type '%d'", encoding.getCompression())); + } + } else { + throw runtime_error(make_string("Unhandled crc type '%d'", encoding.getCrc())); + } +} + +int32_t Encoding::calcCrc(Crc version, const void * buf, size_t sz) +{ + if (version == xxh64) { + return static_cast<int32_t>(XXH64(buf, sz, 0ll)); + } else if (version == ccitt_crc32) { + vespalib::crc_32_type calculator; + calculator.process_bytes(buf, sz); + return calculator.checksum(); + } else { + abort(); + } +} + +} |