Skip to content

Commit

Permalink
FastCDR version bump (#141)
Browse files Browse the repository at this point in the history
* update fastcdr types and function names

* Get rid of warning when building on newer g++.

It warns that these are unnecessary std::move.

Signed-off-by: Chris Lalancette <[email protected]>

* Add in a class to paper over fastcdr v1 to v2 differences.

Signed-off-by: Chris Lalancette <[email protected]>

---------

Signed-off-by: Chris Lalancette <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
Co-authored-by: Yadunund <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent 87f20f8 commit 58404f7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 46 deletions.
1 change: 1 addition & 0 deletions rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions rmw_zenoh_cpp/src/detail/cdr.cpp
Original file line number Diff line number Diff line change
@@ -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_;
}
39 changes: 39 additions & 0 deletions rmw_zenoh_cpp/src/detail/cdr.hpp
Original file line number Diff line number Diff line change
@@ -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_
4 changes: 2 additions & 2 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ std::shared_ptr<Entity> Entity::make(
return std::make_shared<Entity>(
Entity{
zid_to_str(zid),
std::move(nid),
std::move(id),
nid,
id,
std::move(type),
std::move(node_info),
std::move(topic_info)});
Expand Down
67 changes: 23 additions & 44 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>

#include <zenoh.h>

Expand All @@ -29,6 +28,7 @@
#include <utility>

#include "detail/attachment_helpers.hpp"
#include "detail/cdr.hpp"
#include "detail/guard_condition.hpp"
#include "detail/graph_cache.hpp"
#include "detail/identifier.hpp"
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -1056,9 +1053,8 @@ rmw_publish_serialized_message(

eprosima::fastcdr::FastBuffer buffer(
reinterpret_cast<char *>(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;
}
Expand All @@ -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
Expand Down Expand Up @@ -1161,10 +1157,9 @@ rmw_serialize(

eprosima::fastcdr::FastBuffer buffer(
reinterpret_cast<char *>(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;
Expand All @@ -1188,10 +1183,9 @@ rmw_deserialize(
auto tss = MessageTypeSupport(callbacks);
eprosima::fastcdr::FastBuffer buffer(
reinterpret_cast<char *>(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;
}

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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<ZenohQuery> query =
Expand Down

0 comments on commit 58404f7

Please sign in to comment.