Skip to content

Commit

Permalink
Change serialize function default behaviour to omit the data represen…
Browse files Browse the repository at this point in the history
…tation (#4131)

* Refs #20134: Change serialize function default behaviour to omit the data representation

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Refs #20134: Separate header and sources files for TopicDataType

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Refs #20134: Add deprecation note

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Refs #20134: Uncrustify

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

---------

Signed-off-by: Raul Sanchez-Mateos <[email protected]>
  • Loading branch information
rsanchez15 authored Dec 18, 2023
1 parent 7157a19 commit 3625421
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 27 deletions.
34 changes: 7 additions & 27 deletions include/fastdds/dds/topic/TopicDataType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,12 @@ class TopicDataType
/**
* @brief Constructor
*/
RTPS_DllAPI TopicDataType()
: m_typeSize(0)
, m_isGetKeyDefined(false)
, auto_fill_type_object_(true)
, auto_fill_type_information_(true)
{
}
RTPS_DllAPI TopicDataType();

/**
* @brief Destructor
*/
RTPS_DllAPI virtual ~TopicDataType()
{
}
RTPS_DllAPI virtual ~TopicDataType();

/**
* Serialize method, it should be implemented by the user, since it is abstract.
Expand All @@ -89,12 +81,14 @@ class TopicDataType
* @param[out] payload Pointer to the payload
* @return True if correct.
*/
FASTDDS_TODO_BEFORE(3, 0, "Remove this overload")
RTPS_DllAPI virtual bool serialize(
void* data,
fastrtps::rtps::SerializedPayload_t* payload) = 0;

/**
* Serialize method, it should be implemented by the user, since it is abstract.
* Serialize method, it should be implemented by the user, since it is abstract. If not implemented, this method
* will call the serialize method in which the topic data representation is not considered.
* It is VERY IMPORTANT that the user sets the SerializedPayload length correctly.
*
* @param[in] data Pointer to the data
Expand All @@ -105,13 +99,7 @@ class TopicDataType
RTPS_DllAPI virtual bool serialize(
void* data,
fastrtps::rtps::SerializedPayload_t* payload,
DataRepresentationId_t data_representation)
{
static_cast<void>(data);
static_cast<void>(payload);
static_cast<void>(data_representation);
return false;
}
DataRepresentationId_t data_representation);

/**
* Deserialize method, it should be implemented by the user, since it is abstract.
Expand Down Expand Up @@ -142,15 +130,7 @@ class TopicDataType
*/
RTPS_DllAPI virtual std::function<uint32_t()> getSerializedSizeProvider(
void* data,
DataRepresentationId_t data_representation)
{
static_cast<void>(data);
static_cast<void>(data_representation);
return []()
{
return 0;
};
}
DataRepresentationId_t data_representation);

/**
* Create a Data Type.
Expand Down
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ set(${PROJECT_NAME}_source_files
fastdds/topic/TopicImpl.cpp
fastdds/topic/TopicProxyFactory.cpp
fastdds/topic/TypeSupport.cpp
fastdds/topic/TopicDataType.cpp
fastdds/topic/qos/TopicQos.cpp
fastdds/publisher/qos/DataWriterQos.cpp
fastdds/subscriber/qos/DataReaderQos.cpp
Expand Down
70 changes: 70 additions & 0 deletions src/cpp/fastdds/topic/TopicDataType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

/**
* @file TopicDataType.cpp
*/

#include <functional>
#include <memory>
#include <string>

#include <fastdds/rtps/common/CdrSerialization.hpp>
#include <fastdds/rtps/common/SerializedPayload.h>
#include <fastdds/dds/topic/TopicDataType.hpp>

#include <fastrtps/fastrtps_dll.h>
#include <fastrtps/utils/md5.h>

namespace eprosima {
namespace fastdds {
namespace dds {

TopicDataType::TopicDataType()
: m_typeSize(0)
, m_isGetKeyDefined(false)
, auto_fill_type_object_(true)
, auto_fill_type_information_(true)
{
}

TopicDataType::~TopicDataType()
{
}

bool TopicDataType::serialize(
void* data,
fastrtps::rtps::SerializedPayload_t* payload,
DataRepresentationId_t data_representation)
{

static_cast<void>(data_representation);
return serialize(data, payload);
}

std::function<uint32_t()> TopicDataType::getSerializedSizeProvider(
void* data,
DataRepresentationId_t data_representation)
{
static_cast<void>(data);
static_cast<void>(data_representation);
return []()
{
return 0;
};
}

} /* namespace dds */
} /* namespace fastdds */
} /* namespace eprosima */
1 change: 1 addition & 0 deletions test/unittest/dds/publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/dds/status/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/dds/subscriber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(DATAREADERHISTORYTESTS_SOURCE DataReaderHistoryTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/History.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/ReaderHistory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
)

if(WIN32)
Expand Down
1 change: 1 addition & 0 deletions test/unittest/dds/topic/DDSSQLFilter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ file(GLOB DDSSQLFILTER_SOURCES
file(GLOB DDSSQLFILTER_LIB_SOURCES
${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/*.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/*.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/dynamic_types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(DYNAMIC_TYPES_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(BUILTIN_DATA_SERIALIZATION_TESTS_SOURCE BuiltinDataSerializationTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp
Expand Down
2 changes: 2 additions & 0 deletions test/unittest/rtps/discovery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(EDPTESTS_SOURCE EdpTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
Expand Down Expand Up @@ -104,6 +105,7 @@ set(PDPTESTS_SOURCE PDPTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/participant/PDP.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ add_executable(ExternalLocatorsProcessorTests
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/statistics/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if (FASTDDS_STATISTICS)
${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/monitorservice_typesPubSubTypes.cxx
${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/monitorservice_types.cxx
${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/monitorservice_typesv1.cxx
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp
${TINYXML2_SOURCES}
Expand Down Expand Up @@ -171,6 +172,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX)
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
Expand Down Expand Up @@ -361,6 +363,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX)
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/statistics/rtps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(STATISTICS_RTPS_MONITORSERVICETESTS_SOURCE
MonitorServiceTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/xmlparser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ set(XMLPROFILEPARSER_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
Expand Down Expand Up @@ -208,6 +209,7 @@ set(XMLPARSER_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
Expand Down Expand Up @@ -339,6 +341,7 @@ set(XMLENDPOINTPARSERTESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/xtypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(XTYPES_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicDataType.cpp
)

set(XTYPES_TEST_SOURCE
Expand Down

0 comments on commit 3625421

Please sign in to comment.