VLink  2.0.0
A high-performance communication middleware
vlink::FastStream类 参考

Logger-friendly std::ostream with a custom growable string buffer. 更多...

#include <fast_stream.h>

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

Public 成员函数

 FastStream () noexcept
 Constructs the stream with the default initial backing capacity. 更多...
 
 ~FastStream () noexcept override
 Destructor; releases the underlying string buffer. 更多...
 
void reset () noexcept
 Empties the buffer and clears the stream's error state. 更多...
 
void append_to (std::string &target) const noexcept
 Appends the current buffer contents to target without resetting the stream. 更多...
 
std::string_view take_view ()
 Returns a non-owning view of the current buffer contents. 更多...
 
size_t size () const noexcept
 Returns the number of bytes currently held in the buffer. 更多...
 
size_t capacity () const noexcept
 Returns the current allocated capacity of the backing buffer. 更多...
 
void shrink_to_fit () noexcept
 Trims the underlying buffer to its current backing size. 更多...
 
FastStreamwrite_raw (const char *data, size_t len)
 Writes raw bytes into the buffer without going through std::ostream formatting. 更多...
 

详细描述

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.

构造及析构函数说明

◆ FastStream()

vlink::FastStream::FastStream ( )
noexcept

Constructs the stream with the default initial backing capacity.

Initial capacity is kDefaultCapacity (256 bytes); the buffer grows on demand.

◆ ~FastStream()

vlink::FastStream::~FastStream ( )
overridenoexcept

Destructor; releases the underlying string buffer.

成员函数说明

◆ append_to()

void vlink::FastStream::append_to ( std::string &  target) const
noexcept

Appends the current buffer contents to target without resetting the stream.

参数
targetDestination string; contents are appended in place.

◆ capacity()

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

Returns the current allocated capacity of the backing buffer.

返回
Capacity in bytes.

◆ reset()

void vlink::FastStream::reset ( )
noexcept

Empties the buffer and clears the stream's error state.

Retains the allocated capacity so subsequent messages avoid reallocation.

◆ shrink_to_fit()

void vlink::FastStream::shrink_to_fit ( )
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.

◆ size()

size_t vlink::FastStream::size ( ) const
noexcept

Returns the number of bytes currently held in the buffer.

返回
Buffer length in bytes.

◆ take_view()

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.

警告
Do not retain the view beyond the next stream operation; doing so dereferences freed or moved storage.
返回
View covering the current buffer.

◆ write_raw()

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.

参数
dataSource pointer; non-null when len is non-zero.
lenNumber of bytes to write.
返回
Reference to *this for chaining.

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