diff --git a/CHANGELOG.md b/CHANGELOG.md index ca922c2a..9923dfcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 83: + +* Add flat_static_buffer::mutable_data + +-------------------------------------------------------------------------------- + Version 82: * Documentation tidying diff --git a/include/beast/core/flat_static_buffer.hpp b/include/beast/core/flat_static_buffer.hpp index 4f088196..b15c0e45 100644 --- a/include/beast/core/flat_static_buffer.hpp +++ b/include/beast/core/flat_static_buffer.hpp @@ -51,6 +51,12 @@ public: */ using const_buffers_type = boost::asio::const_buffers_1; + /** The type used to represent the mutable input sequence as a list of buffers. + + This buffer sequence is guaranteed to have length 1. + */ + using mutable_data_type = boost::asio::mutable_buffers_1; + /** The type used to represent the output sequence as a list of buffers. This buffer sequence is guaranteed to have length 1. @@ -98,6 +104,13 @@ public: const_buffers_type data() const; + /** Get a list of mutable buffers that represent the input sequence. + + @note These buffers remain valid across subsequent calls to `prepare`. + */ + mutable_data_type + mutable_data(); + /** 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 diff --git a/include/beast/core/impl/flat_static_buffer.ipp b/include/beast/core/impl/flat_static_buffer.ipp index b605a1c2..7b23e94d 100644 --- a/include/beast/core/impl/flat_static_buffer.ipp +++ b/include/beast/core/impl/flat_static_buffer.ipp @@ -32,6 +32,15 @@ data() const -> return {in_, dist(in_, out_)}; } +inline +auto +flat_static_buffer_base:: +mutable_data() -> + mutable_data_type +{ + return {in_, dist(in_, out_)}; +} + inline auto flat_static_buffer_base:: diff --git a/test/core/flat_static_buffer.cpp b/test/core/flat_static_buffer.cpp index 773cde9e..c259a062 100644 --- a/test/core/flat_static_buffer.cpp +++ b/test/core/flat_static_buffer.cpp @@ -102,6 +102,7 @@ public: ba.commit(buffer_copy(d, buffer(s.data()+x+y, z))); } ba.commit(2); + BEAST_EXPECT(buffer_size(ba.data()) == buffer_size(ba.mutable_data())); BEAST_EXPECT(ba.size() == x + y + z); BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); BEAST_EXPECT(to_string(ba.data()) == s);