From e21254c78a659643828233fd019e918dc380404b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 20 Feb 2024 19:24:01 +0100 Subject: [PATCH] Improve wide string (de)serialization in rwm_dynamic_fastrtps_cpp (#740) * Move type support headers to src Signed-off-by: Miguel Company * Fix references to moved headers Signed-off-by: Miguel Company * move macros.hpp to src/serialization_helpers.hpp Signed-off-by: Miguel Company * Move other non-api headers Signed-off-by: Miguel Company * Move common code into serialize_wide_string. Signed-off-by: Miguel Company * Move common code into deserialize_wide_string. Signed-off-by: Miguel Company * Move serialization into serialization_helpers.hpp Signed-off-by: Miguel Company * Move deserialization into serialization_helpers.hpp Signed-off-by: Miguel Company * Fix header guards Signed-off-by: Miguel Company * Linters Signed-off-by: Miguel Company * Do not account for extra character on serialized size calculation Signed-off-by: Miguel Company * Remove dependency on rosidl_typesupport_fastrtps_c(pp) Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company --- rmw_fastrtps_dynamic_cpp/CMakeLists.txt | 6 -- .../QUALITY_DECLARATION.md | 2 - .../rmw_fastrtps_dynamic_cpp/macros.hpp | 36 ------- rmw_fastrtps_dynamic_cpp/package.xml | 4 - .../MessageTypeSupport.hpp | 6 +- .../MessageTypeSupport_impl.hpp | 8 +- .../ServiceTypeSupport.hpp | 6 +- .../ServiceTypeSupport_impl.hpp | 8 +- .../TypeSupport.hpp | 6 +- .../TypeSupport_impl.hpp | 68 +++++------- .../src/init_rmw_context_impl.cpp | 8 +- .../init_rmw_context_impl.hpp | 6 +- rmw_fastrtps_dynamic_cpp/src/publisher.cpp | 2 +- .../publisher.hpp | 6 +- rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp | 5 +- rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp | 3 +- .../src/rmw_publisher.cpp | 2 +- .../src/rmw_subscription.cpp | 2 +- .../src/serialization_helpers.hpp | 101 ++++++++++++++++++ rmw_fastrtps_dynamic_cpp/src/subscription.cpp | 2 +- .../subscription.hpp | 6 +- .../src/type_support_common.cpp | 2 +- .../src/type_support_common.hpp | 4 +- .../src/type_support_proxy.cpp | 2 +- 24 files changed, 171 insertions(+), 130 deletions(-) delete mode 100644 rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/MessageTypeSupport.hpp (87%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/MessageTypeSupport_impl.hpp (89%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/ServiceTypeSupport.hpp (88%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/ServiceTypeSupport_impl.hpp (93%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/TypeSupport.hpp (97%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/TypeSupport_impl.hpp (94%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/init_rmw_context_impl.hpp (84%) rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/publisher.hpp (87%) create mode 100644 rmw_fastrtps_dynamic_cpp/src/serialization_helpers.hpp rename rmw_fastrtps_dynamic_cpp/{include/rmw_fastrtps_dynamic_cpp => src}/subscription.hpp (87%) diff --git a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt index f2331d677..1128ef855 100644 --- a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt +++ b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt @@ -44,8 +44,6 @@ find_package(FastRTPS 2.10 REQUIRED MODULE) find_package(rmw REQUIRED) find_package(rosidl_runtime_c REQUIRED) -find_package(rosidl_typesupport_fastrtps_c REQUIRED) -find_package(rosidl_typesupport_fastrtps_cpp REQUIRED) find_package(rosidl_typesupport_introspection_c REQUIRED) find_package(rosidl_typesupport_introspection_cpp REQUIRED) @@ -108,8 +106,6 @@ target_link_libraries(rmw_fastrtps_dynamic_cpp PUBLIC rmw::rmw rmw_fastrtps_shared_cpp::rmw_fastrtps_shared_cpp rosidl_runtime_c::rosidl_runtime_c - rosidl_typesupport_fastrtps_c::rosidl_typesupport_fastrtps_c - rosidl_typesupport_fastrtps_cpp::rosidl_typesupport_fastrtps_cpp rosidl_typesupport_introspection_c::rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp::rosidl_typesupport_introspection_cpp ) @@ -135,8 +131,6 @@ ament_export_dependencies( rmw rmw_fastrtps_shared_cpp rosidl_runtime_c - rosidl_typesupport_fastrtps_c - rosidl_typesupport_fastrtps_cpp rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp ) diff --git a/rmw_fastrtps_dynamic_cpp/QUALITY_DECLARATION.md b/rmw_fastrtps_dynamic_cpp/QUALITY_DECLARATION.md index 073bec19b..65ed69649 100644 --- a/rmw_fastrtps_dynamic_cpp/QUALITY_DECLARATION.md +++ b/rmw_fastrtps_dynamic_cpp/QUALITY_DECLARATION.md @@ -127,8 +127,6 @@ Results of the nightly linter tests can be found [here](https://ci.ros2.org/view * `rmw_dds_common`: [QUALITY DECLARATION](https://github.com/ros2/rmw_dds_common/blob/master/rmw_dds_common/QUALITY_DECLARATION.md) * `rmw_fastrtps_shared_cpp`: [QUALITY DECLARATION](https://github.com/ros2/rmw_fastrtps/blob/master/rmw_fastrtps_shared_cpp/QUALITY_DECLARATION.md) * `rosidl_runtime_c`: [QUALITY DECLARATION](https://github.com/ros2/rosidl/blob/master/rosidl_runtime_c/QUALITY_DECLARATION.md) -* `rosidl_typesupport_fastrtps_c`: [QUALITY DECLARATION](https://github.com/ros2/rosidl_typesupport_fastrtps/blob/master/rosidl_typesupport_fastrtps_c/QUALITY_DECLARATION.md) -* `rosidl_typesupport_fastrtps_cpp`: [QUALITY DECLARATION](https://github.com/ros2/rosidl_typesupport_fastrtps/blob/master/rosidl_typesupport_fastrtps_cpp/QUALITY_DECLARATION.md) * `rosidl_typesupport_introspection_c` * `rosidl_typesupport_introspection_cpp` diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp deleted file mode 100644 index 19d66de5f..000000000 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2016 Open Source Robotics Foundation, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__MACROS_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__MACROS_HPP_ - -#include -#include - -#define SPECIALIZE_GENERIC_C_SEQUENCE(C_NAME, C_TYPE) \ - template<> \ - struct GenericCSequence \ - { \ - using type = rosidl_runtime_c__ ## C_NAME ## __Sequence; \ - \ - static void fini(type * array) { \ - rosidl_runtime_c__ ## C_NAME ## __Sequence__fini(array); \ - } \ - \ - static bool init(type * array, size_t size) { \ - return rosidl_runtime_c__ ## C_NAME ## __Sequence__init(array, size); \ - } \ - }; - -#endif // RMW_FASTRTPS_DYNAMIC_CPP__MACROS_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/package.xml b/rmw_fastrtps_dynamic_cpp/package.xml index 953fac735..3aa31b2a4 100644 --- a/rmw_fastrtps_dynamic_cpp/package.xml +++ b/rmw_fastrtps_dynamic_cpp/package.xml @@ -29,8 +29,6 @@ rmw_dds_common rmw_fastrtps_shared_cpp rosidl_runtime_c - rosidl_typesupport_fastrtps_c - rosidl_typesupport_fastrtps_cpp rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp @@ -43,8 +41,6 @@ rmw_dds_common rmw_fastrtps_shared_cpp rosidl_runtime_c - rosidl_typesupport_fastrtps_c - rosidl_typesupport_fastrtps_cpp rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport.hpp similarity index 87% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp rename to rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport.hpp index 67d8a72b8..31c77a683 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_HPP_ +#ifndef MESSAGETYPESUPPORT_HPP_ +#define MESSAGETYPESUPPORT_HPP_ #include #include @@ -39,4 +39,4 @@ class MessageTypeSupport : public TypeSupport #include "MessageTypeSupport_impl.hpp" -#endif // RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_HPP_ +#endif // MESSAGETYPESUPPORT_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp similarity index 89% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp rename to rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp index 95f48e996..c56945ae1 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_IMPL_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_IMPL_HPP_ +#ifndef MESSAGETYPESUPPORT_IMPL_HPP_ +#define MESSAGETYPESUPPORT_IMPL_HPP_ #include #include @@ -25,7 +25,7 @@ #include "rcpputils/find_and_replace.hpp" -#include "rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp" +#include "MessageTypeSupport.hpp" #include "rosidl_typesupport_introspection_cpp/field_types.hpp" namespace rmw_fastrtps_dynamic_cpp @@ -66,4 +66,4 @@ MessageTypeSupport::MessageTypeSupport( } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__MESSAGETYPESUPPORT_IMPL_HPP_ +#endif // MESSAGETYPESUPPORT_IMPL_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport.hpp similarity index 88% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp rename to rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport.hpp index c4ac036d7..01f2713e6 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_HPP_ +#ifndef SERVICETYPESUPPORT_HPP_ +#define SERVICETYPESUPPORT_HPP_ #include @@ -44,4 +44,4 @@ class ResponseTypeSupport : public TypeSupport #include "ServiceTypeSupport_impl.hpp" -#endif // RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_HPP_ +#endif // SERVICETYPESUPPORT_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp similarity index 93% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp rename to rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp index 45e3fc602..b7152480a 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_IMPL_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_IMPL_HPP_ +#ifndef SERVICETYPESUPPORT_IMPL_HPP_ +#define SERVICETYPESUPPORT_IMPL_HPP_ #include #include @@ -24,7 +24,7 @@ #include "rcpputils/find_and_replace.hpp" -#include "rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp" +#include "ServiceTypeSupport.hpp" #include "rosidl_typesupport_introspection_cpp/field_types.hpp" namespace rmw_fastrtps_dynamic_cpp @@ -98,4 +98,4 @@ ResponseTypeSupport::ResponseTypeSupport } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__SERVICETYPESUPPORT_IMPL_HPP_ +#endif // SERVICETYPESUPPORT_IMPL_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp similarity index 97% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport.hpp rename to rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp index 270839275..627e4d5c2 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_HPP_ +#ifndef TYPESUPPORT_HPP_ +#define TYPESUPPORT_HPP_ #include #include @@ -198,4 +198,4 @@ class TypeSupport : public BaseTypeSupport #include "TypeSupport_impl.hpp" -#endif // RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_HPP_ +#endif // TYPESUPPORT_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp similarity index 94% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp rename to rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 899119f88..f3a636062 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_IMPL_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_IMPL_HPP_ +#ifndef TYPESUPPORT_IMPL_HPP_ +#define TYPESUPPORT_IMPL_HPP_ #include #include @@ -23,13 +23,8 @@ #include "fastcdr/FastBuffer.h" #include "fastcdr/exceptions/Exception.h" -#include "rmw_fastrtps_dynamic_cpp/TypeSupport.hpp" -#include "rmw_fastrtps_dynamic_cpp/macros.hpp" - #include "rmw/error_handling.h" -#include "rosidl_typesupport_fastrtps_c/wstring_conversion.hpp" -#include "rosidl_typesupport_fastrtps_cpp/wstring_conversion.hpp" #include "rosidl_typesupport_introspection_cpp/field_types.hpp" #include "rosidl_typesupport_introspection_cpp/message_introspection.hpp" #include "rosidl_typesupport_introspection_cpp/service_introspection.hpp" @@ -40,6 +35,9 @@ #include "rosidl_runtime_c/primitives_sequence_functions.h" #include "rosidl_runtime_c/u16string_functions.h" +#include "TypeSupport.hpp" +#include "serialization_helpers.hpp" + namespace rmw_fastrtps_dynamic_cpp { @@ -93,11 +91,9 @@ void serialize_field( void * field, eprosima::fastcdr::Cdr & ser) { - std::wstring wstr; if (!member->is_array_) { auto u16str = static_cast(field); - rosidl_typesupport_fastrtps_cpp::u16string_to_wstring(*u16str, wstr); - ser << wstr; + ser << *u16str; } else { size_t size; if (member->array_size_ && !member->is_upper_bound_) { @@ -109,8 +105,7 @@ void serialize_field( for (size_t i = 0; i < size; ++i) { const void * element = member->get_const_function(field, i); auto u16str = static_cast(element); - rosidl_typesupport_fastrtps_cpp::u16string_to_wstring(*u16str, wstr); - ser << wstr; + ser << *u16str; } } } @@ -179,23 +174,19 @@ void serialize_field( void * field, eprosima::fastcdr::Cdr & ser) { - std::wstring wstr; if (!member->is_array_) { auto u16str = static_cast(field); - rosidl_typesupport_fastrtps_c::u16string_to_wstring(*u16str, wstr); - ser << wstr; + ser << *u16str; } else if (member->array_size_ && !member->is_upper_bound_) { auto array = static_cast(field); for (size_t i = 0; i < member->array_size_; ++i) { - rosidl_typesupport_fastrtps_c::u16string_to_wstring(array[i], wstr); - ser << wstr; + ser << array[i]; } } else { auto sequence = static_cast(field); ser << static_cast(sequence->size); for (size_t i = 0; i < sequence->size; ++i) { - rosidl_typesupport_fastrtps_c::u16string_to_wstring(sequence->data[i], wstr); - ser << wstr; + ser << sequence->data[i]; } } } @@ -335,17 +326,19 @@ size_t next_field_align_string( const size_t padding = 4; size_t character_size = (member->type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) ? 4 : 1; + size_t extra_char = + (member->type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) ? 0 : 1; if (!member->is_array_) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; auto & str = *static_cast(field); - current_alignment += character_size * (str.size() + 1); + current_alignment += character_size * (str.size() + extra_char); } else if (member->array_size_ && !member->is_upper_bound_) { auto str_arr = static_cast(field); for (size_t index = 0; index < member->array_size_; ++index) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - current_alignment += character_size * (str_arr[index].size() + 1); + current_alignment += character_size * (str_arr[index].size() + extra_char); } } else { auto & data = *reinterpret_cast *>(field); @@ -354,7 +347,7 @@ size_t next_field_align_string( for (auto & it : data) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - current_alignment += character_size * (it.size() + 1); + current_alignment += character_size * (it.size() + extra_char); } } return current_alignment; @@ -437,14 +430,14 @@ size_t next_field_align_string( auto u16str = static_cast(field); current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - current_alignment += 4 * (u16str->size + 1); + current_alignment += 4 * (u16str->size); } else { if (member->array_size_ && !member->is_upper_bound_) { auto string_field = static_cast(field); for (size_t i = 0; i < member->array_size_; ++i) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - current_alignment += 4 * (string_field[i].size + 1); + current_alignment += 4 * (string_field[i].size); } } else { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); @@ -454,7 +447,7 @@ size_t next_field_align_string( for (size_t i = 0; i < string_sequence_field.size; ++i) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - current_alignment += 4 * (string_sequence_field.data[i].size + 1); + current_alignment += 4 * (string_sequence_field.data[i].size); } } } @@ -598,11 +591,8 @@ inline void deserialize_field( void * field, eprosima::fastcdr::Cdr & deser) { - std::wstring wstr; if (!member->is_array_) { - deser >> wstr; - rosidl_typesupport_fastrtps_cpp::wstring_to_u16string( - wstr, *static_cast(field)); + deser >> *static_cast(field); } else { uint32_t size; if (member->array_size_ && !member->is_upper_bound_) { @@ -614,8 +604,7 @@ inline void deserialize_field( for (size_t i = 0; i < size; ++i) { void * element = member->get_function(field, i); auto u16str = static_cast(element); - deser >> wstr; - rosidl_typesupport_fastrtps_cpp::wstring_to_u16string(wstr, *u16str); + deser >> *u16str; } } } @@ -691,16 +680,12 @@ inline void deserialize_field( void * field, eprosima::fastcdr::Cdr & deser) { - std::wstring wstr; if (!member->is_array_) { - deser >> wstr; - rosidl_typesupport_fastrtps_c::wstring_to_u16string( - wstr, *static_cast(field)); + deser >> *static_cast(field); } else if (member->array_size_ && !member->is_upper_bound_) { auto array = static_cast(field); for (size_t i = 0; i < member->array_size_; ++i) { - deser >> wstr; - rosidl_typesupport_fastrtps_c::wstring_to_u16string(wstr, array[i]); + deser >> array[i]; } } else { uint32_t size; @@ -710,8 +695,7 @@ inline void deserialize_field( throw std::runtime_error("unable to initialize rosidl_runtime_c__U16String sequence"); } for (size_t i = 0; i < sequence->size; ++i) { - deser >> wstr; - rosidl_typesupport_fastrtps_c::wstring_to_u16string(wstr, sequence->data[i]); + deser >> sequence->data[i]; } } } @@ -882,10 +866,12 @@ size_t TypeSupport::calculateMaxSerializedSize( this->is_plain_ = false; size_t character_size = (member->type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) ? 4 : 1; + size_t extra_char = + (member->type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) ? 0 : 1; for (size_t index = 0; index < array_size; ++index) { current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + - character_size * (member->string_upper_bound_ + 1); + character_size * (member->string_upper_bound_ + extra_char); } } break; @@ -995,4 +981,4 @@ bool TypeSupport::deserializeROSmessage( } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__TYPESUPPORT_IMPL_HPP_ +#endif // TYPESUPPORT_IMPL_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.cpp b/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.cpp index d8e12d127..2574a163d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "rmw_fastrtps_dynamic_cpp/init_rmw_context_impl.hpp" +#include "init_rmw_context_impl.hpp" #include #include @@ -25,10 +25,9 @@ #include "rmw_dds_common/msg/participant_entities_info.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/publisher.hpp" -#include "rmw_fastrtps_dynamic_cpp/subscription.hpp" #include "rmw_fastrtps_shared_cpp/custom_participant_info.hpp" +#include "rmw_fastrtps_shared_cpp/listener_thread.hpp" #include "rmw_fastrtps_shared_cpp/participant.hpp" #include "rmw_fastrtps_shared_cpp/publisher.hpp" #include "rmw_fastrtps_shared_cpp/subscription.hpp" @@ -36,7 +35,8 @@ #include "rosidl_typesupport_cpp/message_type_support.hpp" -#include "rmw_fastrtps_shared_cpp/listener_thread.hpp" +#include "publisher.hpp" +#include "subscription.hpp" using rmw_dds_common::msg::ParticipantEntitiesInfo; diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/init_rmw_context_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.hpp similarity index 84% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/init_rmw_context_impl.hpp rename to rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.hpp index 11cc71da4..bfa77c400 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/init_rmw_context_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/init_rmw_context_impl.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__INIT_RMW_CONTEXT_IMPL_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__INIT_RMW_CONTEXT_IMPL_HPP_ +#ifndef INIT_RMW_CONTEXT_IMPL_HPP_ +#define INIT_RMW_CONTEXT_IMPL_HPP_ #include "rmw/init.h" #include "rmw/types.h" @@ -30,4 +30,4 @@ increment_context_impl_ref_count(rmw_context_t * context); } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__INIT_RMW_CONTEXT_IMPL_HPP_ +#endif // INIT_RMW_CONTEXT_IMPL_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index 0135129e9..c1ef92651 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -44,8 +44,8 @@ #include "rmw_fastrtps_shared_cpp/utils.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/publisher.hpp" +#include "publisher.hpp" #include "type_support_common.hpp" #include "type_support_registry.hpp" diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/publisher.hpp b/rmw_fastrtps_dynamic_cpp/src/publisher.hpp similarity index 87% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/publisher.hpp rename to rmw_fastrtps_dynamic_cpp/src/publisher.hpp index ee9a8351a..0386d0e43 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/publisher.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__PUBLISHER_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__PUBLISHER_HPP_ +#ifndef PUBLISHER_HPP_ +#define PUBLISHER_HPP_ #include "rmw/rmw.h" #include "rmw_fastrtps_shared_cpp/custom_participant_info.hpp" @@ -31,4 +31,4 @@ create_publisher( } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__PUBLISHER_HPP_ +#endif // PUBLISHER_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp index af621b2dc..0a20b693d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp @@ -42,8 +42,9 @@ #include "rosidl_typesupport_cpp/message_type_support.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/publisher.hpp" -#include "rmw_fastrtps_dynamic_cpp/subscription.hpp" + +#include "publisher.hpp" +#include "subscription.hpp" extern "C" { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp index 70a8bb150..09810184d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp @@ -31,7 +31,8 @@ #include "rmw_fastrtps_shared_cpp/rmw_context_impl.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/init_rmw_context_impl.hpp" + +#include "init_rmw_context_impl.hpp" extern "C" { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp index c1d5dd38d..daedcada6 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp @@ -32,11 +32,11 @@ #include "rmw_fastrtps_shared_cpp/rmw_context_impl.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/publisher.hpp" #include "rmw_dds_common/context.hpp" #include "rmw_dds_common/msg/participant_entities_info.hpp" +#include "publisher.hpp" #include "type_support_common.hpp" #include "type_support_registry.hpp" diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp index e2885ffe6..ce40b70bd 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp @@ -31,8 +31,8 @@ #include "rmw_fastrtps_shared_cpp/subscription.hpp" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/subscription.hpp" +#include "subscription.hpp" #include "type_support_common.hpp" #include "type_support_registry.hpp" diff --git a/rmw_fastrtps_dynamic_cpp/src/serialization_helpers.hpp b/rmw_fastrtps_dynamic_cpp/src/serialization_helpers.hpp new file mode 100644 index 000000000..ba4d249fa --- /dev/null +++ b/rmw_fastrtps_dynamic_cpp/src/serialization_helpers.hpp @@ -0,0 +1,101 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SERIALIZATION_HELPERS_HPP_ +#define SERIALIZATION_HELPERS_HPP_ + +#include +#include + +#define SPECIALIZE_GENERIC_C_SEQUENCE(C_NAME, C_TYPE) \ + template<> \ + struct GenericCSequence \ + { \ + using type = rosidl_runtime_c__ ## C_NAME ## __Sequence; \ + \ + static void fini(type * array) { \ + rosidl_runtime_c__ ## C_NAME ## __Sequence__fini(array); \ + } \ + \ + static bool init(type * array, size_t size) { \ + return rosidl_runtime_c__ ## C_NAME ## __Sequence__init(array, size); \ + } \ + }; + +namespace eprosima +{ +namespace fastcdr +{ + +inline eprosima::fastcdr::Cdr & operator<<( + eprosima::fastcdr::Cdr & cdr, const std::u16string & u16str) +{ + auto ptr = u16str.c_str(); + auto len = static_cast(u16str.size()); + cdr << len; + for (; len > 0; --len) { + cdr << static_cast(*ptr++); + } + return cdr; +} + +inline eprosima::fastcdr::Cdr & operator<<( + eprosima::fastcdr::Cdr & cdr, const rosidl_runtime_c__U16String & u16str) +{ + auto ptr = u16str.data; + auto len = static_cast(u16str.size); + cdr << len; + for (; len > 0; --len) { + cdr << static_cast(*ptr++); + } + return cdr; +} + +inline eprosima::fastcdr::Cdr & operator>>( + eprosima::fastcdr::Cdr & cdr, std::u16string & u16str) +{ + uint32_t len; + cdr >> len; + u16str.resize(len); + for (uint32_t i = 0; i < len; ++i) { + uint32_t c; + cdr >> c; + u16str[i] = static_cast(c); + } + + return cdr; +} + +inline eprosima::fastcdr::Cdr & operator>>( + eprosima::fastcdr::Cdr & cdr, rosidl_runtime_c__U16String & u16str) +{ + uint32_t len; + cdr >> len; + if (!rosidl_runtime_c__U16String__resize(&u16str, len)) { + throw std::bad_alloc(); + } + + for (uint32_t i = 0; i < len; ++i) { + uint32_t c; + cdr >> c; + u16str.data[i] = static_cast(c); + } + + return cdr; +} + +} // namespace fastcdr +} // namespace eprosima + +#endif // SERIALIZATION_HELPERS_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index 1c8630e21..5a6869783 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -50,8 +50,8 @@ #include "fastrtps/xmlparser/XMLProfileManager.h" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" -#include "rmw_fastrtps_dynamic_cpp/subscription.hpp" +#include "subscription.hpp" #include "type_support_common.hpp" #include "type_support_registry.hpp" diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/subscription.hpp b/rmw_fastrtps_dynamic_cpp/src/subscription.hpp similarity index 87% rename from rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/subscription.hpp rename to rmw_fastrtps_dynamic_cpp/src/subscription.hpp index d274df03d..59f5f5401 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/subscription.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW_FASTRTPS_DYNAMIC_CPP__SUBSCRIPTION_HPP_ -#define RMW_FASTRTPS_DYNAMIC_CPP__SUBSCRIPTION_HPP_ +#ifndef SUBSCRIPTION_HPP_ +#define SUBSCRIPTION_HPP_ #include "rmw/rmw.h" #include "rmw/subscription_options.h" @@ -34,4 +34,4 @@ create_subscription( } // namespace rmw_fastrtps_dynamic_cpp -#endif // RMW_FASTRTPS_DYNAMIC_CPP__SUBSCRIPTION_HPP_ +#endif // SUBSCRIPTION_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp index d60206970..e139dcff6 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.cpp @@ -14,7 +14,7 @@ #include "rmw/error_handling.h" -#include "rmw_fastrtps_dynamic_cpp/TypeSupport.hpp" +#include "TypeSupport.hpp" #include "rosidl_typesupport_introspection_cpp/identifier.hpp" diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp index 1846b7ba5..3f5953714 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp @@ -24,8 +24,8 @@ #include "rmw_fastrtps_shared_cpp/TypeSupport.hpp" -#include "rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp" -#include "rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp" +#include "MessageTypeSupport.hpp" +#include "ServiceTypeSupport.hpp" #include "rosidl_typesupport_introspection_c/visibility_control.h" diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp index 43c3b0ac4..f4924c7a4 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "rmw_fastrtps_dynamic_cpp/TypeSupport.hpp" +#include "TypeSupport.hpp" namespace rmw_fastrtps_dynamic_cpp {