CARLA
Loading...
Searching...
No Matches
UserDataFormat.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2// This work is licensed under the terms of the MIT license.
3// For a copy, see <https://opensource.org/licenses/MIT>.
4
5#pragma once
6
8
9#include <cstdint>
10#include <cstring>
11#include <vector>
12
13namespace carla {
14namespace ros2 {
15
16/// Builds the REP-2016 endpoint USER_DATA payload encoding a REP-2011 type
17/// hash.
18///
19/// Per OMG DDSI-RTPS v2.5 §9.6.2.2.2, PID_USER_DATA (0x002c) carries the
20/// DDS UserDataQosPolicy octet sequence. ROS 2 REP-2016 defines the payload
21/// as a set of ASCII key=value pairs separated by semicolons, e.g.:
22///
23/// typehash=RIHS01_<64 lowercase hex>;
24///
25/// rmw_cyclonedds_cpp and rmw_fastrtps_cpp on Iron / Jazzy parse this string
26/// from PID_USER_DATA during SEDP endpoint discovery to perform REP-2011
27/// type-hash-based matching. When it is absent (null), Jazzy rmws emit:
28/// [WARN] Failed to parse type hash ... from USER_DATA '(null)'.
29///
30/// This helper is vendor-agnostic; the resulting byte vector is fed to:
31/// FastDDS : DataWriterQos::user_data().data_vec()
32/// DataReaderQos::user_data().data_vec()
33/// CycloneDDS: dds_qset_userdata(qos, data, size)
34///
35/// If type_hash is nullptr (used for types whose hash is unknown), an empty
36/// vector is returned and user_data should NOT be set.
37inline std::vector<uint8_t> build_user_data(const char* type_hash) {
38 if (type_hash == nullptr) {
39 return {};
40 }
41 // Payload: "typehash=<hash>;" (no null terminator — DDS carries length)
42 static const char prefix[] = "typehash=";
43 static const char suffix[] = ";";
44 const size_t hash_len = std::strlen(type_hash);
45 const size_t total_len = sizeof(prefix) - 1u + hash_len + sizeof(suffix) - 1u;
46
47 std::vector<uint8_t> payload;
48 payload.reserve(total_len);
49 for (const char* p = prefix; *p; ++p) payload.push_back(static_cast<uint8_t>(*p));
50 for (size_t i = 0u; i < hash_len; ++i) payload.push_back(static_cast<uint8_t>(type_hash[i]));
51 for (const char* p = suffix; *p; ++p) payload.push_back(static_cast<uint8_t>(*p));
52 return payload;
53}
54
55/// Convenience: build user_data from the CdrTopicInfo<T>::type_hash() of T.
56/// Returns an empty vector (and the caller must skip setting user_data) when
57/// CdrTopicInfo<T>::type_hash() returns nullptr.
58template<typename T>
59inline std::vector<uint8_t> build_user_data_for() {
61}
62
63} // namespace ros2
64} // namespace carla
std::vector< uint8_t > build_user_data_for()
Convenience: build user_data from the CdrTopicInfo<T>::type_hash() of T.
std::vector< uint8_t > build_user_data(const char *type_hash)
Builds the REP-2016 endpoint USER_DATA payload encoding a REP-2011 type hash.
This file contains definitions of common data structures used in traffic manager.
Per-type metadata needed by the middleware layer.