diff --git a/rmw_zenoh_cpp/CMakeLists.txt b/rmw_zenoh_cpp/CMakeLists.txt index 809f0624..1785a4cd 100644 --- a/rmw_zenoh_cpp/CMakeLists.txt +++ b/rmw_zenoh_cpp/CMakeLists.txt @@ -27,6 +27,7 @@ find_package(zenohc REQUIRED) add_library(rmw_zenoh_cpp SHARED src/detail/attachment_helpers.cpp + src/detail/cdr.cpp src/detail/event.cpp src/detail/identifier.cpp src/detail/graph_cache.cpp diff --git a/rmw_zenoh_cpp/src/detail/cdr.cpp b/rmw_zenoh_cpp/src/detail/cdr.cpp new file mode 100644 index 00000000..0d8ec267 --- /dev/null +++ b/rmw_zenoh_cpp/src/detail/cdr.cpp @@ -0,0 +1,42 @@ +// Copyright 2024 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. + +#include "fastcdr/Cdr.h" +#include "fastcdr/FastBuffer.h" +#include "fastcdr/config.h" + +#include "cdr.hpp" + +rmw_zenoh_cpp::Cdr::Cdr(eprosima::fastcdr::FastBuffer & fastbuffer) +#if FASTCDR_VERSION_MAJOR == 1 +: cdr_(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR) +#else +: cdr_(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::CdrVersion::DDS_CDR) +#endif +{ +} + +size_t rmw_zenoh_cpp::Cdr::get_serialized_data_length() const +{ +#if FASTCDR_VERSION_MAJOR == 1 + return cdr_.getSerializedDataLength(); +#else + return cdr_.get_serialized_data_length(); +#endif +} + +eprosima::fastcdr::Cdr & rmw_zenoh_cpp::Cdr::get_cdr() +{ + return cdr_; +} diff --git a/rmw_zenoh_cpp/src/detail/cdr.hpp b/rmw_zenoh_cpp/src/detail/cdr.hpp new file mode 100644 index 00000000..22ac942d --- /dev/null +++ b/rmw_zenoh_cpp/src/detail/cdr.hpp @@ -0,0 +1,39 @@ +// Copyright 2024 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 DETAIL__CDR_HPP_ +#define DETAIL__CDR_HPP_ + +#include "fastcdr/Cdr.h" +#include "fastcdr/FastBuffer.h" + +// A wrapper class to paper over the differences between Fast-CDR v1 and Fast-CDR v2 +namespace rmw_zenoh_cpp +{ +class Cdr final +{ +public: + explicit Cdr(eprosima::fastcdr::FastBuffer & fastbuffer); + + eprosima::fastcdr::Cdr & get_cdr(); + + size_t get_serialized_data_length() const; + +private: + eprosima::fastcdr::Cdr cdr_; +}; + +} // namespace rmw_zenoh_cpp + +#endif // DETAIL__CDR_HPP_ diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 1bb4464c..a4b1e5ce 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -319,8 +319,8 @@ std::shared_ptr Entity::make( return std::make_shared( Entity{ zid_to_str(zid), - std::move(nid), - std::move(id), + nid, + id, std::move(type), std::move(node_info), std::move(topic_info)}); diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 08c90b87..9b81ff21 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include @@ -29,6 +28,7 @@ #include #include "detail/attachment_helpers.hpp" +#include "detail/cdr.hpp" #include "detail/guard_condition.hpp" #include "detail/graph_cache.hpp" #include "detail/identifier.hpp" @@ -912,20 +912,17 @@ rmw_publish( eprosima::fastcdr::FastBuffer fastbuffer(msg_bytes, max_data_length); // Object that serializes the data - eprosima::fastcdr::Cdr ser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr ser(fastbuffer); if (!publisher_data->type_support->serialize_ros_message( ros_message, - ser, + ser.get_cdr(), publisher_data->type_support_impl)) { RMW_SET_ERROR_MSG("could not serialize ROS message"); return RMW_RET_ERROR; } - const size_t data_length = ser.getSerializedDataLength(); + const size_t data_length = ser.get_serialized_data_length(); int64_t sequence_number = publisher_data->get_next_sequence_number(); @@ -1056,9 +1053,8 @@ rmw_publish_serialized_message( eprosima::fastcdr::FastBuffer buffer( reinterpret_cast(serialized_message->buffer), serialized_message->buffer_length); - eprosima::fastcdr::Cdr ser( - buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); - if (!ser.jump(serialized_message->buffer_length)) { + rmw_zenoh_cpp::Cdr ser(buffer); + if (!ser.get_cdr().jump(serialized_message->buffer_length)) { RMW_SET_ERROR_MSG("cannot correctly set serialized buffer"); return RMW_RET_ERROR; } @@ -1077,7 +1073,7 @@ rmw_publish_serialized_message( z_bytes_map_drop(z_move(map)); }); - const size_t data_length = ser.getSerializedDataLength(); + const size_t data_length = ser.get_serialized_data_length(); // The encoding is simply forwarded and is useful when key expressions in the // session use different encoding formats. In our case, all key expressions @@ -1161,10 +1157,9 @@ rmw_serialize( eprosima::fastcdr::FastBuffer buffer( reinterpret_cast(serialized_message->buffer), data_length); - eprosima::fastcdr::Cdr ser( - buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr ser(buffer); - auto ret = tss.serialize_ros_message(ros_message, ser, callbacks); + auto ret = tss.serialize_ros_message(ros_message, ser.get_cdr(), callbacks); serialized_message->buffer_length = data_length; serialized_message->buffer_capacity = data_length; return ret == true ? RMW_RET_OK : RMW_RET_ERROR; @@ -1188,10 +1183,9 @@ rmw_deserialize( auto tss = MessageTypeSupport(callbacks); eprosima::fastcdr::FastBuffer buffer( reinterpret_cast(serialized_message->buffer), serialized_message->buffer_length); - eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr deser(buffer); - auto ret = tss.deserialize_ros_message(deser, ros_message, callbacks); + auto ret = tss.deserialize_ros_message(deser.get_cdr(), ros_message, callbacks); return ret == true ? RMW_RET_OK : RMW_RET_ERROR; } @@ -1662,12 +1656,9 @@ static rmw_ret_t __rmw_take( msg_data->payload.payload.len); // Object that serializes the data - eprosima::fastcdr::Cdr deser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr deser(fastbuffer); if (!sub_data->type_support->deserialize_ros_message( - deser, + deser.get_cdr(), ros_message, sub_data->type_support_impl)) { @@ -2243,19 +2234,16 @@ rmw_send_request( eprosima::fastcdr::FastBuffer fastbuffer(request_bytes, max_data_length); // Object that serializes the data - eprosima::fastcdr::Cdr ser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr ser(fastbuffer); if (!client_data->request_type_support->serialize_ros_message( ros_request, - ser, + ser.get_cdr(), client_data->request_type_support_impl)) { return RMW_RET_ERROR; } - size_t data_length = ser.getSerializedDataLength(); + size_t data_length = ser.get_serialized_data_length(); *sequence_id = client_data->get_next_sequence_number(); @@ -2339,12 +2327,9 @@ rmw_take_response( sample->payload.len); // Object that serializes the data - eprosima::fastcdr::Cdr deser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr deser(fastbuffer); if (!client_data->response_type_support->deserialize_ros_message( - deser, + deser.get_cdr(), ros_response, client_data->response_type_support_impl)) { @@ -2788,12 +2773,9 @@ rmw_take_request( payload_value.payload.len); // Object that serializes the data - eprosima::fastcdr::Cdr deser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr deser(fastbuffer); if (!service_data->request_type_support->deserialize_ros_message( - deser, + deser.get_cdr(), ros_request, service_data->request_type_support_impl)) { @@ -2890,19 +2872,16 @@ rmw_send_response( eprosima::fastcdr::FastBuffer fastbuffer(response_bytes, max_data_length); // Object that serializes the data - eprosima::fastcdr::Cdr ser( - fastbuffer, - eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::Cdr::DDS_CDR); + rmw_zenoh_cpp::Cdr ser(fastbuffer); if (!service_data->response_type_support->serialize_ros_message( ros_response, - ser, + ser.get_cdr(), service_data->response_type_support_impl)) { return RMW_RET_ERROR; } - size_t data_length = ser.getSerializedDataLength(); + size_t data_length = ser.get_serialized_data_length(); // Create the queryable payload std::unique_ptr query =