Skip to main content

Packet Packing and Parsing

The Message module provides a unified PackedData<T> format and a Server parser for structured transport over UART, CAN, network links, and similar channels.

Packet Example

float value = 36.5f;
topic.Publish(value);

LibXR::Topic::PackedData<float> pkt;
topic.DumpData(pkt);

DumpData(pkt) depends on topic cache. If cache was not enabled when the topic was created, this call returns ErrorCode::EMPTY.

Packet Layout

FieldMeaning
0xA5fixed prefix
CRC32topic name checksum
Lengthpayload length (24-bit)
CRC8header checksum
Datapayload
CRC8tail checksum

Server Parsing Example

LibXR::Topic::Server server(512);
server.Register(topic);
server.ParseData(LibXR::ConstRawData(pkt));

The parser handles sticky packets and fragmented input, validates the frame, and publishes valid payloads to the target Topic.

Data Export and PackData

Read Cached Data

float val = 0;
topic.DumpData(val);

Export as PackedData

LibXR::Topic::PackedData<float> pkt;
topic.DumpData(pkt);

Pack Arbitrary Data Manually

float value = 123.45f;
LibXR::RawData src(value);
uint8_t buffer[128];
LibXR::RawData dst(buffer, sizeof(buffer));

Topic::PackData(topic.GetKey(), dst, src);

Method Comparison

ScenarioRecommended methodNeeds cachePacked
Get latest valueDumpData(DataType)YesNo
Build network packetDumpData(PackedData&)YesYes
Fill custom bufferDumpData<Mode>(RawData, pack)YesOptional
Pack without cachePackData()NoYes