30#include <seastar/core/deleter.hh>
31#include <seastar/util/eclipse.hh>
32#include <seastar/util/std-compat.hh>
33#include <seastar/util/modules.hh>
66template <
typename CharType>
68 static_assert(
sizeof(CharType) == 1,
"must buffer stream of bytes");
78 : _buffer(static_cast<CharType*>(malloc(
size * sizeof(CharType)))), _size(
size)
79 , _deleter(make_free_deleter(_buffer)) {
80 if (
size && !_buffer) {
81 throw std::bad_alloc();
104 : _buffer(buf), _size(
size), _deleter(std::move(d)) {}
110 std::copy_n(src,
size, _buffer);
118 _deleter = std::move(x._deleter);
125 const CharType*
get() const noexcept {
return _buffer; }
130 size_t size() const noexcept {
return _size; }
132 const CharType*
begin() const noexcept {
return _buffer; }
134 const CharType*
end() const noexcept {
return _buffer + _size; }
141 auto ret = std::move(*
this);
154 explicit operator bool() const noexcept {
return size(); }
180 return {_buffer, _size};
194 void trim(
size_t pos)
noexcept {
204 return std::move(_deleter);
214 auto ret = ::posix_memalign(&ptr, alignment,
size *
sizeof(CharType));
215 auto buf =
static_cast<CharType*
>(ptr);
217 throw std::bad_alloc();
223 void* ptr = ::malloc(view.size());
225 throw std::bad_alloc();
227 auto buf =
static_cast<CharType*
>(ptr);
228 memcpy(buf, view.data(), view.size());
237 return size() == o.size() && std::equal(
begin(),
end(), o.begin());
245 return !(*
this == o);
Definition: deleter.hh:52
Definition: temporary_buffer.hh:67
temporary_buffer(CharType *buf, size_t size, deleter d) noexcept
Definition: temporary_buffer.hh:103
temporary_buffer clone() const
Definition: temporary_buffer.hh:179
temporary_buffer(temporary_buffer &&x) noexcept
Moves a temporary_buffer.
Definition: temporary_buffer.hh:92
void trim(size_t pos) noexcept
Definition: temporary_buffer.hh:194
deleter release() noexcept
Definition: temporary_buffer.hh:203
const CharType * begin() const noexcept
Gets a pointer to the beginning of the buffer.
Definition: temporary_buffer.hh:132
bool empty() const noexcept
Checks whether the buffer is empty.
Definition: temporary_buffer.hh:152
const CharType * end() const noexcept
Gets a pointer to the end of the buffer.
Definition: temporary_buffer.hh:134
bool operator==(const temporary_buffer &o) const noexcept
Definition: temporary_buffer.hh:236
temporary_buffer share(size_t pos, size_t len)
Definition: temporary_buffer.hh:170
temporary_buffer & operator=(temporary_buffer &&x) noexcept
Moves a temporary_buffer.
Definition: temporary_buffer.hh:114
temporary_buffer share()
Definition: temporary_buffer.hh:160
temporary_buffer() noexcept
Creates an empty temporary_buffer that does not point at anything.
Definition: temporary_buffer.hh:86
temporary_buffer(size_t size)
Definition: temporary_buffer.hh:77
void trim_front(size_t pos) noexcept
Definition: temporary_buffer.hh:186
size_t size() const noexcept
Gets the buffer size.
Definition: temporary_buffer.hh:130
const CharType * get() const noexcept
Gets a pointer to the beginning of the buffer.
Definition: temporary_buffer.hh:125
CharType * get_write() noexcept
Definition: temporary_buffer.hh:128
CharType operator[](size_t pos) const noexcept
Definition: temporary_buffer.hh:148
static temporary_buffer aligned(size_t alignment, size_t size)
Definition: temporary_buffer.hh:212
temporary_buffer(const CharType *src, size_t size)
Definition: temporary_buffer.hh:109
bool operator!=(const temporary_buffer &o) const noexcept
Definition: temporary_buffer.hh:244
temporary_buffer prefix(size_t size) &&noexcept
Definition: temporary_buffer.hh:140
deleter share()
Definition: deleter.hh:205
Seastar API namespace.
Definition: abort_on_ebadf.hh:26