Fast DDS  Version 3.1.2
Fast DDS
Loading...
Searching...
No Matches
TopicDataType.hpp
1// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19#ifndef FASTDDS_DDS_TOPIC__TOPICDATATYPE_HPP
20#define FASTDDS_DDS_TOPIC__TOPICDATATYPE_HPP
21
22#include <functional>
23#include <memory>
24#include <string>
25
26#include <fastdds/dds/core/policy/QosPolicies.hpp>
27#include <fastdds/dds/xtypes/type_representation/detail/dds_xtypes_typeobject.hpp>
28#include <fastdds/fastdds_dll.hpp>
29#include <fastdds/rtps/common/CdrSerialization.hpp>
30#include <fastdds/rtps/common/InstanceHandle.hpp>
31#include <fastdds/rtps/common/SerializedPayload.hpp>
32#include <fastdds/utils/md5.hpp>
33
34// This version of TypeSupport has `is_bounded()`
35#define TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
36
37// This version of TypeSupport has `is_plain()`
38#define TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
39
40// This version of TypeSupport has `construct_sample()`
41#define TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
42
43namespace eprosima {
44namespace fastdds {
45
46namespace rtps {
47struct SerializedPayload_t;
48struct InstanceHandle_t;
49} // namespace rtps
50
51namespace dds {
52
53class TypeSupport;
54
61{
62public:
63
67 FASTDDS_EXPORTED_API TopicDataType() = default;
68
72 FASTDDS_EXPORTED_API virtual ~TopicDataType() = default;
73
84 FASTDDS_EXPORTED_API virtual bool serialize(
85 const void* const data,
88
96 FASTDDS_EXPORTED_API virtual bool deserialize(
98 void* data) = 0;
99
107 FASTDDS_EXPORTED_API virtual uint32_t calculate_serialized_size(
108 const void* const data,
109 eprosima::fastdds::dds::DataRepresentationId_t data_representation) = 0;
110
116 FASTDDS_EXPORTED_API virtual void* create_data() = 0;
117
123 FASTDDS_EXPORTED_API virtual void delete_data(
124 void* data) = 0;
125
134 FASTDDS_EXPORTED_API virtual bool compute_key(
136 rtps::InstanceHandle_t& ihandle,
137 bool force_md5 = false) = 0;
138
147 FASTDDS_EXPORTED_API virtual bool compute_key(
148 const void* const data,
149 rtps::InstanceHandle_t& ihandle,
150 bool force_md5 = false) = 0;
151
157 FASTDDS_EXPORTED_API inline void set_name(
158 const std::string& nam)
159 {
160 topic_data_typename_ = nam;
161 }
162
168 FASTDDS_EXPORTED_API inline void set_name(
169 std::string&& nam)
170 {
171 topic_data_typename_ = std::move(nam);
172 }
173
179 FASTDDS_EXPORTED_API inline const std::string& get_name() const
180 {
181 return topic_data_typename_;
182 }
183
189 FASTDDS_EXPORTED_API inline const xtypes::TypeIdentifierPair& type_identifiers() const
190 {
191 return type_identifiers_;
192 }
193
197 FASTDDS_EXPORTED_API virtual inline bool is_bounded() const
198 {
199 return false;
200 }
201
205 FASTDDS_EXPORTED_API virtual inline bool is_plain(
207 {
208 return false;
209 }
210
218 FASTDDS_EXPORTED_API virtual inline bool construct_sample(
219 void* memory) const
220 {
221 static_cast<void>(memory);
222 return false;
223 }
224
228 FASTDDS_EXPORTED_API virtual inline void register_type_object_representation()
229 {
230 }
231
235
238
239protected:
240
242
243private:
244
246 std::string topic_data_typename_;
247
248};
249
250} // namespace dds
251} // namespace fastdds
252} // namespace eprosima
253
254#endif // FASTDDS_DDS_TOPIC__TOPICDATATYPE_HPP
Class TopicDataType used to provide the DomainRTPSParticipant with the methods to serialize,...
Definition TopicDataType.hpp:61
virtual FASTDDS_EXPORTED_API bool serialize(const void *const data, rtps::SerializedPayload_t &payload, eprosima::fastdds::dds::DataRepresentationId_t data_representation)=0
Serialize method, it should be implemented by the user, since it is abstract.
virtual FASTDDS_EXPORTED_API bool construct_sample(void *memory) const
Construct a sample on a memory location.
Definition TopicDataType.hpp:218
FASTDDS_EXPORTED_API const xtypes::TypeIdentifierPair & type_identifiers() const
Get the type identifiers.
Definition TopicDataType.hpp:189
FASTDDS_EXPORTED_API void set_name(std::string &&nam)
Set topic data type name.
Definition TopicDataType.hpp:168
virtual FASTDDS_EXPORTED_API void register_type_object_representation()
Register TypeObject type representation.
Definition TopicDataType.hpp:228
virtual FASTDDS_EXPORTED_API void delete_data(void *data)=0
Remove a previously created object.
virtual FASTDDS_EXPORTED_API ~TopicDataType()=default
Destructor.
FASTDDS_EXPORTED_API const std::string & get_name() const
Get topic data type name.
Definition TopicDataType.hpp:179
bool is_compute_key_provided
Indicates whether the method to obtain the key has been implemented.
Definition TopicDataType.hpp:237
uint32_t max_serialized_type_size
Maximum serialized size of the type in bytes.
Definition TopicDataType.hpp:234
FASTDDS_EXPORTED_API TopicDataType()=default
Constructor.
virtual FASTDDS_EXPORTED_API uint32_t calculate_serialized_size(const void *const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation)=0
Calculates the serialized size of the provided data.
xtypes::TypeIdentifierPair type_identifiers_
Definition TopicDataType.hpp:241
virtual FASTDDS_EXPORTED_API bool is_plain(DataRepresentationId_t) const
Checks if the type is plain when using a specific encoding.
Definition TopicDataType.hpp:205
virtual FASTDDS_EXPORTED_API void * create_data()=0
Create a Data Type.
virtual FASTDDS_EXPORTED_API bool compute_key(rtps::SerializedPayload_t &payload, rtps::InstanceHandle_t &ihandle, bool force_md5=false)=0
Get the key associated with the data.
virtual FASTDDS_EXPORTED_API bool is_bounded() const
Checks if the type is bounded.
Definition TopicDataType.hpp:197
virtual FASTDDS_EXPORTED_API bool deserialize(rtps::SerializedPayload_t &payload, void *data)=0
Deserialize method, it should be implemented by the user, since it is abstract.
virtual FASTDDS_EXPORTED_API bool compute_key(const void *const data, rtps::InstanceHandle_t &ihandle, bool force_md5=false)=0
Get the key associated with the data.
FASTDDS_EXPORTED_API void set_name(const std::string &nam)
Set topic data type name.
Definition TopicDataType.hpp:157
This class represents the structure TypeIdentifierPair defined by the user in the IDL file.
Definition dds_xtypes_typeobject.hpp:24033
Definition DomainParticipant.hpp:45
eprosima::fastdds::rtps::InstanceHandle_t InstanceHandle_t
Definition InstanceHandle.hpp:31
enum eprosima::fastdds::dds::DataRepresentationId DataRepresentationId_t
Enum DataRepresentationId, different kinds of topic data representation.
eProsima namespace.
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition InstanceHandle.hpp:154
Structure SerializedPayload_t.
Definition SerializedPayload.hpp:59