diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h index 047b9598c..5a8fb5627 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h @@ -784,6 +784,9 @@ size_t TypeSupport::calculateMaxSerializedSize( size_t initial_alignment = current_alignment; + // Encapsulation + current_alignment += 4; + for (uint32_t i = 0; i < members->member_count_; ++i) { const auto * member = members->members_ + i; @@ -891,6 +894,9 @@ bool TypeSupport::serializeROSmessage( { assert(ros_message); + // Serialize encapsulation + ser.serialize_encapsulation(); + if (members_->member_count_ != 0) { TypeSupport::serializeROSmessage(ser, members_, ros_message); } else { @@ -907,7 +913,11 @@ bool TypeSupport::deserializeROSmessage( assert(buffer); assert(ros_message); - eprosima::fastcdr::Cdr deser(*buffer); + eprosima::fastcdr::Cdr deser(*buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); if (members_->member_count_ != 0) { TypeSupport::deserializeROSmessage(deser, members_, ros_message, false); @@ -936,7 +946,8 @@ bool TypeSupport::serialize( eprosima::fastcdr::Cdr * ser = static_cast(data); if (payload->max_size >= ser->getSerializedDataLength()) { payload->length = static_cast(ser->getSerializedDataLength()); - payload->encapsulation = CDR_LE; + payload->encapsulation = ser->endianness() == + eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; memcpy(payload->data, ser->getBufferPointer(), ser->getSerializedDataLength()); return true; } diff --git a/rmw_fastrtps_cpp/src/functions.cpp b/rmw_fastrtps_cpp/src/functions.cpp index 0ee6b98d7..f9f8c2a2e 100644 --- a/rmw_fastrtps_cpp/src/functions.cpp +++ b/rmw_fastrtps_cpp/src/functions.cpp @@ -948,7 +948,8 @@ rmw_ret_t rmw_publish(const rmw_publisher_t * publisher, const void * ros_messag assert(info); eprosima::fastcdr::FastBuffer buffer; - eprosima::fastcdr::Cdr ser(buffer); + eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); if (_serialize_ros_message(ros_message, ser, info->type_support_, info->typesupport_identifier_)) @@ -1699,7 +1700,8 @@ rmw_ret_t rmw_send_request(const rmw_client_t * client, assert(info); eprosima::fastcdr::FastBuffer buffer; - eprosima::fastcdr::Cdr ser(buffer); + eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); if (_serialize_ros_message(ros_request, ser, info->request_type_support_, info->typesupport_identifier_)) @@ -1816,7 +1818,8 @@ rmw_ret_t rmw_send_response(const rmw_service_t * service, assert(info); eprosima::fastcdr::FastBuffer buffer; - eprosima::fastcdr::Cdr ser(buffer); + eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); _serialize_ros_message(ros_response, ser, info->response_type_support_, info->typesupport_identifier_);