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_);