File osi_to_dds_converter.h
Last update: 22.04.2026Location: autonomy/communication/utils/osi_to_dds_converter.h
Namespaces
- simulation_framework
- simulation_framework::autonomy
- simulation_framework::autonomy::communication
- simulation_framework::autonomy::communication::utils
Includes
- core/message/rtidds/generic_bytes/generic_bytes.hpp
-
-
-
Source
#ifndef SIMFWK_AUTONOMY_AUTONOMY_COMMUNICATION_UTILS_OSITODDSCONVERTER_H
#define SIMFWK_AUTONOMY_AUTONOMY_COMMUNICATION_UTILS_OSITODDSCONVERTER_H
#include "core/message/rtidds/generic_bytes/generic_bytes.hpp"
#include <stdexcept>
#include <string>
#include <vector>
namespace simulation_framework
{
namespace autonomy
{
namespace communication
{
namespace utils
{
template <typename OsiProtoType>
rtidds::GenericBytesMessage CreateDdsMessageFromOsiProto(const int frame_counter,
const std::string& header_name,
const OsiProtoType& osi_proto_msg)
{
rtidds::GenericBytesMessage generic_msg{};
generic_msg.header = header_name;
generic_msg.frame_number = frame_counter;
generic_msg.timestamp.seconds = osi_proto_msg.timestamp().seconds();
generic_msg.timestamp.nanoseconds = osi_proto_msg.timestamp().nanos();
size_t size = osi_proto_msg.ByteSizeLong();
std::vector<unsigned char> proto_data_in_bytes;
proto_data_in_bytes.resize(size);
if (!osi_proto_msg.SerializeToArray(proto_data_in_bytes.data(), size))
{
throw std::runtime_error("[CreateDdsMessageFromOsiProto] Failed to serialize OSI proto message to bytes");
}
generic_msg.size = size;
generic_msg.bytes_array = proto_data_in_bytes;
return generic_msg;
}
template <typename OsiProtoType>
void ParseOsiProtoFromDdsMessage(const rtidds::GenericBytesMessage& dds_msg, OsiProtoType& osi_proto_msg)
{
if (!osi_proto_msg.ParseFromArray(dds_msg.bytes_array.data(), dds_msg.size))
{
throw std::runtime_error("[ParseOsiProtoFromDdsMessage] Failed to parse OSI proto message from bytes array");
}
}
} // namespace utils
} // namespace communication
} // namespace autonomy
} // namespace simulation_framework
#endif // SIMFWK_AUTONOMY_AUTONOMY_COMMUNICATION_UTILS_OSITODDSCONVERTER_H