|
VLink
2.0.0
A high-performance communication middleware
|
Logger-friendly std::ostream with a custom growable string buffer.
More...
#include <fast_stream.h>
Public Member Functions | |
| FastStream () noexcept | |
| Constructs the stream with the default initial backing capacity. More... | |
| ~FastStream () noexcept override | |
| Destructor; releases the underlying string buffer. More... | |
| void | reset () noexcept |
| Empties the buffer and clears the stream's error state. More... | |
| void | append_to (std::string &target) const noexcept |
Appends the current buffer contents to target without resetting the stream. More... | |
| std::string_view | take_view () |
| Returns a non-owning view of the current buffer contents. More... | |
| size_t | size () const noexcept |
| Returns the number of bytes currently held in the buffer. More... | |
| size_t | capacity () const noexcept |
| Returns the current allocated capacity of the backing buffer. More... | |
| void | shrink_to_fit () noexcept |
| Trims the underlying buffer to its current backing size. More... | |
| FastStream & | write_raw (const char *data, size_t len) |
Writes raw bytes into the buffer without going through std::ostream formatting. More... | |
Logger-friendly std::ostream with a custom growable string buffer.
Routes every write through an embedded StringBuf that owns a std::string. The buffer grows by doubling up to 8 KiB and by linear 8 KiB increments thereafter. take_view yields a non-owning view into the buffer, so a single log line incurs at most one allocation when the buffer must grow and zero allocations on the steady-state path.
|
noexcept |
Constructs the stream with the default initial backing capacity.
Initial capacity is kDefaultCapacity (256 bytes); the buffer grows on demand.
|
overridenoexcept |
Destructor; releases the underlying string buffer.
|
noexcept |
Appends the current buffer contents to target without resetting the stream.
| target | Destination string; contents are appended in place. |
|
noexcept |
Returns the current allocated capacity of the backing buffer.
|
noexcept |
Empties the buffer and clears the stream's error state.
Retains the allocated capacity so subsequent messages avoid reallocation.
|
noexcept |
Trims the underlying buffer to its current backing size.
Does not shrink to the formatted message length; the put pointer is reset to the start.
|
noexcept |
Returns the number of bytes currently held in the buffer.
| std::string_view vlink::FastStream::take_view | ( | ) |
Returns a non-owning view of the current buffer contents.
Primary zero-copy hand-off used by the logger. The view remains valid until the next write to this stream or an explicit reset.
| FastStream& vlink::FastStream::write_raw | ( | const char * | data, |
| size_t | len | ||
| ) |
Writes raw bytes into the buffer without going through std::ostream formatting.
Faster than std::ostream::write for pre-formatted C strings because it skips the locale and format-flag plumbing.
| data | Source pointer; non-null when len is non-zero. |
| len | Number of bytes to write. |
*this for chaining.