|
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 | + |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +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. |
| 16 | + |
| 17 | +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). There are efficient (move) operations for creating a `const_shared_buffer` from a `mutable_shared_buffer`, which allows the use case of creating a message and serializing its contents, then sending it out over the network. |
| 18 | + |
| 19 | +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). |
| 20 | + |
| 21 | +## Generated Documentation |
| 22 | + |
| 23 | +The generated Doxygen documentation for `shared_buffer` is [here](https://connectivecpp.github.io/shared-buffer/). |
| 24 | + |
| 25 | +## Dependencies |
| 26 | + |
| 27 | +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. |
| 28 | + |
| 29 | +## C++ Standard |
| 30 | + |
| 31 | +`shared_buffer` uses C++ 20 features, including the "spaceship" operator (`<=>`), `std::span`, and `concepts` / `requires`. |
| 32 | + |
| 33 | +## Supported Compilers |
| 34 | + |
| 35 | +Continuous integration workflows build and unit test on g++ (through Ubuntu), MSVC (through Windows), and clang (through macOS). |
| 36 | + |
| 37 | +## Unit Test Dependencies |
| 38 | + |
| 39 | +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. |
| 40 | + |
| 41 | +The unit test uses utilities from Connective C++'s [utility-rack](https://github.com/connectivecpp/utility-rack). |
| 42 | + |
| 43 | +Specific version (or branch) specs for the dependenies are in `test/CMakeLists.txt`. |
| 44 | + |
| 45 | +## Build and Run Unit Tests |
| 46 | + |
| 47 | +To build and run the unit test program: |
| 48 | + |
| 49 | +First clone the `shared-buffer` repository, then create a build directory in parallel to the `shared-buffer` directory (this is called "out of source" builds, which is recommended), then `cd` (change directory) into the build directory. The CMake commands: |
| 50 | + |
| 51 | +``` |
| 52 | +cmake -D SHARED_BUFFER_BUILD_TESTS:BOOL=ON ../shared-buffer |
| 53 | +
|
| 54 | +cmake --build . |
| 55 | +
|
| 56 | +ctest |
| 57 | +``` |
| 58 | + |
| 59 | +For additional test output, run the unit test individually, for example: |
| 60 | + |
| 61 | +``` |
| 62 | +test/shared_buffer_test -s |
| 63 | +``` |
| 64 | + |
| 65 | +The example can be built by adding `-D SHARED_BUFFER_BUILD_EXAMPLES:BOOL=ON` to the CMake configure / generate step. |
| 66 | + |
0 commit comments