Skip to content

Commit

Permalink
bytes: add iobuf::from(std::string_view)
Browse files Browse the repository at this point in the history
It's common (especially in tests) to want to get an iobuf from a string.
Adds a convenience method for this.
  • Loading branch information
andrwng committed Jun 27, 2024
1 parent 5e13e1b commit 06ceb0d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/v/bytes/include/bytes/iobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class iobuf {
using byte_iterator = details::io_byte_iterator;
using placeholder = details::io_placeholder;

static iobuf from(std::string_view view) {
iobuf i;
i.append(view.data(), view.size());
return i;
}

// NOLINTNEXTLINE
iobuf() noexcept {
// nothing allocates memory, but boost intrusive list is not marked as
Expand Down

0 comments on commit 06ceb0d

Please sign in to comment.