|
sparrow-ipc 0.2.0
|
An output stream that writes data to a contiguous memory buffer. More...
#include <memory_output_stream.hpp>
Public Member Functions | |
| memory_output_stream (R &buffer) | |
| Constructs a memory output stream with a reference to a buffer. | |
| memory_output_stream & | write (const char *s, std::streamsize count) |
| Writes character data to the buffer. | |
| memory_output_stream & | write (std::span< const std::uint8_t > span) |
| Writes a span of bytes to the buffer. | |
| memory_output_stream & | write (uint8_t value, std::size_t count) |
| Writes a byte value repeated a specified number of times. | |
| memory_output_stream & | put (char value) |
| Writes a single character to the buffer. | |
| void | reserve (std::size_t size) |
| Reserves capacity in the underlying buffer. | |
| void | reserve (const std::function< std::size_t()> &calculate_reserve_size) |
| Reserves capacity using a lazy calculation function. | |
| size_t | size () const |
| Gets the current size of the buffer. | |
An output stream that writes data to a contiguous memory buffer.
This template class implements an output_stream that appends data to a contiguous random-access range (typically std::vector<uint8_t>). All write operations append data to the end of the buffer, making it grow as needed.
| R | A random access range type with uint8_t as its value type. Typically std::vector<uint8_t> or similar contiguous container types. |
The memory output stream:
Definition at line 29 of file memory_output_stream.hpp.
|
inline |
Constructs a memory output stream with a reference to a buffer.
| buffer | Reference to the container that will store the written data. The stream stores a non-owning pointer to this buffer for write operations. |
Definition at line 41 of file memory_output_stream.hpp.
| memory_output_stream< R > & sparrow_ipc::memory_output_stream< R >::put | ( | char | value | ) |
Writes a single character to the buffer.
Appends a single byte to the end of the buffer. The character is cast to uint8_t.
| value | The character value to write |
Definition at line 148 of file memory_output_stream.hpp.
| void sparrow_ipc::memory_output_stream< R >::reserve | ( | const std::function< std::size_t()> & | calculate_reserve_size | ) |
Reserves capacity using a lazy calculation function.
Calls the provided function to determine the buffer size to reserve.
| calculate_reserve_size | Function that returns the number of bytes to reserve |
Definition at line 163 of file memory_output_stream.hpp.
| void sparrow_ipc::memory_output_stream< R >::reserve | ( | std::size_t | size | ) |
Reserves capacity in the underlying buffer.
Reserves space for at least the specified number of bytes in the buffer. This can help minimize reallocations during subsequent write operations.
| size | Number of bytes to reserve |
Definition at line 156 of file memory_output_stream.hpp.
|
nodiscard |
Gets the current size of the buffer.
Definition at line 170 of file memory_output_stream.hpp.
| memory_output_stream< R > & sparrow_ipc::memory_output_stream< R >::write | ( | const char * | s, |
| std::streamsize | count ) |
Writes character data to the buffer.
Appends the specified character data to the end of the buffer.
| s | Pointer to the character data to write |
| count | Number of characters to write |
Definition at line 124 of file memory_output_stream.hpp.
| memory_output_stream< R > & sparrow_ipc::memory_output_stream< R >::write | ( | std::span< const std::uint8_t > | span | ) |
Writes a span of bytes to the buffer.
Appends the data from the provided span to the end of the buffer.
| span | A span of bytes to write |
Definition at line 132 of file memory_output_stream.hpp.
| memory_output_stream< R > & sparrow_ipc::memory_output_stream< R >::write | ( | uint8_t | value, |
| std::size_t | count ) |
Writes a byte value repeated a specified number of times.
Appends the specified byte value repeated count times to the end of the buffer. This is useful for padding operations or filling with a specific value.
| value | The byte value to write |
| count | Number of times to repeat the value |
Definition at line 140 of file memory_output_stream.hpp.