From 92586f4538db5d34e7aba77581aa0e19bce8cc36 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 22 Jul 2021 15:17:34 +0200 Subject: [PATCH 1/2] Prepare type size for alignment requirements. Signed-off-by: Miguel Company --- rmw_fastrtps_cpp/src/type_support_common.cpp | 1 + .../rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp | 1 + .../rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index ef5567641..bbca127eb 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -54,6 +54,7 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members) // Total size is encapsulation size + data size m_typeSize = 4 + data_size; + m_typeSize = (m_typeSize + 3) & ~3; } size_t TypeSupport::getEstimatedSerializedSize(const void * ros_message, const void * impl) const diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index a21e20721..bc88f12e1 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -60,6 +60,7 @@ MessageTypeSupport::MessageTypeSupport( } else { this->m_typeSize++; } + this->m_typeSize = (this->m_typeSize + 3) & ~3; } } // namespace rmw_fastrtps_dynamic_cpp diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index 467703712..a3bf402c1 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -59,6 +59,7 @@ RequestTypeSupport::RequestTypeSupport( } else { this->m_typeSize++; } + this->m_typeSize = (this->m_typeSize + 3) & ~3; } template @@ -90,6 +91,7 @@ ResponseTypeSupport::ResponseTypeSupport } else { this->m_typeSize++; } + this->m_typeSize = (this->m_typeSize + 3) & ~3; } } // namespace rmw_fastrtps_dynamic_cpp From 4584b75095a1c0a560b59713b093a32d6325ef7b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 26 Jul 2021 08:44:51 +0200 Subject: [PATCH 2/2] Add comments on alignment code. Signed-off-by: Miguel Company --- rmw_fastrtps_cpp/src/type_support_common.cpp | 1 + .../rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp | 1 + .../rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index bbca127eb..25bdb86a4 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -54,6 +54,7 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members) // Total size is encapsulation size + data size m_typeSize = 4 + data_size; + // Account for RTPS submessage alignment m_typeSize = (m_typeSize + 3) & ~3; } diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index bc88f12e1..95f48e996 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -60,6 +60,7 @@ MessageTypeSupport::MessageTypeSupport( } else { this->m_typeSize++; } + // Account for RTPS submessage alignment this->m_typeSize = (this->m_typeSize + 3) & ~3; } diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index a3bf402c1..45e3fc602 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -59,6 +59,7 @@ RequestTypeSupport::RequestTypeSupport( } else { this->m_typeSize++; } + // Account for RTPS submessage alignment this->m_typeSize = (this->m_typeSize + 3) & ~3; } @@ -91,6 +92,7 @@ ResponseTypeSupport::ResponseTypeSupport } else { this->m_typeSize++; } + // Account for RTPS submessage alignment this->m_typeSize = (this->m_typeSize + 3) & ~3; }