summaryrefslogtreecommitdiffstats
path: root/src/common/buffer_seastar.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/common/buffer_seastar.h
parentInitial commit. (diff)
downloadceph-upstream/18.2.2.tar.xz
ceph-upstream/18.2.2.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/buffer_seastar.h')
-rw-r--r--src/common/buffer_seastar.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/common/buffer_seastar.h b/src/common/buffer_seastar.h
new file mode 100644
index 000000000..70a7b9325
--- /dev/null
+++ b/src/common/buffer_seastar.h
@@ -0,0 +1,62 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include <seastar/core/temporary_buffer.hh>
+#include "include/buffer.h"
+#include "common/error_code.h"
+
+namespace details {
+
+template<bool is_const>
+class buffer_iterator_impl {
+public:
+ using pointer = std::conditional_t<is_const, const char*, char *>;
+ buffer_iterator_impl(pointer first, const char* last)
+ : pos(first), end_ptr(last)
+ {}
+ pointer get_pos_add(size_t n) {
+ auto r = pos;
+ pos += n;
+ if (pos > end_ptr) {
+ throw buffer::end_of_buffer{};
+ }
+ return r;
+ }
+ pointer get() const {
+ return pos;
+ }
+protected:
+ pointer pos;
+ const char* end_ptr;
+};
+} // namespace details
+
+class seastar_buffer_iterator : details::buffer_iterator_impl<false> {
+ using parent = details::buffer_iterator_impl<false>;
+ using temporary_buffer = seastar::temporary_buffer<char>;
+public:
+ seastar_buffer_iterator(temporary_buffer& b)
+ : parent(b.get_write(), b.end()), buf(b)
+ {}
+ using parent::pointer;
+ using parent::get_pos_add;
+ using parent::get;
+ ceph::buffer::ptr get_ptr(size_t len);
+
+private:
+ // keep the reference to buf around, so it can be "shared" by get_ptr()
+ temporary_buffer& buf;
+};
+
+class const_seastar_buffer_iterator : details::buffer_iterator_impl<true> {
+ using parent = details::buffer_iterator_impl<true>;
+ using temporary_buffer = seastar::temporary_buffer<char>;
+public:
+ const_seastar_buffer_iterator(temporary_buffer& b)
+ : parent(b.get_write(), b.end())
+ {}
+ using parent::pointer;
+ using parent::get_pos_add;
+ using parent::get;
+ ceph::buffer::ptr get_ptr(size_t len);
+};