IOBU is an independent C++ library providing generic zero-copy buffer utilities. It is compatible with the vast majority
of STL and 3rd-party buffer-like types, including std::vector<std::byte>, std::string, asio::mutable/const_buffer, std::span<uint8_t>.
No additional conversion operators, no polluting the call site with additional constructors, calls to make_buffer or std::views adaptors:
if you have a buffer-compatible type or a buffer sequence - you deserve to use it directly, no questions asked, and no data copied.
- CMake 3.13 or later
- C++20 compiler
- Any CMake generator (Ninja is recommended)
git clone https://github.com/gubnik/iobu.git
cd iobu
cmake --preset x64-linux
cmake --build build/x64-linux --config DebugAdd a portfile of this library to your ports directory and declare it as a dependency as
{
"name": "iobu"
}Currently, IOBU is not available at vcpkg registry.
include(FetchContent)
FetchContent_Declare(iobu
GIT_REPOSITORY https://github.com/gubnik/iobu.git
GIT_TAG develop
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(iobu)
target_link_libraries(my_app iobu::iobu)In IOBU, a type is treated as buffer-compatible if it exposes a
data() noexcept -> buffer-compatible-data-pointer and a size() noexcept -> convertible-to-std-size_t methods,
specialized by const-qualifiers for read and write buffers accordingly. A buffer-compatible-data-pointer is a pointer
to either std::byte, signed char, unsigned char, char or void. This makes it trivial for any library to be IOBU-compatible,
simply by following the already established STL naming convention.
IOBU also inherits Asio concept of buffer sequences. A buffer sequence is a type which models a bidirectional range the value type of which is buffer-compatible. All IOBU algorithms are designed to operate on buffer sequences, with uniform return types
- if a function returns a
iobu::buffer_view<BufSeqTy>you can expect it to have the exact same API whether the given sequence is a single buffer or a range of buffers.
IOBU buffers are separated into read and write buffers: a read buffer is a buffer that exposes the data in any form, const or not, and write buffers require the data to be non-const - from this it follows that any write buffer can be treated as a read buffer, but no read buffer can be treated as a write buffer.
IOBU operates in terms of non-owning buffer views enabling extremely efficient zero-copy usage patterns. This, however, requires the caller to keep the underlying storage alive and at a stable address for as long as an operation may access it. For asynchronous operations, that usually means keeping the storage alive until completion; using a coroutine-native API such as Boost.Capy can help organize that lifetime, but does not manage it automatically. The caller remains responsible for ownership.