diff options
author | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
commit | 22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch) | |
tree | bffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/deprecated/datafile/datafile.cpp | |
parent | 332b99e2173f0425444abb759eebcb2fafaa9209 (diff) | |
download | ydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz |
validate canons without yatest_common
Diffstat (limited to 'library/cpp/deprecated/datafile/datafile.cpp')
-rw-r--r-- | library/cpp/deprecated/datafile/datafile.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/deprecated/datafile/datafile.cpp b/library/cpp/deprecated/datafile/datafile.cpp new file mode 100644 index 00000000000..ff93f11c6b7 --- /dev/null +++ b/library/cpp/deprecated/datafile/datafile.cpp @@ -0,0 +1,42 @@ +#include "datafile.h" + +void TDataFileBase::DoLoad(const char* fname, int loadMode) { + Destroy(); + TFile f(fname, RdOnly); + DoLoad(f, loadMode, nullptr, 0); +} + +void TDataFileBase::DoLoad(TFile& f, int loadMode, void* hdrPtr, size_t hdrSize) { + if (hdrPtr) { + if (loadMode & DLM_EXACT_SIZE && f.GetLength() != (i64)Length) + throw yexception() << f.GetName() << " size does not match its header value"; + } else { + Length = f.GetLength(); + hdrSize = 0; + } + if ((loadMode & DLM_LD_TYPE_MASK) == DLM_READ) { + MemData = TVector<char>(Length); + memcpy(MemData.begin(), hdrPtr, hdrSize); + f.Load(MemData.begin() + hdrSize, Length - hdrSize); + Start = MemData.begin(); + } else { + FileData.init(f); + if (FileData.getSize() < Length) + throw yexception() << f.GetName() << " is smaller than what its header value says"; + if ((loadMode & DLM_LD_TYPE_MASK) == DLM_MMAP_PRC) + FileData.precharge(); + Start = (const char*)FileData.getData(); + } +} + +void TDataFileBase::Destroy() { + TVector<char>().swap(MemData); + FileData.term(); + Start = nullptr; + Length = 0; +} + +void TDataFileBase::Precharge() const { + if (Length && Start == (char*)FileData.getData()) + FileData.precharge(); +} |