|
sparrow-ipc 0.2.0
|
An output stream that writes data into separate memory chunks. More...
#include <chunk_memory_output_stream.hpp>
Public Member Functions | |
| chunked_memory_output_stream (R &chunks) | |
| Constructs a chunked memory output stream with a reference to a chunk container. | |
| chunked_memory_output_stream< R > & | write (const char *s, std::streamsize count) |
| Writes character data as a new chunk. | |
| chunked_memory_output_stream< R > & | write (std::span< const std::uint8_t > span) |
| Writes a span of bytes as a new chunk. | |
| chunked_memory_output_stream< R > & | write (std::vector< uint8_t > &&buffer) |
| Writes a buffer by moving it into the chunk container. | |
| chunked_memory_output_stream< R > & | write (uint8_t value, std::size_t count) |
| Writes a byte value repeated a specified number of times as a new chunk. | |
| chunked_memory_output_stream< R > & | put (char value) |
| Writes a single character as a new chunk. | |
| void | reserve (std::size_t size) |
| Reserves capacity in the chunk container. | |
| void | reserve (const std::function< std::size_t()> &calculate_reserve_size) |
| Reserves capacity using a lazy calculation function. | |
| size_t | size () const |
| Gets the total size of all chunks. | |
An output stream that writes data into separate memory chunks.
This template class stores data in discrete memory chunks rather than a single contiguous buffer. Each write operation creates a new chunk, making it suitable for scenarios where data needs to be processed or transmitted in separate units.
| R | A random access range type where each element is itself a random access range of uint8_t. Typically std::vector<std::vector<uint8_t>> or similar nested container types. |
The chunked approach offers several benefits:
Definition at line 32 of file chunk_memory_output_stream.hpp.
|
inlineexplicit |
Constructs a chunked memory output stream with a reference to a chunk container.
| chunks | Reference to the container that will store the memory chunks. The stream stores a pointer to this container for write operations. |
Definition at line 42 of file chunk_memory_output_stream.hpp.
| chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::put | ( | char | value | ) |
Writes a single character as a new chunk.
Creates a new chunk containing a single byte.
| value | The character value to write |
Definition at line 177 of file chunk_memory_output_stream.hpp.
| void sparrow_ipc::chunked_memory_output_stream< R >::reserve | ( | const std::function< std::size_t()> & | calculate_reserve_size | ) |
Reserves capacity using a lazy calculation function.
Reserves space for chunks by calling the provided function to determine the count.
| calculate_reserve_size | Function that returns the number of chunks to reserve |
Definition at line 196 of file chunk_memory_output_stream.hpp.
| void sparrow_ipc::chunked_memory_output_stream< R >::reserve | ( | std::size_t | size | ) |
Reserves capacity in the chunk container.
Reserves space for the specified number of chunks in the container. This does not reserve space within individual chunks.
| size | Number of chunks to reserve space for |
Definition at line 187 of file chunk_memory_output_stream.hpp.
|
nodiscard |
Gets the total size of all chunks.
Calculates and returns the sum of sizes of all chunks in the container.
Definition at line 205 of file chunk_memory_output_stream.hpp.
| chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write | ( | const char * | s, |
| std::streamsize | count ) |
Writes character data as a new chunk.
Creates a new chunk containing the specified character data.
| s | Pointer to the character data to write |
| count | Number of characters to write |
Definition at line 137 of file chunk_memory_output_stream.hpp.
| chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write | ( | std::span< const std::uint8_t > | span | ) |
Writes a span of bytes as a new chunk.
Creates a new chunk containing the data from the provided span.
| span | A span of bytes to write as a new chunk |
Definition at line 147 of file chunk_memory_output_stream.hpp.
| chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write | ( | std::vector< uint8_t > && | buffer | ) |
Writes a buffer by moving it into the chunk container.
This is an optimized write operation that moves an existing buffer into the chunk container, avoiding a copy operation.
| buffer | A vector of bytes to move into the chunk container |
Definition at line 157 of file chunk_memory_output_stream.hpp.
| chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write | ( | uint8_t | value, |
| std::size_t | count ) |
Writes a byte value repeated a specified number of times as a new chunk.
Creates a new chunk filled with the specified byte value.
| value | The byte value to write |
| count | Number of times to repeat the value |
Definition at line 167 of file chunk_memory_output_stream.hpp.