diff options
author | Alexander Fokin <apfokin@gmail.com> | 2022-02-10 16:45:38 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:38 +0300 |
commit | bf9e69a933f89af083d895185f01ed65e4d90766 (patch) | |
tree | b2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /util/stream/aligned.h | |
parent | 863a59a65247c24db7cb06789bc5cf79d04da32f (diff) | |
download | ydb-bf9e69a933f89af083d895185f01ed65e4d90766.tar.gz |
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/stream/aligned.h')
-rw-r--r-- | util/stream/aligned.h | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/util/stream/aligned.h b/util/stream/aligned.h index 04b420c1db..70e7be05a9 100644 --- a/util/stream/aligned.h +++ b/util/stream/aligned.h @@ -1,99 +1,99 @@ #pragma once -#include "input.h" -#include "output.h" - -#include <util/system/yassert.h> -#include <util/generic/bitops.h> - -/** - * @addtogroup Streams - * @{ - */ - -/** - * Proxy input stream that provides additional functions that make reading - * aligned data easier. - */ +#include "input.h" +#include "output.h" + +#include <util/system/yassert.h> +#include <util/generic/bitops.h> + +/** + * @addtogroup Streams + * @{ + */ + +/** + * Proxy input stream that provides additional functions that make reading + * aligned data easier. + */ class TAlignedInput: public IInputStream { public: TAlignedInput(IInputStream* s) - : Stream_(s) - , Position_(0) + : Stream_(s) + , Position_(0) { } - /** - * Ensures alignment of the position in the input stream by skipping - * some input. - * - * @param alignment Alignment. Must be a power of 2. - */ - void Align(size_t alignment = sizeof(void*)) { + /** + * Ensures alignment of the position in the input stream by skipping + * some input. + * + * @param alignment Alignment. Must be a power of 2. + */ + void Align(size_t alignment = sizeof(void*)) { Y_ASSERT(IsPowerOf2(alignment)); - - if (Position_ & (alignment - 1)) { - size_t len = alignment - (Position_ & (alignment - 1)); - - do { - len -= DoSkip(len); - } while (len); - } + + if (Position_ & (alignment - 1)) { + size_t len = alignment - (Position_ & (alignment - 1)); + + do { + len -= DoSkip(len); + } while (len); + } } - -private: + +private: size_t DoRead(void* ptr, size_t len) override; size_t DoSkip(size_t len) override; size_t DoReadTo(TString& st, char ch) override; ui64 DoReadAll(IOutputStream& out) override; - -private: + +private: IInputStream* Stream_; - ui64 Position_; + ui64 Position_; }; -/** - * Proxy output stream that provides additional functions that make writing - * aligned data easier. - */ +/** + * Proxy output stream that provides additional functions that make writing + * aligned data easier. + */ class TAlignedOutput: public IOutputStream { public: TAlignedOutput(IOutputStream* s) - : Stream_(s) - , Position_(0) + : Stream_(s) + , Position_(0) { } TAlignedOutput(TAlignedOutput&&) noexcept = default; TAlignedOutput& operator=(TAlignedOutput&&) noexcept = default; - size_t GetCurrentOffset() const { - return Position_; + size_t GetCurrentOffset() const { + return Position_; } - /** - * Ensures alignment of the position in the output stream by writing - * some data. - * - * @param alignment Alignment. Must be a power of 2. - */ - void Align(size_t alignment = sizeof(void*)) { + /** + * Ensures alignment of the position in the output stream by writing + * some data. + * + * @param alignment Alignment. Must be a power of 2. + */ + void Align(size_t alignment = sizeof(void*)) { Y_ASSERT(IsPowerOf2(alignment)); - + static char unused[sizeof(void*) * 2]; Y_ASSERT(alignment <= sizeof(unused)); - + if (Position_ & (alignment - 1)) { - DoWrite(unused, alignment - (Position_ & (alignment - 1))); + DoWrite(unused, alignment - (Position_ & (alignment - 1))); } } - -private: + +private: void DoWrite(const void* ptr, size_t len) override; - -private: + +private: IOutputStream* Stream_; - ui64 Position_; + ui64 Position_; }; -/** @} */ +/** @} */ |