libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
packet.hpp
1#pragma once
2
3#include "message.hpp"
4
5namespace LibXR
6{
7#ifndef __DOXYGEN__
8#pragma pack(push, 1)
17template <typename Data>
18class Topic::PackedData
19{
20 static_assert(TopicPayload<Data>);
21
22 public:
23#pragma pack(push, 1)
29 struct
30 {
31 PackedDataHeader header_;
32 uint8_t data_[sizeof(Data)];
33 } raw;
34
35 uint8_t crc8_;
36
37#pragma pack(pop)
38
43 operator Data() { return *reinterpret_cast<Data*>(raw.data_); }
44
48 Data* operator->() { return reinterpret_cast<Data*>(raw.data_); }
49
54 const Data* operator->() const { return reinterpret_cast<const Data*>(raw.data_); }
55
56 MicrosecondTimestamp GetTimestamp() const { return raw.header_.GetTimestamp(); }
57
58 Message<Data> GetMessage() const
59 {
60 return Message<Data>{GetTimestamp(), *reinterpret_cast<const Data*>(raw.data_)};
61 }
62};
63#pragma pack(pop)
64#endif
65
66template <typename Data>
67ErrorCode Topic::DumpData(PackedData<Data>& data)
68{
69 CheckTopicPayload<Data>();
70 if (block_->data_.data.addr_ == nullptr)
71 {
72 return ErrorCode::EMPTY;
73 }
74
75 ASSERT(sizeof(Data) == block_->data_.data.size_);
76
77 return DumpPacket<SizeLimitMode::NONE>(RawData(data));
78}
79} // namespace LibXR
Data data_
存储的数据 (Stored data).
Definition rbt.hpp:99
可写原始数据视图 / Mutable raw data view
ErrorCode DumpData(PackedData< Data > &data)
转储数据到 PackedData Dumps data into PackedData format
Definition packet.hpp:67
TopicHandle block_
主题句柄,指向当前主题的内存块 Topic handle pointing to the memory block of the current topic
Definition message.hpp:547
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举
@ EMPTY
为空 | Empty