diff options
author | karpik <karpik@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
commit | 9cb2cb2fdceae44848ab4504f5e445015b0eca6e (patch) | |
tree | 3a0eb3ce001feaa01c007e7845c304fbafeeca9f /library/cpp/binsaver/buffered_io.h | |
parent | 4413723d359117d4e6287d7ba94ee9b4102fa149 (diff) | |
download | ydb-9cb2cb2fdceae44848ab4504f5e445015b0eca6e.tar.gz |
Restoring authorship annotation for <karpik@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/binsaver/buffered_io.h')
-rw-r--r-- | library/cpp/binsaver/buffered_io.h | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/library/cpp/binsaver/buffered_io.h b/library/cpp/binsaver/buffered_io.h index 75465c9c5ca..58a22e7c780 100644 --- a/library/cpp/binsaver/buffered_io.h +++ b/library/cpp/binsaver/buffered_io.h @@ -1,10 +1,10 @@ -#pragma once +#pragma once #include <util/system/yassert.h> #include <util/generic/utility.h> #include <util/generic/ylimits.h> #include <string.h> - + struct IBinaryStream { virtual ~IBinaryStream() = default; ; @@ -25,7 +25,7 @@ struct IBinaryStream { } } - virtual bool IsValid() const = 0; + virtual bool IsValid() const = 0; virtual bool IsFailed() const = 0; private: @@ -34,15 +34,15 @@ private: i64 LongRead(void* userBuffer, i64 size); i64 LongWrite(const void* userBuffer, i64 size); -}; - +}; + template <int N_SIZE = 16384> class TBufferedStream { - char Buf[N_SIZE]; + char Buf[N_SIZE]; i64 Pos, BufSize; IBinaryStream& Stream; bool bIsReading, bIsEof, bFailed; - + void ReadComplex(void* userBuffer, i64 size) { if (bIsEof) { memset(userBuffer, 0, size); @@ -82,7 +82,7 @@ class TBufferedStream { void operator=(const TBufferedStream&) { } -public: +public: TBufferedStream(bool bRead, IBinaryStream& stream) : Pos(0) , BufSize(0) @@ -92,10 +92,10 @@ public: , bFailed(false) { } - ~TBufferedStream() { - if (!bIsReading) + ~TBufferedStream() { + if (!bIsReading) Flush(); - } + } void Flush() { Y_ASSERT(!bIsReading); if (bIsReading) @@ -109,26 +109,26 @@ public: } inline void Read(void* userBuffer, i64 size) { Y_ASSERT(bIsReading); - if (!bIsEof && size + Pos <= BufSize) { - memcpy(userBuffer, Buf + Pos, size); - Pos += size; - return; - } - ReadComplex(userBuffer, size); - } + if (!bIsEof && size + Pos <= BufSize) { + memcpy(userBuffer, Buf + Pos, size); + Pos += size; + return; + } + ReadComplex(userBuffer, size); + } inline void Write(const void* userBuffer, i64 size) { Y_ASSERT(!bIsReading); - if (Pos + size < N_SIZE) { - memcpy(Buf + Pos, userBuffer, size); - Pos += size; - return; - } - WriteComplex(userBuffer, size); - } + if (Pos + size < N_SIZE) { + memcpy(Buf + Pos, userBuffer, size); + Pos += size; + return; + } + WriteComplex(userBuffer, size); + } bool IsValid() const { return Stream.IsValid(); } bool IsFailed() const { return bFailed; } -}; +}; |