diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/blockcodecs/core/codecs.cpp | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/blockcodecs/core/codecs.cpp')
-rw-r--r-- | library/cpp/blockcodecs/core/codecs.cpp | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/library/cpp/blockcodecs/core/codecs.cpp b/library/cpp/blockcodecs/core/codecs.cpp index 4f6b15b550..21506e812b 100644 --- a/library/cpp/blockcodecs/core/codecs.cpp +++ b/library/cpp/blockcodecs/core/codecs.cpp @@ -1,91 +1,91 @@ -#include "codecs.h" +#include "codecs.h" #include "common.h" #include "register.h" - -#include <util/ysaveload.h> + +#include <util/ysaveload.h> #include <util/stream/null.h> -#include <util/stream/mem.h> -#include <util/string/cast.h> -#include <util/string/join.h> -#include <util/system/align.h> -#include <util/system/unaligned_mem.h> -#include <util/generic/hash.h> -#include <util/generic/cast.h> +#include <util/stream/mem.h> +#include <util/string/cast.h> +#include <util/string/join.h> +#include <util/system/align.h> +#include <util/system/unaligned_mem.h> +#include <util/generic/hash.h> +#include <util/generic/cast.h> #include <util/generic/deque.h> -#include <util/generic/buffer.h> +#include <util/generic/buffer.h> #include <util/generic/array_ref.h> -#include <util/generic/singleton.h> -#include <util/generic/algorithm.h> -#include <util/generic/mem_copy.h> - -using namespace NBlockCodecs; - -namespace { - - struct TCodecFactory { - inline TCodecFactory() { - Add(&Null); - } - - inline const ICodec* Find(const TStringBuf& name) const { - auto it = Registry.find(name); - - if (it == Registry.end()) { - ythrow TNotFound() << "can not found " << name << " codec"; - } - - return it->second; - } - - inline void ListCodecs(TCodecList& lst) const { +#include <util/generic/singleton.h> +#include <util/generic/algorithm.h> +#include <util/generic/mem_copy.h> + +using namespace NBlockCodecs; + +namespace { + + struct TCodecFactory { + inline TCodecFactory() { + Add(&Null); + } + + inline const ICodec* Find(const TStringBuf& name) const { + auto it = Registry.find(name); + + if (it == Registry.end()) { + ythrow TNotFound() << "can not found " << name << " codec"; + } + + return it->second; + } + + inline void ListCodecs(TCodecList& lst) const { for (const auto& it : Registry) { lst.push_back(it.first); - } - - Sort(lst.begin(), lst.end()); - } - - inline void Add(ICodec* codec) { - Registry[codec->Name()] = codec; - } - + } + + Sort(lst.begin(), lst.end()); + } + + inline void Add(ICodec* codec) { + Registry[codec->Name()] = codec; + } + inline void Add(TCodecPtr codec) { Codecs.push_back(std::move(codec)); Add(Codecs.back().Get()); } - inline void Alias(TStringBuf from, TStringBuf to) { - Tmp.emplace_back(from); - Registry[Tmp.back()] = Registry[to]; - } - + inline void Alias(TStringBuf from, TStringBuf to) { + Tmp.emplace_back(from); + Registry[Tmp.back()] = Registry[to]; + } + TDeque<TString> Tmp; - TNullCodec Null; + TNullCodec Null; TVector<TCodecPtr> Codecs; typedef THashMap<TStringBuf, ICodec*> TRegistry; - TRegistry Registry; + TRegistry Registry; // SEARCH-8344: Global decompressed size limiter (to prevent remote DoS) size_t MaxPossibleDecompressedLength = Max<size_t>(); - }; -} - -const ICodec* NBlockCodecs::Codec(const TStringBuf& name) { - return Singleton<TCodecFactory>()->Find(name); -} - -TCodecList NBlockCodecs::ListAllCodecs() { - TCodecList ret; - - Singleton<TCodecFactory>()->ListCodecs(ret); - - return ret; -} - + }; +} + +const ICodec* NBlockCodecs::Codec(const TStringBuf& name) { + return Singleton<TCodecFactory>()->Find(name); +} + +TCodecList NBlockCodecs::ListAllCodecs() { + TCodecList ret; + + Singleton<TCodecFactory>()->ListCodecs(ret); + + return ret; +} + TString NBlockCodecs::ListAllCodecsAsString() { return JoinSeq(TStringBuf(","), ListAllCodecs()); -} - +} + void NBlockCodecs::RegisterCodec(TCodecPtr codec) { Singleton<TCodecFactory>()->Add(std::move(codec)); } @@ -113,36 +113,36 @@ size_t ICodec::GetDecompressedLength(const TData& in) const { return len; } -void ICodec::Encode(const TData& in, TBuffer& out) const { - const size_t maxLen = MaxCompressedLength(in); - - out.Reserve(maxLen); - out.Resize(Compress(in, out.Data())); -} - -void ICodec::Decode(const TData& in, TBuffer& out) const { +void ICodec::Encode(const TData& in, TBuffer& out) const { + const size_t maxLen = MaxCompressedLength(in); + + out.Reserve(maxLen); + out.Resize(Compress(in, out.Data())); +} + +void ICodec::Decode(const TData& in, TBuffer& out) const { const size_t len = GetDecompressedLength(in); - - out.Reserve(len); - out.Resize(Decompress(in, out.Data())); -} - + + out.Reserve(len); + out.Resize(Decompress(in, out.Data())); +} + void ICodec::Encode(const TData& in, TString& out) const { - const size_t maxLen = MaxCompressedLength(in); + const size_t maxLen = MaxCompressedLength(in); out.ReserveAndResize(maxLen); - + size_t actualLen = Compress(in, out.begin()); Y_ASSERT(actualLen <= maxLen); out.resize(actualLen); -} - +} + void ICodec::Decode(const TData& in, TString& out) const { const size_t maxLen = GetDecompressedLength(in); out.ReserveAndResize(maxLen); - + size_t actualLen = Decompress(in, out.begin()); Y_ASSERT(actualLen <= maxLen); out.resize(actualLen); -} - +} + ICodec::~ICodec() = default; |