From 79e086bae5509753eff4dce5669b3a7f5eac525f Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 11 Dec 2024 17:00:42 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0get=5Fdata?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/of_util.h | 1 + src/of_util.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/of_util.h b/include/of_util.h index 3a80369..8d97fa5 100644 --- a/include/of_util.h +++ b/include/of_util.h @@ -39,6 +39,7 @@ public: public: void push(const char* data, int len); int index_of(const char* data, int len, int start_pos = 0); + const char* get_data() const; void remove_of(int start_pos, int len); void clear(); private: diff --git a/src/of_util.cpp b/src/of_util.cpp index 55a5def..843afcc 100644 --- a/src/of_util.cpp +++ b/src/of_util.cpp @@ -12,7 +12,6 @@ int CMutBuffer::index_of(const char* data, int len, int start_pos) if (start_pos < 0 || start_pos >= static_cast(buffer_.size()) || len <= 0) { return -1; } - auto it = std::search(buffer_.begin() + start_pos, buffer_.end(), data, data + len); if (it != buffer_.end()) { return std::distance(buffer_.begin(), it); @@ -25,10 +24,15 @@ void CMutBuffer::remove_of(int start_pos, int len) if (start_pos < 0 || start_pos >= static_cast(buffer_.size()) || len <= 0) { return; } - auto end_pos = std::min(start_pos + len, static_cast(buffer_.size())); buffer_.erase(buffer_.begin() + start_pos, buffer_.begin() + end_pos); } + +const char* CMutBuffer::get_data() const +{ + return buffer_.data(); +} + void CMutBuffer::clear() { std::lock_guard lock(mutex_);