High-performance std::ostream with an embedded resizable string buffer.
More...
#include <fast_stream.h>
|
| | FastStream () noexcept |
| | Constructs a FastStream with a default initial buffer capacity.
|
| | ~FastStream () noexcept override |
| | Destructor. Releases the internal string buffer.
|
| void | reset () noexcept |
| | Clears all buffered content and resets the stream error state.
|
| void | append_to (std::string &target) const noexcept |
| | Appends the current buffered content to an existing std::string.
|
| std::string_view | take_view () noexcept |
| | Returns a std::string_view of the current buffer contents.
|
| size_t | size () const noexcept |
| | Returns the current number of bytes stored in the buffer.
|
| size_t | capacity () const noexcept |
| | Returns the current allocated capacity of the internal buffer in bytes.
|
| void | shrink_to_fit () noexcept |
| | Releases any excess capacity allocated by the internal buffer.
|
| FastStream & | write_raw (const char *data, size_t len) noexcept |
| | Writes raw bytes directly into the buffer, bypassing std::ostream formatting.
|
High-performance std::ostream with an embedded resizable string buffer.
Used internally by Logger to accumulate a single log message and hand it off to the sink as a std::string_view without an extra copy. All std::ostream formatting (hex, precision, fill, etc.) is supported.
◆ FastStream()
| vlink::FastStream::FastStream |
( |
| ) |
|
|
noexcept |
Constructs a FastStream with a default initial buffer capacity.
The default capacity is 256 bytes. The buffer grows automatically when the message length exceeds the current capacity.
◆ ~FastStream()
| vlink::FastStream::~FastStream |
( |
| ) |
|
|
overridenoexcept |
Destructor. Releases the internal string buffer.
◆ append_to()
| void vlink::FastStream::append_to |
( |
std::string & | target | ) |
const |
|
noexcept |
Appends the current buffered content to an existing std::string.
The internal buffer is not reset after this call. Use this method when the content needs to be collected into an external string incrementally.
- Parameters
-
| target | The string to which buffered content is appended. |
◆ capacity()
| size_t vlink::FastStream::capacity |
( |
| ) |
const |
|
nodiscardnoexcept |
Returns the current allocated capacity of the internal buffer in bytes.
- Returns
- Capacity in bytes.
◆ reset()
| void vlink::FastStream::reset |
( |
| ) |
|
|
noexcept |
Clears all buffered content and resets the stream error state.
After reset() the stream is ready to receive a new message. The allocated memory of the underlying buffer is retained (no deallocation).
◆ shrink_to_fit()
| void vlink::FastStream::shrink_to_fit |
( |
| ) |
|
|
noexcept |
Releases any excess capacity allocated by the internal buffer.
Useful after a particularly large log message to reclaim memory back to a sensible minimum (kMinCapacity = 64 bytes).
◆ size()
| size_t vlink::FastStream::size |
( |
| ) |
const |
|
nodiscardnoexcept |
Returns the current number of bytes stored in the buffer.
- Returns
- Number of bytes written since the last
reset().
◆ take_view()
| std::string_view vlink::FastStream::take_view |
( |
| ) |
|
|
noexcept |
Returns a std::string_view of the current buffer contents.
The stream is not reset by this call. The returned view remains valid only until the next write to the stream or an explicit reset(). This is the primary zero-copy hand-off mechanism used by the Logger.
- Warning
- Do not store the returned view beyond the lifetime of the next stream operation. Treating it as a persistent string leads to undefined behaviour.
- Returns
- A
std::string_view over the internal buffer content.
◆ write_raw()
| FastStream & vlink::FastStream::write_raw |
( |
const char * | data, |
|
|
size_t | len ) |
|
noexcept |
Writes raw bytes directly into the buffer, bypassing std::ostream formatting.
This is faster than std::ostream::write for pre-formatted C-strings because it avoids locale and format-flag overhead.
- Parameters
-
| data | Pointer to the bytes to write. Must not be null if len > 0. |
| len | Number of bytes to write. |
- Returns
- A reference to
*this to support chaining.
The documentation for this class was generated from the following file: