From 5b699449462f1dcfe9401a9d0ee2090d3bc6e443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Wed, 15 Nov 2023 15:28:25 +0100 Subject: [PATCH] Fix warning with Fast CDR v1 (#260) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- .../idl/templates/DDSPubSubTypeSource.stg | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg index dfece16b..21d39d0a 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg @@ -95,7 +95,7 @@ $struct.name$PubSubType::$struct.name$PubSubType() $if(ctx.GenerateTypesROS2)$setName("$struct.ROS2Scopedname$");$else$setName("$struct.scopedname$");$endif$ uint32_t type_size = #if FASTCDR_VERSION_MAJOR == 1 - $struct.name$::getMaxCdrSerializedSize(); + static_cast($struct.name$::getMaxCdrSerializedSize()); #else $struct.cScopedname$_max_cdr_typesize; #endif @@ -198,23 +198,24 @@ std::function $struct.name$PubSubType::getSerializedSizeProvider( return [data, data_representation]() -> uint32_t { #if FASTCDR_VERSION_MAJOR == 1 - return static_cast(type::getCdrSerializedSize(*static_cast<$struct.name$*>(data))) + + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast<$struct.name$*>(data))) + 4u /*encapsulation*/; #else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast<$struct.name$*>(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast<$struct.name$*>(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } #endif // FASTCDR_VERSION_MAJOR == 1 }; }