diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b726d1..0bce2f10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ HTTP * Check invariants in parse_op: * Clean up message docs +Core + +* Meet DynamicBuffer requirements for static_streambuf + Extras * unit_test::suite fixes: diff --git a/include/beast/core/impl/static_streambuf.ipp b/include/beast/core/impl/static_streambuf.ipp index ab487fab..3f19cd7e 100644 --- a/include/beast/core/impl/static_streambuf.ipp +++ b/include/beast/core/impl/static_streambuf.ipp @@ -279,6 +279,16 @@ static_streambuf::mutable_buffers_type::end() const -> //------------------------------------------------------------------------------ + +inline +auto +static_streambuf::data() const -> + const_buffers_type +{ + return const_buffers_type{in_, + static_cast(out_ - in_)}; +} + inline auto static_streambuf::prepare(std::size_t n) -> @@ -290,15 +300,6 @@ static_streambuf::prepare(std::size_t n) -> return mutable_buffers_type{out_, n}; } -inline -auto -static_streambuf::data() const -> - const_buffers_type -{ - return const_buffers_type{in_, - static_cast(out_ - in_)}; -} - } // beast #endif diff --git a/include/beast/core/static_streambuf.hpp b/include/beast/core/static_streambuf.hpp index eb1f6c9c..2323b3ba 100644 --- a/include/beast/core/static_streambuf.hpp +++ b/include/beast/core/static_streambuf.hpp @@ -32,6 +32,7 @@ private: #else protected: #endif + std::uint8_t* begin_; std::uint8_t* in_; std::uint8_t* out_; std::uint8_t* last_; @@ -57,21 +58,35 @@ public: #endif - /// Returns the largest size output sequence possible. - std::size_t - max_size() const - { - return end_ - in_; - } - - /// Get the size of the input sequence. + /// Return the size of the input sequence. std::size_t size() const { return out_ - in_; } - /** Get a list of buffers that represents the output sequence, with the given size. + /// Return the maximum sum of the input and output sequence sizes. + std::size_t + max_size() const + { + return end_ - begin_; + } + + /// Return the maximum sum of input and output sizes that can be held without an allocation. + std::size_t + capacity() const + { + return end_ - in_; + } + + /** Get a list of buffers that represent the input sequence. + + @note These buffers remain valid across subsequent calls to `prepare`. + */ + const_buffers_type + data() const; + + /** Get a list of buffers that represent the output sequence, with the given size. @throws std::length_error if the size would exceed the limit imposed by the underlying mutable buffer sequence. @@ -93,13 +108,6 @@ public: out_ += std::min(n, last_ - out_); } - /** Get a list of buffers that represents the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const; - /// Remove bytes from the input sequence. void consume(std::size_t n) @@ -120,6 +128,7 @@ protected: void reset(std::uint8_t* p, std::size_t n) { + begin_ = p; in_ = p; out_ = p; last_ = p;