diff options
author | dvorkanton <dvorkanton@yandex-team.ru> | 2022-02-10 16:46:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:04 +0300 |
commit | ce1ca0f8ad5b8231d32b35629f85bb09beea1bfb (patch) | |
tree | 19b21fdcf9ef01e0c94a15434fb08a4a555a79e9 /library/cpp/blockcodecs/codecs/lzma | |
parent | fc361854fd6ee8d747229b090f0b8018e260d1fb (diff) | |
download | ydb-ce1ca0f8ad5b8231d32b35629f85bb09beea1bfb.tar.gz |
Restoring authorship annotation for <dvorkanton@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/blockcodecs/codecs/lzma')
-rw-r--r-- | library/cpp/blockcodecs/codecs/lzma/lzma.cpp | 136 | ||||
-rw-r--r-- | library/cpp/blockcodecs/codecs/lzma/ya.make | 26 |
2 files changed, 81 insertions, 81 deletions
diff --git a/library/cpp/blockcodecs/codecs/lzma/lzma.cpp b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp index 6c8d5fded4..eb52842aee 100644 --- a/library/cpp/blockcodecs/codecs/lzma/lzma.cpp +++ b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp @@ -1,74 +1,74 @@ #include <library/cpp/blockcodecs/core/codecs.h> #include <library/cpp/blockcodecs/core/common.h> #include <library/cpp/blockcodecs/core/register.h> - -#include <contrib/libs/lzmasdk/LzmaLib.h> - -using namespace NBlockCodecs; - -namespace { - struct TLzmaCodec: public TAddLengthCodec<TLzmaCodec> { - inline TLzmaCodec(int level) - : Level(level) - , MyName("lzma-" + ToString(Level)) - { - } - - static inline size_t DoMaxCompressedLength(size_t in) noexcept { - return Max<size_t>(in + in / 20, 128) + LZMA_PROPS_SIZE; - } - - TStringBuf Name() const noexcept override { - return MyName; - } - - inline size_t DoCompress(const TData& in, void* buf) const { - unsigned char* props = (unsigned char*)buf; - unsigned char* data = props + LZMA_PROPS_SIZE; - size_t destLen = Max<size_t>(); - size_t outPropsSize = LZMA_PROPS_SIZE; - - const int ret = LzmaCompress(data, &destLen, (const unsigned char*)in.data(), in.size(), props, &outPropsSize, Level, 0, -1, -1, -1, -1, -1); - - if (ret != SZ_OK) { - ythrow TCompressError(ret); - } - - return destLen + LZMA_PROPS_SIZE; - } - - inline void DoDecompress(const TData& in, void* out, size_t len) const { - if (in.size() <= LZMA_PROPS_SIZE) { + +#include <contrib/libs/lzmasdk/LzmaLib.h> + +using namespace NBlockCodecs; + +namespace { + struct TLzmaCodec: public TAddLengthCodec<TLzmaCodec> { + inline TLzmaCodec(int level) + : Level(level) + , MyName("lzma-" + ToString(Level)) + { + } + + static inline size_t DoMaxCompressedLength(size_t in) noexcept { + return Max<size_t>(in + in / 20, 128) + LZMA_PROPS_SIZE; + } + + TStringBuf Name() const noexcept override { + return MyName; + } + + inline size_t DoCompress(const TData& in, void* buf) const { + unsigned char* props = (unsigned char*)buf; + unsigned char* data = props + LZMA_PROPS_SIZE; + size_t destLen = Max<size_t>(); + size_t outPropsSize = LZMA_PROPS_SIZE; + + const int ret = LzmaCompress(data, &destLen, (const unsigned char*)in.data(), in.size(), props, &outPropsSize, Level, 0, -1, -1, -1, -1, -1); + + if (ret != SZ_OK) { + ythrow TCompressError(ret); + } + + return destLen + LZMA_PROPS_SIZE; + } + + inline void DoDecompress(const TData& in, void* out, size_t len) const { + if (in.size() <= LZMA_PROPS_SIZE) { ythrow TDataError() << TStringBuf("broken lzma stream"); - } - - const unsigned char* props = (const unsigned char*)in.data(); - const unsigned char* data = props + LZMA_PROPS_SIZE; - size_t destLen = len; - SizeT srcLen = in.size() - LZMA_PROPS_SIZE; - - const int res = LzmaUncompress((unsigned char*)out, &destLen, data, &srcLen, props, LZMA_PROPS_SIZE); - - if (res != SZ_OK) { - ythrow TDecompressError(res); - } - - if (destLen != len) { - ythrow TDecompressError(len, destLen); - } - } - - const int Level; - const TString MyName; - }; - - struct TLzmaRegistrar { - TLzmaRegistrar() { - for (int i = 0; i < 10; ++i) { + } + + const unsigned char* props = (const unsigned char*)in.data(); + const unsigned char* data = props + LZMA_PROPS_SIZE; + size_t destLen = len; + SizeT srcLen = in.size() - LZMA_PROPS_SIZE; + + const int res = LzmaUncompress((unsigned char*)out, &destLen, data, &srcLen, props, LZMA_PROPS_SIZE); + + if (res != SZ_OK) { + ythrow TDecompressError(res); + } + + if (destLen != len) { + ythrow TDecompressError(len, destLen); + } + } + + const int Level; + const TString MyName; + }; + + struct TLzmaRegistrar { + TLzmaRegistrar() { + for (int i = 0; i < 10; ++i) { RegisterCodec(MakeHolder<TLzmaCodec>(i)); - } - RegisterAlias("lzma", "lzma-5"); - } - }; + } + RegisterAlias("lzma", "lzma-5"); + } + }; const TLzmaRegistrar Registrar{}; -} +} diff --git a/library/cpp/blockcodecs/codecs/lzma/ya.make b/library/cpp/blockcodecs/codecs/lzma/ya.make index e145834da6..11f38eca71 100644 --- a/library/cpp/blockcodecs/codecs/lzma/ya.make +++ b/library/cpp/blockcodecs/codecs/lzma/ya.make @@ -1,14 +1,14 @@ -LIBRARY() - -OWNER(pg) - -PEERDIR( - contrib/libs/lzmasdk +LIBRARY() + +OWNER(pg) + +PEERDIR( + contrib/libs/lzmasdk library/cpp/blockcodecs/core -) - -SRCS( - GLOBAL lzma.cpp -) - -END() +) + +SRCS( + GLOBAL lzma.cpp +) + +END() |