From 3b66aa76709c7919e28733a38f0caf273f18f313 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Tue, 16 Nov 2021 04:58:50 +0200 Subject: [PATCH] BufferOutputStream: Add reset() method. --- .github/FUNDING.yml | 1 + src/oatpp/core/data/stream/BufferStream.cpp | 7 +++++++ src/oatpp/core/data/stream/BufferStream.hpp | 6 ++++++ 3 files changed, 14 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..2b5fe63a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: oatpp diff --git a/src/oatpp/core/data/stream/BufferStream.cpp b/src/oatpp/core/data/stream/BufferStream.cpp index 026fb967..0dacf395 100644 --- a/src/oatpp/core/data/stream/BufferStream.cpp +++ b/src/oatpp/core/data/stream/BufferStream.cpp @@ -118,6 +118,13 @@ void BufferOutputStream::setCurrentPosition(v_buff_size position) { m_position = position; } +void BufferOutputStream::reset(v_buff_size initialCapacity) { + delete [] m_data; + m_data = new v_char8[initialCapacity]; + m_capacity = initialCapacity; + m_position = 0; +} + oatpp::String BufferOutputStream::toString() { return oatpp::String((const char*) m_data, m_position); } diff --git a/src/oatpp/core/data/stream/BufferStream.hpp b/src/oatpp/core/data/stream/BufferStream.hpp index 4624ae55..42fe6726 100644 --- a/src/oatpp/core/data/stream/BufferStream.hpp +++ b/src/oatpp/core/data/stream/BufferStream.hpp @@ -115,6 +115,12 @@ public: */ void setCurrentPosition(v_buff_size position); + /** + * Reset stream buffer and its capacity. Also reset write position. + * @param initialCapacity + */ + void reset(v_buff_size initialCapacity = 2048); + /** * Copy data to &id:oatpp::String;. * @return