diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (patch) | |
tree | cb7a9f4a92c0d4cc5a86eeed49ad71e810953c1f /library/cpp/streams/zc_memory_input | |
parent | 83a8efcf3af051e3dd59c00d1d5dafc96412ec1e (diff) | |
download | ydb-00afc96e9c0298054b7386fa7fb9e3cc3d67b974.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/streams/zc_memory_input')
-rw-r--r-- | library/cpp/streams/zc_memory_input/zc_memory_input.h | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/library/cpp/streams/zc_memory_input/zc_memory_input.h b/library/cpp/streams/zc_memory_input/zc_memory_input.h index c939d8e4263..3880959afde 100644 --- a/library/cpp/streams/zc_memory_input/zc_memory_input.h +++ b/library/cpp/streams/zc_memory_input/zc_memory_input.h @@ -1,48 +1,48 @@ -#pragma once - -#include <util/stream/mem.h> -#include <util/system/defaults.h> +#pragma once + +#include <util/stream/mem.h> +#include <util/system/defaults.h> #include <util/generic/yexception.h> - -/// Zero-copy memory input with fixed read + +/// Zero-copy memory input with fixed read class TZCMemoryInput: public TMemoryInput { -public: +public: TZCMemoryInput() { } - TZCMemoryInput(const char* dataPtr, size_t size) - : TMemoryInput(dataPtr, size) + TZCMemoryInput(const char* dataPtr, size_t size) + : TMemoryInput(dataPtr, size) { } - TZCMemoryInput(TMemoryInput& rhs) - : TMemoryInput(rhs.Buf(), rhs.Avail()) + TZCMemoryInput(TMemoryInput& rhs) + : TMemoryInput(rhs.Buf(), rhs.Avail()) { } - /// if there's 'size' data read it, otherwise just return false + /// if there's 'size' data read it, otherwise just return false Y_FORCE_INLINE bool ReadFixed(const char*& buf, size_t size) { - if (Avail() >= size) { - buf = Buf(); - Reset(Buf() + size, Avail() - size); - return true; - } - return false; - } - + if (Avail() >= size) { + buf = Buf(); + Reset(Buf() + size, Avail() - size); + return true; + } + return false; + } + template <class T> Y_FORCE_INLINE T LoadPOD() { const char* buf = nullptr; - if (!ReadFixed(buf, sizeof(T))) + if (!ReadFixed(buf, sizeof(T))) ythrow yexception() << "TZCMemoryInput::LoadPOD failed: not enough data (" - << Avail() << " of " << sizeof(T) << " bytes)"; + << Avail() << " of " << sizeof(T) << " bytes)"; T res; memcpy(&res, buf, sizeof(T)); return res; } - + template <class T> Y_FORCE_INLINE void ReadPOD(T& x) { - x = LoadPOD<T>(); - } -}; + x = LoadPOD<T>(); + } +}; |