aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/mem.h
diff options
context:
space:
mode:
authorAlexander Fokin <apfokin@gmail.com>2022-02-10 16:45:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:38 +0300
commit863a59a65247c24db7cb06789bc5cf79d04da32f (patch)
tree139dc000c8cd4a40f5659e421b7c75135d080307 /util/stream/mem.h
parentf64e95a9eb9ab03240599eb9581c5a9102426a96 (diff)
downloadydb-863a59a65247c24db7cb06789bc5cf79d04da32f.tar.gz
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/stream/mem.h')
-rw-r--r--util/stream/mem.h196
1 files changed, 98 insertions, 98 deletions
diff --git a/util/stream/mem.h b/util/stream/mem.h
index 18a5d46772..faed25c5f8 100644
--- a/util/stream/mem.h
+++ b/util/stream/mem.h
@@ -5,26 +5,26 @@
#include <util/generic/strbuf.h>
-/**
- * @addtogroup Streams_Memory
- * @{
- */
-
-/**
- * Input stream that reads data from a memory block.
- */
+/**
+ * @addtogroup Streams_Memory
+ * @{
+ */
+
+/**
+ * Input stream that reads data from a memory block.
+ */
class TMemoryInput: public IZeroCopyInputFastReadTo {
public:
TMemoryInput() noexcept;
- /**
- * Constructs a stream that reads from the provided memory block. It's up
- * to the user to make sure that the memory block doesn't get freed while
- * this stream is in use.
- *
- * @param buf Memory block to use.
- * @param len Size of the memory block.
- */
+ /**
+ * Constructs a stream that reads from the provided memory block. It's up
+ * to the user to make sure that the memory block doesn't get freed while
+ * this stream is in use.
+ *
+ * @param buf Memory block to use.
+ * @param len Size of the memory block.
+ */
TMemoryInput(const void* buf, size_t len) noexcept;
explicit TMemoryInput(const TStringBuf buf) noexcept;
~TMemoryInput() override;
@@ -48,50 +48,50 @@ public:
TMemoryInput(TMemoryInput&&) noexcept = default;
TMemoryInput& operator=(TMemoryInput&&) noexcept = default;
- /**
- * Initializes this stream with a new memory block. It's up to the
- * user to make sure that the memory block doesn't get freed while this
- * stream is in use.
- *
- * @param buf New memory block to use.
- * @param len Size of the new memory block.
- */
+ /**
+ * Initializes this stream with a new memory block. It's up to the
+ * user to make sure that the memory block doesn't get freed while this
+ * stream is in use.
+ *
+ * @param buf New memory block to use.
+ * @param len Size of the new memory block.
+ */
void Reset(const void* buf, size_t len) noexcept {
Buf_ = (const char*)buf;
Len_ = len;
}
- /**
- * @returns Whether there is more data in the stream.
- */
+ /**
+ * @returns Whether there is more data in the stream.
+ */
bool Exhausted() const noexcept {
return !Avail();
}
- /**
- * @returns Number of bytes available in the stream.
- */
+ /**
+ * @returns Number of bytes available in the stream.
+ */
size_t Avail() const noexcept {
return Len_;
}
- /**
- * @returns Current read position in the memory block
- * used by this stream.
- */
+ /**
+ * @returns Current read position in the memory block
+ * used by this stream.
+ */
const char* Buf() const noexcept {
return Buf_;
}
- /**
- * Initializes this stream with a next chunk extracted from the given zero
- * copy stream.
- *
- * @param stream Zero copy stream to initialize from.
- */
+ /**
+ * Initializes this stream with a next chunk extracted from the given zero
+ * copy stream.
+ *
+ * @param stream Zero copy stream to initialize from.
+ */
void Fill(IZeroCopyInput* stream) {
- Len_ = stream->Next(&Buf_);
- if (!Len_) {
+ Len_ = stream->Next(&Buf_);
+ if (!Len_) {
Reset(nullptr, 0);
}
}
@@ -105,19 +105,19 @@ private:
size_t Len_;
};
-/**
- * Output stream that writes data to a memory block.
- */
+/**
+ * Output stream that writes data to a memory block.
+ */
class TMemoryOutput: public IZeroCopyOutput {
public:
- /**
- * Constructs a stream that writes to the provided memory block. It's up
- * to the user to make sure that the memory block doesn't get freed while
- * this stream is in use.
- *
- * @param buf Memory block to use.
- * @param len Size of the memory block.
- */
+ /**
+ * Constructs a stream that writes to the provided memory block. It's up
+ * to the user to make sure that the memory block doesn't get freed while
+ * this stream is in use.
+ *
+ * @param buf Memory block to use.
+ * @param len Size of the memory block.
+ */
TMemoryOutput(void* buf, size_t len) noexcept
: Buf_(static_cast<char*>(buf))
, End_(Buf_ + len)
@@ -128,47 +128,47 @@ public:
TMemoryOutput(TMemoryOutput&&) noexcept = default;
TMemoryOutput& operator=(TMemoryOutput&&) noexcept = default;
- /**
- * Initializes this stream with a new memory block. It's up to the
- * user to make sure that the memory block doesn't get freed while this
- * stream is in use.
- *
- * @param buf New memory block to use.
- * @param len Size of the new memory block.
- */
+ /**
+ * Initializes this stream with a new memory block. It's up to the
+ * user to make sure that the memory block doesn't get freed while this
+ * stream is in use.
+ *
+ * @param buf New memory block to use.
+ * @param len Size of the new memory block.
+ */
inline void Reset(void* buf, size_t len) noexcept {
Buf_ = static_cast<char*>(buf);
End_ = Buf_ + len;
}
- /**
- * @returns Whether there is more space in the
- * stream for writing.
- */
+ /**
+ * @returns Whether there is more space in the
+ * stream for writing.
+ */
inline bool Exhausted() const noexcept {
return !Avail();
}
- /**
- * @returns Number of bytes available for writing
- * in the stream.
- */
+ /**
+ * @returns Number of bytes available for writing
+ * in the stream.
+ */
inline size_t Avail() const noexcept {
return End_ - Buf_;
}
- /**
- * @returns Current write position in the memory block
- * used by this stream.
- */
+ /**
+ * @returns Current write position in the memory block
+ * used by this stream.
+ */
inline char* Buf() const noexcept {
return Buf_;
}
- /**
- * @returns Pointer to the end of the memory block
- * used by this stream.
- */
+ /**
+ * @returns Pointer to the end of the memory block
+ * used by this stream.
+ */
char* End() const {
return End_;
}
@@ -184,12 +184,12 @@ protected:
char* End_;
};
-/**
- * Memory output stream that supports changing the position of the
- * write pointer.
- *
- * @see TMemoryOutput
- */
+/**
+ * Memory output stream that supports changing the position of the
+ * write pointer.
+ *
+ * @see TMemoryOutput
+ */
class TMemoryWriteBuffer: public TMemoryOutput {
public:
TMemoryWriteBuffer(void* buf, size_t len)
@@ -211,10 +211,10 @@ public:
return Buf() == Beg();
}
- /**
- * @returns Data that has been written into this
- * stream as a string.
- */
+ /**
+ * @returns Data that has been written into this
+ * stream as a string.
+ */
TStringBuf Str() const {
return TStringBuf(Beg(), Buf());
}
@@ -223,21 +223,21 @@ public:
return Beg_;
}
- /**
- * @param ptr New write position for this stream.
- * Must be inside the memory block that
- * this stream uses.
- */
+ /**
+ * @param ptr New write position for this stream.
+ * Must be inside the memory block that
+ * this stream uses.
+ */
void SetPos(char* ptr) {
Y_ASSERT(Beg_ <= ptr);
SetPosImpl(ptr);
}
- /**
- * @param pos New write position for this stream,
- * relative to the beginning of the memory
- * block that this stream uses.
- */
+ /**
+ * @param pos New write position for this stream,
+ * relative to the beginning of the memory
+ * block that this stream uses.
+ */
void SetPos(size_t pos) {
SetPosImpl(Beg_ + pos);
}
@@ -252,4 +252,4 @@ protected:
char* Beg_;
};
-/** @} */
+/** @} */