diff --git a/iceoryx2-ffi/cxx/include/iox2/payload_info.hpp b/iceoryx2-ffi/cxx/include/iox2/payload_info.hpp new file mode 100644 index 00000000..30f2634b --- /dev/null +++ b/iceoryx2-ffi/cxx/include/iox2/payload_info.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#ifndef IOX2_PAYLOAD_INFO_HPP +#define IOX2_PAYLOAD_INFO_HPP + +#include "iox/slice.hpp" + +namespace iox2 { + +template +struct PayloadInfo { + using TYPE = T; +}; + +template +struct PayloadInfo> { + using TYPE = typename iox::Slice::ValueType; +}; + +} // namespace iox2 +#endif diff --git a/iceoryx2-ffi/cxx/include/iox2/port_factory_publisher.hpp b/iceoryx2-ffi/cxx/include/iox2/port_factory_publisher.hpp index 164f5a7e..47487992 100644 --- a/iceoryx2-ffi/cxx/include/iox2/port_factory_publisher.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/port_factory_publisher.hpp @@ -17,6 +17,7 @@ #include "iox/builder_addendum.hpp" #include "iox/expected.hpp" #include "iox2/internal/iceoryx2.hpp" +#include "iox2/payload_info.hpp" #include "iox2/publisher.hpp" #include "iox2/service_type.hpp" #include "iox2/unable_to_deliver_strategy.hpp" @@ -76,20 +77,13 @@ PortFactoryPublisher::create() && -> iox::expected::VALUE) { - iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, - value * sizeof(typename Payload::ValueType)); - } else { - iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, value * sizeof(Payload)); - } + iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, + value * sizeof(typename PayloadInfo::TYPE)); }) .or_else([&]() { // Assume only one element if not otherwise specified - if constexpr (iox::IsSlice::VALUE) { - iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, sizeof(typename Payload::ValueType)); - } else { - iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, sizeof(Payload)); - } + iox2_port_factory_publisher_builder_set_max_slice_len(&m_handle, + sizeof(typename PayloadInfo::TYPE)); }); m_max_loaned_samples.and_then( [&](auto value) { iox2_port_factory_publisher_builder_set_max_loaned_samples(&m_handle, value); }); diff --git a/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe.hpp b/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe.hpp index 4cf9a70b..757252a4 100644 --- a/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe.hpp @@ -19,6 +19,7 @@ #include "iox2/attribute_specifier.hpp" #include "iox2/attribute_verifier.hpp" #include "iox2/internal/iceoryx2.hpp" +#include "iox2/payload_info.hpp" #include "iox2/port_factory_publish_subscribe.hpp" #include "iox2/service_builder_publish_subscribe_error.hpp" #include "iox2/service_type.hpp" @@ -27,16 +28,6 @@ namespace iox2 { -template -struct PayloadValueType { - using TYPE = T; -}; - -template -struct PayloadValueType> { - using TYPE = typename iox::Slice::ValueType; -}; - /// Builder to create new [`MessagingPattern::PublishSubscribe`] based [`Service`]s template class ServiceBuilderPublishSubscribe { @@ -149,7 +140,7 @@ inline void ServiceBuilderPublishSubscribe::set_paramete [&](auto value) { iox2_service_builder_pub_sub_set_payload_alignment(&m_handle, value); }); m_max_nodes.and_then([&](auto value) { iox2_service_builder_pub_sub_set_max_nodes(&m_handle, value); }); - using ValueType = typename PayloadValueType::TYPE; + using ValueType = typename PayloadInfo::TYPE; auto type_variant = iox::IsSlice::VALUE ? iox2_type_variant_e_DYNAMIC : iox2_type_variant_e_FIXED_SIZE; // payload type details