libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
writer_executor.hpp
1#pragma once
2
6template <OutputSink Sink, FormatProfile Profile>
8{
9 public:
16 Executor(Sink& sink, const uint8_t* codes, const uint8_t* args);
17
22 [[nodiscard]] ErrorCode Run();
23
24 private:
25 // Raw sink and generic field-writing helpers.
26 // 原始输出与通用字段写出辅助函数。
27 [[nodiscard]] ErrorCode WriteRaw(std::string_view text);
28 [[nodiscard]] ErrorCode WritePadding(char fill, size_t count);
29 [[nodiscard]] ErrorCode WriteTextField(std::string_view text, const Spec& spec);
30 [[nodiscard]] ErrorCode WriteIntegerField(char sign_char, std::string_view prefix,
31 std::string_view digits,
32 const Spec& spec);
33 [[nodiscard]] ErrorCode WriteFloatField(char sign_char, std::string_view text,
34 const Spec& spec);
35
36 template <std::signed_integral Int>
37 [[nodiscard]] static char ResolveSignChar(Int value, const Spec& spec);
38
39 template <typename T>
40 [[nodiscard]] static char ResolveFloatSignChar(T value, const Spec& spec);
41
42 template <std::signed_integral Int>
43 [[nodiscard]] ErrorCode WriteSigned(const Spec& spec, Int value);
44
45 template <FormatType Type, std::unsigned_integral UInt>
46 [[nodiscard]] ErrorCode WriteUnsigned(const Spec& spec, UInt value);
47
59 template <uint8_t Base, bool UpperCase = false,
60 bool InlineAlternateOctal = false, std::unsigned_integral UInt>
61 [[nodiscard]] ErrorCode WriteUnsignedDigits(std::string_view prefix, const Spec& spec,
62 UInt value);
63 [[nodiscard]] ErrorCode WritePointer(const Spec& spec, uintptr_t value);
64 [[nodiscard]] ErrorCode WriteCharacter(const Spec& spec, char ch);
65 [[nodiscard]] ErrorCode WriteString(const Spec& spec, std::string_view text);
66
67 template <typename T>
68 [[nodiscard]] ErrorCode WriteFloat(FormatType type, const Spec& spec, T value);
69
73 [[nodiscard]] ErrorCode WriteU32Dec(uint32_t value);
74
78 [[nodiscard]] ErrorCode WriteU32ZeroPadWidth(uint8_t width, uint32_t value);
79
83 [[nodiscard]] ErrorCode WriteStringRaw(std::string_view text);
84
88 [[nodiscard]] ErrorCode WriteF32FixedPrec(uint8_t precision, float value);
89
93 [[nodiscard]] ErrorCode WriteF64FixedPrec(uint8_t precision, double value);
94
95 // Small bridges that keep GenericField dispatch readable while preserving the
96 // existing "read spec -> read next packed argument -> call concrete writer"
97 // execution order.
98 // 这些小桥接函数只负责让 GenericField 分发更易读,同时保持原有的
99 // “读 spec -> 读下一个已打包参数 -> 调具体 writer” 执行顺序不变。
100 template <std::signed_integral Int>
101 [[nodiscard]] ErrorCode DispatchSignedField();
102
103 template <FormatType Type, std::unsigned_integral UInt>
104 [[nodiscard]] ErrorCode DispatchUnsignedField();
105
106 template <FormatType Type, typename Float>
107 [[nodiscard]] ErrorCode DispatchFloatField();
108
109 [[nodiscard]] ErrorCode DispatchPointerField();
110
111 [[nodiscard]] ErrorCode DispatchCharacterField();
112
113 [[nodiscard]] ErrorCode DispatchStringField();
114
120 [[nodiscard]] ErrorCode DispatchGenericField(FormatType type);
121
127 [[nodiscard]] ErrorCode DispatchOp(FormatOp op);
128
129 Sink& sink_;
130 CodeReader codes_;
131 ArgumentReader args_;
132};
133
134#include "writer_executor_field.hpp"
135#include "writer_executor_value.hpp"
136#include "writer_executor_generic.hpp"
137#include "writer_executor_opcode.hpp"
运行期参数字节块的顺序读取器 / Sequential reader for the packed runtime argument byte blob
编译后记录流的顺序读取器 / Sequential reader for the compiled record stream
按编译格式 profile 特化的、按输出端类型区分的字节码执行器 / Per-sink bytecode executor specialized by the compiled format pro...
ErrorCode WriteF64FixedPrec(uint8_t precision, double value)
单个带显式精度的定点 double 快路径。 / Fast path for one fixed double with explicit precision.
ErrorCode WriteSigned(const Spec &spec, Int value)
通过共享整数字段路径写出一个有符号整数值 / Write one signed integer value through the shared integer-field path
ErrorCode WriteRaw(std::string_view text)
运行期执行器共享的字段写出原语,供所有操作码路径复用 / Executor-side field-writing primitives shared by all runtime opcodes
ErrorCode Run()
持续执行记录流,直到遇到 FormatOp::End / Run until the compiled record stream reaches FormatOp::End
ErrorCode WriteString(const Spec &spec, std::string_view text)
写出一个字符串字段值,并在需要时应用精度截断 / Write one string field value, including precision truncation when present
static char ResolveFloatSignChar(T value, const Spec &spec)
为一个浮点载荷确定最终可见的符号字符 / Resolve the visible sign character for one float payload
Executor(Sink &sink, const uint8_t *codes, const uint8_t *args)
将一个输出端、一份编译字节块和一份参数字节块绑定起来 / Bind one sink with one compiled byte blob and one packed argument blob
ErrorCode WriteTextField(std::string_view text, const Spec &spec)
按宽度与对齐策略写出一个文本字段 / Write one text field with width/alignment policy applied
ErrorCode DispatchGenericField(FormatType type)
将一个 GenericField 载荷分发到对应的宽回退路径 / Dispatch one GenericField payload to the corresponding wide fallback
ErrorCode DispatchFloatField()
读取一个浮点载荷并转发给选定的浮点语义写出路径 / Read one float payload and forward it to the selected float semantic writer
ErrorCode DispatchPointerField()
读取一个指针载荷并走指针字段写出路径 / Read one pointer payload and write it through the pointer field path
static char ResolveSignChar(Int value, const Spec &spec)
执行器的具体运行期数值写出函数 / Concrete runtime value writers for the executor
ErrorCode DispatchStringField()
读取一个字符串载荷并走字符串字段写出路径 / Read one string payload and write it through the string field path
ErrorCode WriteUnsignedDigits(std::string_view prefix, const Spec &spec, UInt value)
按编译期进制/大小写/八进制备用格式参数复用无符号数字载荷写出逻辑 / Reuse the unsigned-digit payload writer with compile-time radix,...
ErrorCode WriteIntegerField(char sign_char, std::string_view prefix, std::string_view digits, const Spec &spec)
按符号、前缀、精度与填充策略写出一个整数载荷 / Write one integer payload with sign, prefix, precision, and padding policy a...
ErrorCode DispatchSignedField()
运行期执行器中 GenericField 的分发桥接函数 / GenericField dispatch bridges for the runtime executor
ErrorCode WriteFloatField(char sign_char, std::string_view text, const Spec &spec)
按符号与字段填充策略写出一个浮点文本载荷 / Write one float text payload with sign and field padding applied
ErrorCode DispatchUnsignedField()
读取一个无符号载荷并转发给选定的整数语义写出路径 / Read one unsigned payload and forward it to the selected integer semantic ...
ErrorCode WriteU32ZeroPadWidth(uint8_t width, uint32_t value)
单个零填充 uint32_t 十进制字段的快路径。 / Fast path for one zero-padded uint32_t decimal field.
ErrorCode WriteF32FixedPrec(uint8_t precision, float value)
单个带显式精度的定点 float 快路径。 / Fast path for one fixed float with explicit precision.
ErrorCode WriteStringRaw(std::string_view text)
单个原始字符串参数的快路径。 / Fast path for one raw string argument.
ErrorCode WriteFloat(FormatType type, const Spec &spec, T value)
通过共享浮点文本后端写出一个浮点语义值 / Write one float semantic value through the shared float-text backend
ErrorCode WriteCharacter(const Spec &spec, char ch)
写出一个字符字段值 / Write one character field value
ErrorCode DispatchOp(FormatOp op)
将一个运行期操作码分发到选中的特化路径 / Dispatch one runtime opcode to the selected specialized path
ErrorCode WritePadding(char fill, size_t count)
向输出端写入重复填充字符 / Write repeated fill characters into the sink
ErrorCode WritePointer(const Spec &spec, uintptr_t value)
按规范指针字段策略写出一个指针值 / Write one pointer value using the canonical pointer field policy
ErrorCode DispatchCharacterField()
读取一个字符载荷并走字符字段写出路径 / Read one character payload and write it through the character field path
ErrorCode WriteUnsigned(const Spec &spec, UInt value)
通过共享整数字段路径写出一个无符号整数语义值 / Write one unsigned integer semantic value through the shared integer-field p...
ErrorCode WriteU32Dec(uint32_t value)
单个原始 uint32_t 十进制字段的快路径。 / Fast path for one raw uint32_t decimal field.