|
1 | | -# shared-buffer |
2 | | -A reference counted character buffer class template |
| 1 | +# Shared Buffer, Header-Only C++ 20 Reference Counted Byte Buffer Classes |
| 2 | + |
| 3 | +#### Unit Test and Documentation Generation Workflow Status |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +The `shared_buffer` classes are reference counted `std::byte` buffer classes useful for asynchronous networking. In particular, the Asio asynchronous networking library requires a buffer to be kept alive and valid until the outstanding IO operation (e.g. a network write) is completed. A straightforward and idiomatic way to achieve this is by using reference counted buffers. |
| 14 | + |
| 15 | +There are two classes - `const_shared_buffer` for outgoing buffers (which should not be modified), and `mutable_shared_buffer` for incoming buffers (mutable and expandable as data arrives). |
| 16 | + |
| 17 | +While internally all data is kept in `std::byte` buffers, convenience methods are provided for converting between traditional buffer types (such as `char *` or `unsigned char*` or similar). |
| 18 | + |
| 19 | +## Generated Documentation |
| 20 | + |
| 21 | +The generated Doxygen documentation for `shared_buffer` is [here](https://connectivecpp.github.io/shared-buffer/). |
| 22 | + |
| 23 | +## Dependencies |
| 24 | + |
| 25 | +The `shared_buffer` header file does not have any third-party dependencies. It uses C++ standard library headers only. The unit test code does have dependencies as noted below. |
| 26 | + |
| 27 | +## C++ Standard |
| 28 | + |
| 29 | +`shared_buffer` uses C++ 20 features, including the "spaceship" operator (`<=>`), `std::span`, and `concepts` / `requires`. |
| 30 | + |
| 31 | +## Supported Compilers |
| 32 | + |
| 33 | +Continuous integration workflows build and unit test on g++ (through Ubuntu), MSVC (through Windows), and clang (through macOS). |
| 34 | + |
| 35 | +## Unit Test Dependencies |
| 36 | + |
| 37 | +The unit test code uses [Catch2](https://github.com/catchorg/Catch2). If the `SHARED_BUFFER_BUILD_TESTS` flag is provided to Cmake (see commands below) the Cmake configure / generate will download the Catch2 library as appropriate using the [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) dependency manager. If Catch2 (v3 or greater) is already installed using a different package manager (such as Conan or vcpkg), the `CPM_USE_LOCAL_PACKAGES` variable can be set which results in `find_package` being attempted. Note that v3 (or later) of Catch2 is required. |
| 38 | + |
| 39 | +Specific version (or branch) specs for the Catch2 dependency is in `test/CMakeLists.txt`. |
| 40 | + |
| 41 | +## Build and Run Unit Tests |
| 42 | + |
| 43 | +To build and run the unit test program: |
| 44 | + |
| 45 | +First clone the `shared-buffer` repository, then create a build directory in parallel to the `shared-queue` directory (this is called "out of source" builds, which is recommended), then `cd` (change directory) into the build directory. The CMake commands: |
| 46 | + |
| 47 | +``` |
| 48 | +cmake -D SHARED_BUFFER_BUILD_TESTS:BOOL=ON ../shared-buffer |
| 49 | +
|
| 50 | +cmake --build . |
| 51 | +
|
| 52 | +ctest |
| 53 | +``` |
| 54 | + |
| 55 | +For additional test output, run the unit test individually, for example: |
| 56 | + |
| 57 | +``` |
| 58 | +test/shared_buffer_test -s |
| 59 | +``` |
| 60 | + |
| 61 | +The example can be built by adding `-D SHARED_BUFFER_BUILD_EXAMPLES:BOOL=ON` to the CMake configure / generate step. |
| 62 | + |
0 commit comments