11 return static_cast<FormatType
>(*pos_++);
16 return Spec{.flags = *pos_++,
17 .fill =
static_cast<char>(*pos_++),
19 .precision = *pos_++};
24 auto text =
reinterpret_cast<const char*
>(pos_);
25 size_t size = std::strlen(text);
27 return std::string_view(text, size);
32 auto offset = Read<uint16_t>();
33 auto size = Read<uint16_t>();
34 auto text =
reinterpret_cast<const char*
>(base_ + offset);
35 return std::string_view(text, size);
51 std::string_view text)
53 if (size > capacity || text.size() > capacity - size)
57 std::memcpy(buffer + size, text.data(), text.size());
63 uint32_t value, uint8_t width)
68 (width > digit_count) ?
static_cast<size_t>(width) - digit_count : 0;
70 for (
size_t i = 0; i < zero_count; ++i)
78 return AppendBufferText(buffer, capacity, size, std::string_view(digits, digit_count));
81#if LIBXR_PRINT_ENABLE_FLOAT
83size_t Writer::TrimGeneralText(
char* text,
size_t size)
85 size_t exponent_pos = size;
86 for (
size_t i = 0; i < size; ++i)
88 if (text[i] ==
'e' || text[i] ==
'E')
95 size_t mantissa_end = exponent_pos;
96 while (mantissa_end > 0 && text[mantissa_end - 1] ==
'0')
100 if (mantissa_end > 0 && text[mantissa_end - 1] ==
'.')
105 if (exponent_pos == size)
110 std::memmove(text + mantissa_end, text + exponent_pos, size - exponent_pos);
111 return mantissa_end + (size - exponent_pos);
114bool Writer::AppendExponentText(
char* out,
size_t& out_size,
int exponent,
117 if (!
AppendBufferChar(out, float_buffer_capacity, out_size, upper_case ?
'E' :
'e'))
121 if (!
AppendBufferChar(out, float_buffer_capacity, out_size, exponent < 0 ?
'-' :
'+'))
127 unsigned int magnitude =
static_cast<unsigned int>(exponent < 0 ? -exponent : exponent);
129 if (digit_count < 2 && !
AppendBufferChar(out, float_buffer_capacity, out_size,
'0'))
135 std::string_view(digits, digit_count));
ArgumentReader(const uint8_t *data)
从单个运行期参数打包字节块构造读取器 / Create a reader over one packed runtime argument blob
Spec ReadSpec()
读取紧跟在 GenericField 类型字节后的 4 字节字段载荷 / Read the 4-byte field payload that follows one GenericField type...
std::string_view ReadInlineText()
读取内嵌在记录流中的短文本 / Read a null-terminated short text payload embedded in the record stream
std::string_view ReadTextRef()
读取指向尾部文本池的偏移和长度 / Read an offset-size pair pointing into the trailing text pool
CodeReader(const uint8_t *codes)
从单个编译字节块起点构造读取器 / Create a reader over the beginning of one compiled byte blob
FormatOp ReadOp()
读取下一条运行期操作码 / Read the next runtime opcode
FormatType ReadFormatType()
读取 GenericField 载荷中的语义类型字节 / Read the semantic type byte carried by one GenericField payload
static consteval size_t UnsignedDigitCapacity()
返回某个无符号整数在指定进制下所需的最大数字个数 / Return the maximum digit count required for one unsigned integer under the...
static bool AppendBufferText(char *buffer, size_t capacity, size_t &size, std::string_view text)
向有界本地格式化缓冲区追加一段文本 / Append one text span to a bounded local formatting buffer
static bool AppendBufferU32ZeroPad(char *buffer, size_t capacity, size_t &size, uint32_t value, uint8_t width)
追加一个 uint32_t 十进制值,并在前面补零到目标宽度 / Append one uint32_t decimal value and pad leading zeros up to the ta...
static size_t AppendUnsigned(char(&out)[N], UInt value)
把一个无符号整数写进调用方提供的定长数字缓冲区 / Append one unsigned integer into a caller-provided fixed-size digit buffer
static bool AppendBufferChar(char *buffer, size_t capacity, size_t &size, char ch)
向有界本地格式化缓冲区追加一个字符 / Append one character to a bounded local formatting buffer
运行期对单个字段描述字节组的解码视图 / Runtime view of one decoded field specification byte group