diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | bd30392c4cc92487950adc375c07adf52da1d592 (patch) | |
tree | e8d1a3f19b7fc890bcef6e4cc5de41f1d88c9ac3 /library/cpp/blockcodecs | |
parent | 5d50718e66d9c037dc587a0211110b7d25a66185 (diff) | |
download | ydb-bd30392c4cc92487950adc375c07adf52da1d592.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/blockcodecs')
-rw-r--r-- | library/cpp/blockcodecs/README.md | 32 | ||||
-rw-r--r-- | library/cpp/blockcodecs/codecs_ut.cpp | 42 | ||||
-rw-r--r-- | library/cpp/blockcodecs/core/codecs.cpp | 46 | ||||
-rw-r--r-- | library/cpp/blockcodecs/core/codecs.h | 22 |
4 files changed, 71 insertions, 71 deletions
diff --git a/library/cpp/blockcodecs/README.md b/library/cpp/blockcodecs/README.md index 417917a475..b8e9bf16dc 100644 --- a/library/cpp/blockcodecs/README.md +++ b/library/cpp/blockcodecs/README.md @@ -1,20 +1,20 @@ -This is a simple library for block data compression (this means data is compressed/uncompressed +This is a simple library for block data compression (this means data is compressed/uncompressed by whole blocks in memory). It's a lite-version of the `library/cpp/codecs`. Lite here means that it -provide only well-known compression algorithms, without the possibility of learning. - -There are two possible ways to work with it. - -Codec by name -============= -Use `NBlockCodec::Codec` to obtain the codec by name. The codec can be asked to compress -or decompress something and in various ways. - -To get a full list of codecs there is a function `NBlockCodecs::ListAllCodecs()`. - -Streaming -========= -Use `stream.h` to obtain simple streams over block codecs (buffer data, compress them by blocks, -write to the resulting stream). +provide only well-known compression algorithms, without the possibility of learning. + +There are two possible ways to work with it. + +Codec by name +============= +Use `NBlockCodec::Codec` to obtain the codec by name. The codec can be asked to compress +or decompress something and in various ways. + +To get a full list of codecs there is a function `NBlockCodecs::ListAllCodecs()`. + +Streaming +========= +Use `stream.h` to obtain simple streams over block codecs (buffer data, compress them by blocks, +write to the resulting stream). Using codec plugins =================== diff --git a/library/cpp/blockcodecs/codecs_ut.cpp b/library/cpp/blockcodecs/codecs_ut.cpp index bfe5a23690..f9e876327b 100644 --- a/library/cpp/blockcodecs/codecs_ut.cpp +++ b/library/cpp/blockcodecs/codecs_ut.cpp @@ -269,27 +269,27 @@ Y_UNIT_TEST_SUITE(TBlockCodecsTest) { Y_UNIT_TEST(TestStreams19) { TestStreams(20, 19); } - - Y_UNIT_TEST(TestMaxPossibleDecompressedSize) { - - UNIT_ASSERT_VALUES_EQUAL(GetMaxPossibleDecompressedLength(), Max<size_t>()); - - TVector<char> input(10001, ' '); - TCodecList codecs = ListAllCodecs(); - SetMaxPossibleDecompressedLength(10000); - - for (const auto& codec : codecs) { - const ICodec* c = Codec(codec); - TBuffer inputBuffer(input.data(), input.size()); - TBuffer output; - TBuffer decompressed; - c->Encode(inputBuffer, output); - UNIT_ASSERT_EXCEPTION(c->Decode(output, decompressed), yexception); - } - - // restore status quo - SetMaxPossibleDecompressedLength(Max<size_t>()); - } + + Y_UNIT_TEST(TestMaxPossibleDecompressedSize) { + + UNIT_ASSERT_VALUES_EQUAL(GetMaxPossibleDecompressedLength(), Max<size_t>()); + + TVector<char> input(10001, ' '); + TCodecList codecs = ListAllCodecs(); + SetMaxPossibleDecompressedLength(10000); + + for (const auto& codec : codecs) { + const ICodec* c = Codec(codec); + TBuffer inputBuffer(input.data(), input.size()); + TBuffer output; + TBuffer decompressed; + c->Encode(inputBuffer, output); + UNIT_ASSERT_EXCEPTION(c->Decode(output, decompressed), yexception); + } + + // restore status quo + SetMaxPossibleDecompressedLength(Max<size_t>()); + } Y_UNIT_TEST(TestListAllCodecs) { static const TString ALL_CODECS = diff --git a/library/cpp/blockcodecs/core/codecs.cpp b/library/cpp/blockcodecs/core/codecs.cpp index 21506e812b..332b671221 100644 --- a/library/cpp/blockcodecs/core/codecs.cpp +++ b/library/cpp/blockcodecs/core/codecs.cpp @@ -64,9 +64,9 @@ namespace { TVector<TCodecPtr> Codecs; typedef THashMap<TStringBuf, ICodec*> TRegistry; TRegistry Registry; - - // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) - size_t MaxPossibleDecompressedLength = Max<size_t>(); + + // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) + size_t MaxPossibleDecompressedLength = Max<size_t>(); }; } @@ -94,25 +94,25 @@ void NBlockCodecs::RegisterAlias(TStringBuf from, TStringBuf to) { Singleton<TCodecFactory>()->Alias(from, to); } -void NBlockCodecs::SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength) { - Singleton<TCodecFactory>()->MaxPossibleDecompressedLength = maxPossibleDecompressedLength; -} - -size_t NBlockCodecs::GetMaxPossibleDecompressedLength() { - return Singleton<TCodecFactory>()->MaxPossibleDecompressedLength; -} - -size_t ICodec::GetDecompressedLength(const TData& in) const { - const size_t len = DecompressedLength(in); - - Y_ENSURE( - len <= NBlockCodecs::GetMaxPossibleDecompressedLength(), - "Attempt to decompress the block that is larger than maximum possible decompressed length, " - "see SEARCH-8344 for details. " - ); - return len; -} - +void NBlockCodecs::SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength) { + Singleton<TCodecFactory>()->MaxPossibleDecompressedLength = maxPossibleDecompressedLength; +} + +size_t NBlockCodecs::GetMaxPossibleDecompressedLength() { + return Singleton<TCodecFactory>()->MaxPossibleDecompressedLength; +} + +size_t ICodec::GetDecompressedLength(const TData& in) const { + const size_t len = DecompressedLength(in); + + Y_ENSURE( + len <= NBlockCodecs::GetMaxPossibleDecompressedLength(), + "Attempt to decompress the block that is larger than maximum possible decompressed length, " + "see SEARCH-8344 for details. " + ); + return len; +} + void ICodec::Encode(const TData& in, TBuffer& out) const { const size_t maxLen = MaxCompressedLength(in); @@ -121,7 +121,7 @@ void ICodec::Encode(const TData& in, TBuffer& out) const { } void ICodec::Decode(const TData& in, TBuffer& out) const { - const size_t len = GetDecompressedLength(in); + const size_t len = GetDecompressedLength(in); out.Reserve(len); out.Resize(Decompress(in, out.Data())); diff --git a/library/cpp/blockcodecs/core/codecs.h b/library/cpp/blockcodecs/core/codecs.h index 9c93c00274..2fede1f029 100644 --- a/library/cpp/blockcodecs/core/codecs.h +++ b/library/cpp/blockcodecs/core/codecs.h @@ -39,7 +39,7 @@ namespace NBlockCodecs { struct ICodec { virtual ~ICodec(); - // main interface + // main interface virtual size_t DecompressedLength(const TData& in) const = 0; virtual size_t MaxCompressedLength(const TData& in) const = 0; virtual size_t Compress(const TData& in, void* out) const = 0; @@ -47,7 +47,7 @@ namespace NBlockCodecs { virtual TStringBuf Name() const noexcept = 0; - // some useful helpers + // some useful helpers void Encode(const TData& in, TBuffer& out) const; void Decode(const TData& in, TBuffer& out) const; @@ -69,22 +69,22 @@ namespace NBlockCodecs { return out; } - private: - size_t GetDecompressedLength(const TData& in) const; + private: + size_t GetDecompressedLength(const TData& in) const; }; using TCodecPtr = THolder<ICodec>; const ICodec* Codec(const TStringBuf& name); - // some aux methods + // some aux methods typedef TVector<TStringBuf> TCodecList; TCodecList ListAllCodecs(); TString ListAllCodecsAsString(); - - // SEARCH-8344: Get the size of max possible decompressed block - size_t GetMaxPossibleDecompressedLength(); - // SEARCH-8344: Globally set the size of max possible decompressed block - void SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength); - + + // SEARCH-8344: Get the size of max possible decompressed block + size_t GetMaxPossibleDecompressedLength(); + // SEARCH-8344: Globally set the size of max possible decompressed block + void SetMaxPossibleDecompressedLength(size_t maxPossibleDecompressedLength); + } |