15const uint8_t RTPS_VERSION[2] = {2, 4};
17size_t pc_rtps_header(
const uint8_t *guid_prefix,
const uint8_t *vendor_id, uint8_t *out,
size_t cap)
19 if (!guid_prefix || !vendor_id || !out || cap < Rtps::RTPS_HEADER_LEN)
27 out[4] = RTPS_VERSION[0];
28 out[5] = RTPS_VERSION[1];
29 out[6] = vendor_id[0];
30 out[7] = vendor_id[1];
31 memcpy(out + 8, guid_prefix, Rtps::RTPS_GUIDPREFIX_LEN);
32 return Rtps::RTPS_HEADER_LEN;
35size_t pc_rtps_submessage(uint8_t
id, uint8_t flags,
const uint8_t *body, uint16_t body_len, uint8_t *out,
size_t cap)
37 if (!out || (body_len && !body))
41 size_t n = 4 + (size_t)body_len;
49 if (flags & Rtps::RTPS_FLAG_ENDIAN)
51 out[2] = (uint8_t)body_len;
52 out[3] = (uint8_t)(body_len >> 8);
56 out[2] = (uint8_t)(body_len >> 8);
57 out[3] = (uint8_t)body_len;
61 memcpy(out + 4, body, body_len);
66bool pc_rtps_parse(
const uint8_t *msg,
size_t len, pc_rtps_cb cb,
void *arg)
68 if (!msg || len < Rtps::RTPS_HEADER_LEN)
72 if (msg[0] !=
'R' || msg[1] !=
'T' || msg[2] !=
'P' || msg[3] !=
'S')
77 if (msg[4] != RTPS_VERSION[0] || msg[5] > RTPS_VERSION[1])
82 size_t off = Rtps::RTPS_HEADER_LEN;
83 while (off + 4 <= len)
85 uint8_t
id = msg[off];
86 uint8_t flags = msg[off + 1];
87 uint16_t oth = (flags & Rtps::RTPS_FLAG_ENDIAN) ? (uint16_t)(msg[off + 2] | (msg[off + 3] << 8))
88 : (uint16_t)((msg[off + 2] << 8) | msg[off + 3]);
89 size_t body = oth ? oth : (len - (off + 4));
90 if (off + 4 + body > len)
96 cb(
id, flags, body ? (msg + off + 4) : nullptr, body, arg);
DDS / RTPS wire-protocol codec (PC_ENABLE_DDS).