VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::FastStream类 参考

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

#include <fast_stream.h>

类 vlink::FastStream 继承关系图:
vlink::FastStream 的协作图:

Public 成员函数

 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.

详细描述

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.

参数
targetThe 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.

返回
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.

返回
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.

警告
Do not store the returned view beyond the lifetime of the next stream operation. Treating it as a persistent string leads to undefined behaviour.
返回
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.

参数
dataPointer to the bytes to write. Must not be null if len > 0.
lenNumber of bytes to write.
返回
A reference to *this to support chaining.
函数调用图:
这是这个函数的调用关系图:

该类的文档由以下文件生成: