libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
Writer::CodeReader Class Reference

编译后记录流的顺序读取器 / Sequential reader for the compiled record stream More...

#include <writer_reader.hpp>

Public Member Functions

 CodeReader (const uint8_t *codes)
 从单个编译字节块起点构造读取器 / Create a reader over the beginning of one compiled byte blob
 
FormatOp ReadOp ()
 读取下一条运行期操作码 / Read the next runtime opcode
 
template<typename T >
Read ()
 读取编译期发射器按本机字节序写入的 POD 值 / Read a native-endian POD value emitted by the compile-time emitter
 
FormatType ReadFormatType ()
 读取 GenericField 载荷中的语义类型字节 / Read the semantic type byte carried by one GenericField payload
 
Spec ReadSpec ()
 读取紧跟在 GenericField 类型字节后的 4 字节字段载荷 / Read the 4-byte field payload that follows one GenericField type byte
 
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
 

Private Attributes

const uint8_t * pos_ = nullptr
 
const uint8_t * base_ = nullptr
 

Detailed Description

编译后记录流的顺序读取器 / Sequential reader for the compiled record stream

Definition at line 10 of file writer_reader.hpp.

Constructor & Destructor Documentation

◆ CodeReader()

Writer::CodeReader::CodeReader ( const uint8_t * codes)
inlineexplicit

从单个编译字节块起点构造读取器 / Create a reader over the beginning of one compiled byte blob

Parameters
codes指向单个编译字节块起点的指针 / Pointer to the beginning of one compiled byte blob

Definition at line 17 of file writer_reader.hpp.

17 : pos_(codes), base_(codes)
18 {
19 }

Member Function Documentation

◆ Read()

template<typename T >
T Writer::CodeReader::Read ( )
inlinenodiscard

读取编译期发射器按本机字节序写入的 POD 值 / Read a native-endian POD value emitted by the compile-time emitter

Template Parameters
T待读取的 POD 类型 / POD type to read
Returns
返回解码后的 POD 值 / Returns the decoded POD value

Definition at line 33 of file writer_reader.hpp.

34 {
35 T value{};
36 std::memcpy(&value, pos_, sizeof(T));
37 pos_ += sizeof(T);
38 return value;
39 }

◆ ReadFormatType()

FormatType Writer::CodeReader::ReadFormatType ( )
inlinenodiscard

读取 GenericField 载荷中的语义类型字节 / Read the semantic type byte carried by one GenericField payload

Returns
返回解码后的字段语义类型 / Returns the decoded field semantic type

Definition at line 45 of file writer_reader.hpp.

45{ return static_cast<FormatType>(*pos_++); }

◆ ReadInlineText()

std::string_view Writer::CodeReader::ReadInlineText ( )
inlinenodiscard

读取内嵌在记录流中的短文本 / Read a null-terminated short text payload embedded in the record stream

Returns
返回该内嵌文本片段的视图 / Returns a view of the embedded text span

Definition at line 68 of file writer_reader.hpp.

69 {
70 auto text = reinterpret_cast<const char*>(pos_);
71 size_t size = std::strlen(text);
72 pos_ += size + 1;
73 return std::string_view(text, size);
74 }

◆ ReadOp()

FormatOp Writer::CodeReader::ReadOp ( )
inlinenodiscard

读取下一条运行期操作码 / Read the next runtime opcode

Returns
返回下一条解码后的运行期操作码 / Returns the next decoded runtime opcode

Definition at line 25 of file writer_reader.hpp.

25{ return static_cast<FormatOp>(*pos_++); }

◆ ReadSpec()

Spec Writer::CodeReader::ReadSpec ( )
inlinenodiscard

读取紧跟在 GenericField 类型字节后的 4 字节字段载荷 / Read the 4-byte field payload that follows one GenericField type byte

The opcode and semantic type bytes are read separately. This call only consumes flags, fill, width, and precision, in that order. 操作码与语义类型字节由外层单独读取;本函数只继续读取后续 flags、fill、width、precision 这 4 个字节,顺序固定。

Returns
返回解码后的运行期字段规格 / Returns the decoded runtime field spec

Definition at line 56 of file writer_reader.hpp.

57 {
58 return Spec{.flags = *pos_++,
59 .fill = static_cast<char>(*pos_++),
60 .width = *pos_++,
61 .precision = *pos_++};
62 }

◆ ReadTextRef()

std::string_view Writer::CodeReader::ReadTextRef ( )
inlinenodiscard

读取指向尾部文本池的偏移和长度 / Read an offset-size pair pointing into the trailing text pool

The offset is already rebased against the final code blob base. 该偏移已经按最终代码块起点完成重定位。

Returns
返回尾部文本池中被引用的文本片段 / Returns the referenced text span inside the trailing text pool

Definition at line 83 of file writer_reader.hpp.

84 {
85 auto offset = Read<uint16_t>();
86 auto size = Read<uint16_t>();
87 auto text = reinterpret_cast<const char*>(base_ + offset);
88 return std::string_view(text, size);
89 }
T Read()
读取编译期发射器按本机字节序写入的 POD 值 / Read a native-endian POD value emitted by the compile-time emitter

Field Documentation

◆ base_

const uint8_t* Writer::CodeReader::base_ = nullptr
private

Definition at line 93 of file writer_reader.hpp.

◆ pos_

const uint8_t* Writer::CodeReader::pos_ = nullptr
private

Definition at line 92 of file writer_reader.hpp.


The documentation for this class was generated from the following file: