diff options
author | crupest <crupest@outlook.com> | 2024-05-12 00:19:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-05-12 00:19:16 +0800 |
commit | d861d799d2f614a6b58a8f0c0bc6a8911ad0dcfd (patch) | |
tree | adfe4096c07d7bf039b52d3d21d8ef742c8da837 /include/cru/common/Buffer.h | |
parent | dd62b63e1c577abe53d0f9cabe8e9a635c4c8fcf (diff) | |
download | cru-d861d799d2f614a6b58a8f0c0bc6a8911ad0dcfd.tar.gz cru-d861d799d2f614a6b58a8f0c0bc6a8911ad0dcfd.tar.bz2 cru-d861d799d2f614a6b58a8f0c0bc6a8911ad0dcfd.zip |
WORKING: fix Buffer and implement BufferStream::Read.
Diffstat (limited to 'include/cru/common/Buffer.h')
-rw-r--r-- | include/cru/common/Buffer.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/include/cru/common/Buffer.h b/include/cru/common/Buffer.h index 8574cd86..69c47aff 100644 --- a/include/cru/common/Buffer.h +++ b/include/cru/common/Buffer.h @@ -17,7 +17,7 @@ class Buffer final { ~Buffer(); - private: + public: Index GetBufferSize() const { return size_; } Index GetUsedSize() const { return used_end_ - used_begin_; } bool IsNull() const { return ptr_ == nullptr; } @@ -71,7 +71,8 @@ class Buffer final { * written and the size of it will be returned, leaving exceeded data not * saved. */ - Index PushFront(std::byte* other, Index other_size, bool use_memmove = false); + Index PushFront(const std::byte* other, Index other_size, + bool use_memmove = false); /** * @brief Append data to the back of used bytes and increase used size. @@ -81,7 +82,8 @@ class Buffer final { * written and the size of it will be returned, leaving exceeded data not * saved. */ - Index PushBack(std::byte* other, Index other_size, bool use_memmove = false); + Index PushBack(const std::byte* other, Index other_size, + bool use_memmove = false); /** * @brief Move forward the used-begin ptr. @@ -93,6 +95,16 @@ class Buffer final { Index PopFront(Index size); /** + * @brief Pop front data of used bytes into another buffer. + * @return The actual size popped. + * + * If given size is bigger than current used size, then only current used size + * of bytes will be popped. If given size is smaller than current used size, + * then only given size of bytes will be popped. + */ + Index PopFront(std::byte* buffer, Index size, bool use_memmove = false); + + /** * @brief Move backward the used-end ptr. * @return The actual size moved backward. * @@ -101,6 +113,16 @@ class Buffer final { */ Index PopEnd(Index size); + /** + * @brief Pop back data of used bytes into another buffer. + * @return The actual size popped. + * + * If given size is bigger than current used size, then only current used size + * of bytes will be popped. If given size is smaller than current used size, + * then only given size of bytes will be popped. + */ + Index PopEnd(std::byte* buffer, Index size, bool use_memmove = false); + operator std::byte*() { return GetPtr(); } operator const std::byte*() const { return GetPtr(); } |