VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::FastStream Class Reference

High-performance std::ostream with an embedded resizable string buffer. More...

#include <fast_stream.h>

Inheritance diagram for vlink::FastStream:
Collaboration diagram for vlink::FastStream:

Public Member Functions

 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.
FastStreamwrite_raw (const char *data, size_t len) noexcept
 Writes raw bytes directly into the buffer, bypassing std::ostream formatting.

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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.

Here is the caller graph for this function:

◆ ~FastStream()

vlink::FastStream::~FastStream ( )
overridenoexcept

Destructor. Releases the internal string buffer.

Here is the call graph for this function:

Member Function Documentation

◆ 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
targetThe string to which buffered content is appended.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity()

size_t vlink::FastStream::capacity ( ) const
nodiscardnoexcept

Returns the current allocated capacity of the internal buffer in bytes.

Returns
Capacity in bytes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
dataPointer to the bytes to write. Must not be null if len > 0.
lenNumber of bytes to write.
Returns
A reference to *this to support chaining.
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: