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);
40bool Writer::AppendBufferChar(
char* buffer,
size_t capacity,
size_t& size,
char ch)
50bool Writer::AppendBufferText(
char* buffer,
size_t capacity,
size_t& size,
51 std::string_view text)
53 if (size > capacity || text.size() > capacity - size)
57 std::memcpy(buffer + size, text.data(), text.size());
62bool Writer::AppendBufferU32ZeroPad(
char* buffer,
size_t capacity,
size_t& size,
63 uint32_t value, uint8_t width)
65 char digits[UnsignedDigitCapacity<uint32_t, 10>()];
66 size_t digit_count = AppendUnsigned<10>(digits, value);
68 (width > digit_count) ?
static_cast<size_t>(width) - digit_count : 0;
70 for (
size_t i = 0; i < zero_count; ++i)
72 if (!AppendBufferChar(buffer, capacity, size,
'0'))
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 ?
'-' :
'+'))
126 char digits[UnsignedDigitCapacity<unsigned int, 10>()];
127 unsigned int magnitude =
static_cast<unsigned int>(exponent < 0 ? -exponent : exponent);
128 size_t digit_count = AppendUnsigned<10>(digits, magnitude);
129 if (digit_count < 2 && !AppendBufferChar(out, float_buffer_capacity, out_size,
'0'))
134 return AppendBufferText(out, float_buffer_capacity, out_size,
135 std::string_view(digits, digit_count));
ArgumentReader(const uint8_t *data)
从单个运行期参数打包字节块构造读取器 / Create a reader over one packed runtime argument blob
FormatOp ReadOp()
读取下一条运行期操作码 / Read the next runtime opcode
Spec ReadSpec()
读取紧跟在 GenericField 类型字节后的 4 字节字段载荷 / Read the 4-byte field payload that follows one GenericField type...
std::string_view ReadTextRef()
读取指向尾部文本池的偏移和长度 / Read an offset-size pair pointing into the trailing text pool
FormatType ReadFormatType()
读取 GenericField 载荷中的语义类型字节 / Read the semantic type byte carried by one GenericField payload
CodeReader(const uint8_t *codes)
从单个编译字节块起点构造读取器 / Create a reader over the beginning of one compiled byte blob
std::string_view ReadInlineText()
读取内嵌在记录流中的短文本 / Read a null-terminated short text payload embedded in the record stream