diff options
Diffstat (limited to 'src/common/Buffer.cpp')
-rw-r--r-- | src/common/Buffer.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/Buffer.cpp b/src/common/Buffer.cpp index 67e67735..49a0f8ae 100644 --- a/src/common/Buffer.cpp +++ b/src/common/Buffer.cpp @@ -89,6 +89,15 @@ Index Buffer::PushFront(const std::byte* other, Index other_size, return copy_size; } +bool Buffer::PushBack(std::byte b) { + if (IsUsedReachEnd()) { + return false; + } + ptr_[used_end_] = b; + used_end_++; + return true; +} + Index Buffer::PushBack(const std::byte* other, Index other_size, bool use_memmove) { auto copy_size = std::min(size_ - used_end_, other_size); @@ -138,6 +147,16 @@ Index Buffer::PopEnd(std::byte* buffer, Index size, bool use_memmove) { return pop_size; } +std::byte* Buffer::Detach(Index* size) { + auto ptr = this->ptr_; + if (size) { + *size = this->size_; + } + this->ptr_ = nullptr; + this->size_ = this->used_begin_ = this->used_end_ = 0; + return ptr; +} + void Buffer::Copy_(const Buffer& other) { if (other.ptr_ == nullptr) { ptr_ = nullptr; |