10#include "read_port.hpp"
11#include "write_port.hpp"
58 [[nodiscard]]
ErrorCode Write(std::string_view chunk);
66 [[nodiscard]]
size_t RetainedSize()
const {
return retained_size_; }
71 size_t retained_size_ = 0;
72 bool saturated_ =
false;
78 using CompiledWriteFun =
ErrorCode (*)(
void* context, CompiledSink& sink);
86 template <
typename CompiledFormat,
typename... Args>
91 std::tuple<Args&&...> args;
102 [[nodiscard]]
static ErrorCode Write(
void* context, CompiledSink& sink)
104 auto& compiled_call = *
static_cast<CompiledCall*
>(context);
108 return Print::Write(sink, compiled_call.format,
109 std::forward<
decltype(unpacked)>(unpacked)...);
130 [[nodiscard]]
static int WriteCompiledToStream(WritePort::Stream& stream,
void* context,
131 CompiledWriteFun write_fun);
147 [[nodiscard]]
static int WriteCompiledSession(
void* context,
148 CompiledWriteFun write_fun);
163 template <
typename Call>
164 [[nodiscard]]
static int RunCompiledSession(Call& call)
166 if (!BeginWriteSession())
171 return WriteCompiledSession(&call, &Call::Write);
185 template <
typename CompiledFormat,
typename... Args>
186 [[nodiscard]]
static int RunCompiled(
const CompiledFormat& format, Args&&... args)
188 CompiledCall<CompiledFormat, Args...> call{
189 format, std::forward_as_tuple(std::forward<Args>(args)...)};
190 return RunCompiledSession(call);
198 [[nodiscard]]
static bool BeginWriteSession();
211 [[nodiscard]]
static int FinishWriteSession(WritePort::Stream& stream,
212 size_t retained_size,
226 template <Print::Text Source,
typename... Args>
230 return RunCompiled(format, std::forward<Args>(args)...);
247 return RunCompiled(format, std::forward<Args>(args)...);
互斥锁类,提供线程同步机制 Mutex class providing thread synchronization mechanisms.
static consteval Compiled< Source > Build()
在编译期解析并校验 printf 格式串 / Parse and validate a printf format at compile time
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
提供静态全局的输入输出接口绑定与写会话管理 / STDIO interface for read and write ports
static int Printf(Args &&... args)
将一个编译期 printf 字面量打印到当前 STDIO 输出 / Print one compile-time printf literal to the active STDIO output
static int Print(Args &&... args)
将一个编译期 brace 字面量打印到当前 STDIO 输出 / Print one compile-time brace literal to the active STDIO output
static LibXR::WritePort::Stream * write_stream_
可选的外部托管写流 / Optional externally owned write stream.
static LibXR::Mutex * write_mutex_
写入端口互斥锁 / Write port mutex.
static ReadPort * read_
读取端口 / Read port instance.
static WritePort * write_
写入端口 / Write port instance.
合并多次写入的流接口 / Stream interface for batched writes.
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
作为 printf 格式源的结构化字符串字面量包装 / Structural literal wrapper used as the NTTP source for printf formats