aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/codecs/static/static.cpp
diff options
context:
space:
mode:
authorRuslan Kovalev <ruslan.a.kovalev@gmail.com>2022-02-10 16:46:44 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:44 +0300
commit59e19371de37995fcb36beb16cd6ec030af960bc (patch)
treefa68e36093ebff8b805462e9e6d331fe9d348214 /library/cpp/codecs/static/static.cpp
parent89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff)
downloadydb-59e19371de37995fcb36beb16cd6ec030af960bc.tar.gz
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/codecs/static/static.cpp')
-rw-r--r--library/cpp/codecs/static/static.cpp160
1 files changed, 80 insertions, 80 deletions
diff --git a/library/cpp/codecs/static/static.cpp b/library/cpp/codecs/static/static.cpp
index 44a07dd73a..d2c99a15ee 100644
--- a/library/cpp/codecs/static/static.cpp
+++ b/library/cpp/codecs/static/static.cpp
@@ -1,98 +1,98 @@
-#include "static.h"
-#include "common.h"
-
+#include "static.h"
+#include "common.h"
+
#include <library/cpp/codecs/static/static_codec_info.pb.h>
#include <library/cpp/archive/yarchive.h>
-
-#include <util/draft/datetime.h>
-
-#include <util/string/builder.h>
-#include <util/stream/buffer.h>
-#include <util/stream/mem.h>
-#include <util/string/hex.h>
-#include <util/ysaveload.h>
-
-namespace NCodecs {
+
+#include <util/draft/datetime.h>
+
+#include <util/string/builder.h>
+#include <util/stream/buffer.h>
+#include <util/stream/mem.h>
+#include <util/string/hex.h>
+#include <util/ysaveload.h>
+
+namespace NCodecs {
static constexpr TStringBuf STATIC_CODEC_INFO_MAGIC = "CodecInf";
-
- static TStringBuf GetStaticCodecInfoMagic() {
+
+ static TStringBuf GetStaticCodecInfoMagic() {
return STATIC_CODEC_INFO_MAGIC;
- }
-
+ }
+
void SaveCodecInfoToStream(IOutputStream& out, const TStaticCodecInfo& info) {
- TBufferOutput bout;
+ TBufferOutput bout;
info.SerializeToArcadiaStream(&bout);
- ui64 hash = DataSignature(bout.Buffer());
- out.Write(GetStaticCodecInfoMagic());
- ::Save(&out, hash);
- ::Save(&out, bout.Buffer());
- }
-
+ ui64 hash = DataSignature(bout.Buffer());
+ out.Write(GetStaticCodecInfoMagic());
+ ::Save(&out, hash);
+ ::Save(&out, bout.Buffer());
+ }
+
TStaticCodecInfo LoadCodecInfoFromStream(IInputStream& in) {
- {
- TBuffer magic;
+ {
+ TBuffer magic;
magic.Resize(GetStaticCodecInfoMagic().size());
Y_ENSURE_EX(in.Read(magic.Data(), GetStaticCodecInfoMagic().size()) == GetStaticCodecInfoMagic().size(),
- TCodecException() << "bad codec info");
+ TCodecException() << "bad codec info");
Y_ENSURE_EX(TStringBuf(magic.data(), magic.size()) == GetStaticCodecInfoMagic(),
- TCodecException() << "bad codec info");
- }
-
- ui64 hash;
- ::Load(&in, hash);
- TBuffer info;
- ::Load(&in, info);
- Y_ENSURE_EX(hash == DataSignature(info), TCodecException() << "bad codec info");
-
- TStaticCodecInfo result;
+ TCodecException() << "bad codec info");
+ }
+
+ ui64 hash;
+ ::Load(&in, hash);
+ TBuffer info;
+ ::Load(&in, info);
+ Y_ENSURE_EX(hash == DataSignature(info), TCodecException() << "bad codec info");
+
+ TStaticCodecInfo result;
Y_ENSURE_EX(result.ParseFromArray(info.data(), info.size()), TCodecException() << "bad codec info");
-
- return result;
- }
-
+
+ return result;
+ }
+
TString SaveCodecInfoToString(const TStaticCodecInfo& info) {
- TStringStream s;
- SaveCodecInfoToStream(s, info);
- return s.Str();
- }
-
- TStaticCodecInfo LoadCodecInfoFromString(TStringBuf data) {
+ TStringStream s;
+ SaveCodecInfoToStream(s, info);
+ return s.Str();
+ }
+
+ TStaticCodecInfo LoadCodecInfoFromString(TStringBuf data) {
TMemoryInput m{data.data(), data.size()};
- return LoadCodecInfoFromStream(m);
- }
-
+ return LoadCodecInfoFromStream(m);
+ }
+
TString FormatCodecInfo(const TStaticCodecInfo& ci) {
- TStringBuilder s;
- s << "codec name: " << ci.GetDebugInfo().GetCodecName() << Endl;
- s << "codec hash: " << HexWriteScalar(ci.GetDebugInfo().GetStoredCodecHash()) << Endl;
- s << "dict size: " << ci.GetStoredCodec().Size() << Endl;
- s << "sample mult: " << ci.GetDebugInfo().GetSampleSizeMultiplier() << Endl;
- s << "orig.compress: " << ci.GetDebugInfo().GetCompression() * 100 << " %" << Endl;
- s << "timestamp: " << ci.GetDebugInfo().GetTimestamp() << " ("
+ TStringBuilder s;
+ s << "codec name: " << ci.GetDebugInfo().GetCodecName() << Endl;
+ s << "codec hash: " << HexWriteScalar(ci.GetDebugInfo().GetStoredCodecHash()) << Endl;
+ s << "dict size: " << ci.GetStoredCodec().Size() << Endl;
+ s << "sample mult: " << ci.GetDebugInfo().GetSampleSizeMultiplier() << Endl;
+ s << "orig.compress: " << ci.GetDebugInfo().GetCompression() * 100 << " %" << Endl;
+ s << "timestamp: " << ci.GetDebugInfo().GetTimestamp() << " ("
<< NDatetime::TSimpleTM::NewLocal(ci.GetDebugInfo().GetTimestamp()).ToString()
<< ")" << Endl;
- s << "revision: " << ci.GetDebugInfo().GetRevisionInfo() << Endl;
- s << "training set comment: " << ci.GetDebugInfo().GetTrainingSetComment() << Endl;
- s << "training set resId: " << ci.GetDebugInfo().GetTrainingSetResId() << Endl;
- return s;
- }
-
+ s << "revision: " << ci.GetDebugInfo().GetRevisionInfo() << Endl;
+ s << "training set comment: " << ci.GetDebugInfo().GetTrainingSetComment() << Endl;
+ s << "training set resId: " << ci.GetDebugInfo().GetTrainingSetResId() << Endl;
+ return s;
+ }
+
TString LoadStringFromArchive(const ui8* begin, size_t size) {
- TArchiveReader ar(TBlob::NoCopy(begin, size));
- Y_VERIFY(ar.Count() == 1, "invalid number of entries");
- auto blob = ar.ObjectBlobByKey(ar.KeyByIndex(0));
+ TArchiveReader ar(TBlob::NoCopy(begin, size));
+ Y_VERIFY(ar.Count() == 1, "invalid number of entries");
+ auto blob = ar.ObjectBlobByKey(ar.KeyByIndex(0));
return TString{blob.AsCharPtr(), blob.Size()};
- }
-
- TCodecConstPtr RestoreCodecFromCodecInfo(const TStaticCodecInfo& info) {
- return NCodecs::ICodec::RestoreFromString(info.GetStoredCodec());
- }
-
- TCodecConstPtr RestoreCodecFromArchive(const ui8* begin, size_t size) {
- const auto& data = LoadStringFromArchive(begin, size);
- const auto& info = LoadCodecInfoFromString(data);
- const auto& codec = RestoreCodecFromCodecInfo(info);
- Y_ENSURE_EX(codec, TCodecException() << "null codec");
- return codec;
- }
-}
+ }
+
+ TCodecConstPtr RestoreCodecFromCodecInfo(const TStaticCodecInfo& info) {
+ return NCodecs::ICodec::RestoreFromString(info.GetStoredCodec());
+ }
+
+ TCodecConstPtr RestoreCodecFromArchive(const ui8* begin, size_t size) {
+ const auto& data = LoadStringFromArchive(begin, size);
+ const auto& info = LoadCodecInfoFromString(data);
+ const auto& codec = RestoreCodecFromCodecInfo(info);
+ Y_ENSURE_EX(codec, TCodecException() << "null codec");
+ return codec;
+ }
+}