15const uint8_t RTPS_VERSION[2] = {2, 4};
17size_t detws_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)
25 out[4] = RTPS_VERSION[0];
26 out[5] = RTPS_VERSION[1];
27 out[6] = vendor_id[0];
28 out[7] = vendor_id[1];
29 memcpy(out + 8, guid_prefix, Rtps::RTPS_GUIDPREFIX_LEN);
30 return Rtps::RTPS_HEADER_LEN;
33size_t detws_rtps_submessage(uint8_t
id, uint8_t flags,
const uint8_t *body, uint16_t body_len, uint8_t *out,
36 if (!out || (body_len && !body))
38 size_t n = 4 + (size_t)body_len;
44 if (flags & Rtps::RTPS_FLAG_ENDIAN)
46 out[2] = (uint8_t)body_len;
47 out[3] = (uint8_t)(body_len >> 8);
51 out[2] = (uint8_t)(body_len >> 8);
52 out[3] = (uint8_t)body_len;
55 memcpy(out + 4, body, body_len);
59bool detws_rtps_parse(
const uint8_t *msg,
size_t len, DetwsRtpsCb cb,
void *arg)
61 if (!msg || len < Rtps::RTPS_HEADER_LEN)
63 if (msg[0] !=
'R' || msg[1] !=
'T' || msg[2] !=
'P' || msg[3] !=
'S')
66 if (msg[4] != RTPS_VERSION[0] || msg[5] > RTPS_VERSION[1])
69 size_t off = Rtps::RTPS_HEADER_LEN;
70 while (off + 4 <= len)
72 uint8_t
id = msg[off];
73 uint8_t flags = msg[off + 1];
74 uint16_t oth = (flags & Rtps::RTPS_FLAG_ENDIAN) ? (uint16_t)(msg[off + 2] | (msg[off + 3] << 8))
75 : (uint16_t)((msg[off + 2] << 8) | msg[off + 3]);
76 size_t body = oth ? oth : (len - (off + 4));
77 if (off + 4 + body > len)
80 cb(
id, flags, body ? (msg + off + 4) : nullptr, body, arg);
DDS / RTPS wire-protocol codec (DETWS_ENABLE_DDS).