|
libxr
1.0
Want to be the best embedded framework
|
将字节流解析成 packet 并发布到已注册 topic 的状态机 / State machine that parses byte streams into packets and publishes them into registered topics More...
#include <server.hpp>
Public Types | |
| enum class | Status : uint8_t { WAIT_START , WAIT_TOPIC , WAIT_DATA_CRC } |
| parser 当前所在阶段 / Current stage of the parser More... | |
Public Member Functions | |
| Server (size_t buffer_length) | |
| 构造 parser 并分配内部暂存队列 / Construct the parser and allocate its internal staging queue | |
| void | Register (TopicHandle topic) |
| 注册一个可接收 packet 的 topic / Register one topic that may receive parsed packets | |
| size_t | ParseData (ConstRawData data) |
| 在普通上下文里喂入一批新字节 / Feed one new byte batch in normal context | |
| size_t | ParseDataFromCallback (ConstRawData data, bool in_isr) |
| 在回调/ISR 路径里喂入一批新字节 / Feed one new byte batch in callback/ISR path | |
Private Types | |
| enum class | ParseResult : uint8_t { NEED_MORE , DROPPED , DELIVERED } |
| 一次 payload 阶段处理结果 / Result of one payload-stage handling step More... | |
Private Member Functions | |
| size_t | ParseDataRaw (ConstRawData data, bool from_callback, bool in_isr) |
ParseData*() 的共享实现 / Shared implementation behind ParseData*() | |
| bool | SyncToPacketStart () |
| 把输入流同步到下一条 packet 起点 / Synchronize the input stream to the next packet start | |
| bool | ReadHeader () |
| 在已对齐前缀后继续读取并校验完整头部 / Read and validate the full header after the prefix is aligned | |
| ParseResult | ReadPayload (bool from_callback, bool in_isr) |
| 读取当前包的 payload 和尾 CRC,并在成功时发布 / Read the payload and trailing CRC of the current packet and publish it on success | |
| void | ResetParser () |
| 清空当前包的解析上下文并回到找起点状态 / Clear the current packet parsing context and return to the start-search state | |
Private Attributes | |
| Status | status_ = Status::WAIT_START |
| 当前 parser 阶段。Current parser stage. | |
| uint32_t | data_len_ = 0 |
| 当前包头声明的 payload 长度。Payload length declared by the current header. | |
| RBTree< uint32_t > | topic_map_ |
| 从 topic 名称 CRC32 到 topic 句柄的映射。Map from topic-name CRC32 to topic handle. | |
| BaseQueue | queue_ |
| 输入字节 FIFO。Input byte FIFO. | |
| RawData | parse_buff_ |
| 当前包头和 payload 的暂存缓冲区。Staging buffer holding the current header and payload. | |
| TopicHandle | current_topic_ = nullptr |
| 当前包命中的目标 topic。Target topic matched by the current packet. | |
| MicrosecondTimestamp | current_timestamp_ |
| 当前包头里的时间戳。Timestamp carried by the current packet header. | |
将字节流解析成 packet 并发布到已注册 topic 的状态机 / State machine that parses byte streams into packets and publishes them into registered topics
把字节流解析成 packet 并投递到 topic 的 parser / Parser that turns byte streams into packets and delivers them into topics
Server 自己不维护 raw topic/cache 语义;它只依赖注册 topic 的: payload_size、payload_alignment 和名字 CRC 键。 The current Server does not restore old raw topic/cache semantics by itself; it relies only on each registered topic's payload_size, payload_alignment, and name CRC key. Definition at line 28 of file server.hpp.
|
strongprivate |
一次 payload 阶段处理结果 / Result of one payload-stage handling step
| Enumerator | |
|---|---|
| NEED_MORE | 当前包还没收全。Current packet is still incomplete. |
| DROPPED | 当前包被丢弃。Current packet is dropped. |
| DELIVERED | 当前包已发布。Current packet is delivered. |
Definition at line 87 of file server.hpp.
|
strong |
parser 当前所在阶段 / Current stage of the parser
Definition at line 35 of file server.hpp.
| Topic::Server::Server | ( | size_t | buffer_length | ) |
构造 parser 并分配内部暂存队列 / Construct the parser and allocate its internal staging queue
| buffer_length | 内部字节队列和暂存缓冲区大小 / Size of the internal byte queue and staging buffer |
Definition at line 12 of file server.cpp.
| size_t Topic::Server::ParseData | ( | ConstRawData | data | ) |
在普通上下文里喂入一批新字节 / Feed one new byte batch in normal context
| data | 新收到的原始字节 / Newly received raw bytes |
Definition at line 36 of file server.cpp.
| size_t Topic::Server::ParseDataFromCallback | ( | ConstRawData | data, |
| bool | in_isr ) |
在回调/ISR 路径里喂入一批新字节 / Feed one new byte batch in callback/ISR path
| data | 新收到的原始字节 / Newly received raw bytes |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
Definition at line 41 of file server.cpp.
|
private |
ParseData*() 的共享实现 / Shared implementation behind ParseData*()
| data | 新收到的原始字节 / Newly received raw bytes |
| from_callback | 是否来自回调路径 / Whether the current parse comes from callback path |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
Definition at line 46 of file server.cpp.
|
private |
在已对齐前缀后继续读取并校验完整头部 / Read and validate the full header after the prefix is aligned
true,否则返回 false / Returns true when the header is valid, otherwise false Definition at line 98 of file server.cpp.
|
private |
读取当前包的 payload 和尾 CRC,并在成功时发布 / Read the payload and trailing CRC of the current packet and publish it on success
| from_callback | 是否来自回调路径 / Whether the current parse comes from callback path |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
Definition at line 147 of file server.cpp.
| void Topic::Server::Register | ( | TopicHandle | topic | ) |
注册一个可接收 packet 的 topic / Register one topic that may receive parsed packets
| topic | 目标 topic 句柄 / Target topic handle |
payload_size + PACK_BASE_SIZE 能放进本 server 的 暂存缓冲区。 Registration asserts that the topic's payload_size + PACK_BASE_SIZE fits in this server's staging buffer. CACHE_LINE_SIZE 对齐分配;注册时还会 断言该 topic 的 payload_alignment <= CACHE_LINE_SIZE。 The server's internal staging buffer is allocated once at CACHE_LINE_SIZE alignment during construction; registration also asserts that the topic's payload_alignment <= CACHE_LINE_SIZE. Definition at line 23 of file server.cpp.
|
private |
清空当前包的解析上下文并回到找起点状态 / Clear the current packet parsing context and return to the start-search state
Definition at line 197 of file server.cpp.
|
private |
把输入流同步到下一条 packet 起点 / Synchronize the input stream to the next packet start
true,否则返回 false / Returns true when a packet start byte is found, otherwise false Definition at line 80 of file server.cpp.
|
private |
当前包头里的时间戳。Timestamp carried by the current packet header.
Definition at line 142 of file server.hpp.
|
private |
当前包命中的目标 topic。Target topic matched by the current packet.
Definition at line 141 of file server.hpp.
|
private |
当前包头声明的 payload 长度。Payload length declared by the current header.
Definition at line 137 of file server.hpp.
|
private |
当前包头和 payload 的暂存缓冲区。Staging buffer holding the current header and payload.
Definition at line 140 of file server.hpp.
|
private |
输入字节 FIFO。Input byte FIFO.
Definition at line 139 of file server.hpp.
|
private |
当前 parser 阶段。Current parser stage.
Definition at line 136 of file server.hpp.
|
private |
从 topic 名称 CRC32 到 topic 句柄的映射。Map from topic-name CRC32 to topic handle.
Definition at line 138 of file server.hpp.