| Fast DDS Version 3.3.0 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
18
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
43 namespace eprosima {
44 namespace fastdds {
45
46 namespace rtps {
47 struct SerializedPayload_t;
48 struct InstanceHandle_t;
49} // namespace rtps
50
51 namespace dds {
52
53 class TypeSupport;
54
60 class TopicDataType
61{
62 public:
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,
86 rtps::SerializedPayload_t& payload,
87 eprosima::fastdds::dds::DataRepresentationId_t data_representation) = 0;
88
96 FASTDDS_EXPORTED_API virtual bool deserialize(
97 rtps::SerializedPayload_t& payload,
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(
135 rtps::SerializedPayload_t& payload,
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(
206 DataRepresentationId_t) const
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
234 uint32_t max_serialized_type_size {0};
235
237 bool is_compute_key_provided {false};
238
239 protected:
240
241 xtypes::TypeIdentifierPair type_identifiers_;
242
243 private:
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
eprosima::fastdds::dds::TopicDataType::serialize
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.
eprosima::fastdds::dds::TopicDataType::construct_sample
virtual FASTDDS_EXPORTED_API bool construct_sample(void *memory) const
Construct a sample on a memory location.
Definition TopicDataType.hpp:218
eprosima::fastdds::dds::TopicDataType::type_identifiers
FASTDDS_EXPORTED_API const xtypes::TypeIdentifierPair & type_identifiers() const
Get the type identifiers.
Definition TopicDataType.hpp:189
eprosima::fastdds::dds::TopicDataType::set_name
FASTDDS_EXPORTED_API void set_name(std::string &&nam)
Set topic data type name.
Definition TopicDataType.hpp:168
eprosima::fastdds::dds::TopicDataType::register_type_object_representation
virtual FASTDDS_EXPORTED_API void register_type_object_representation()
Register TypeObject type representation.
Definition TopicDataType.hpp:228
eprosima::fastdds::dds::TopicDataType::delete_data
virtual FASTDDS_EXPORTED_API void delete_data(void *data)=0
Remove a previously created object.
eprosima::fastdds::dds::TopicDataType::~TopicDataType
virtual FASTDDS_EXPORTED_API ~TopicDataType()=default
Destructor.
eprosima::fastdds::dds::TopicDataType::get_name
FASTDDS_EXPORTED_API const std::string & get_name() const
Get topic data type name.
Definition TopicDataType.hpp:179
eprosima::fastdds::dds::TopicDataType::is_compute_key_provided
bool is_compute_key_provided
Indicates whether the method to obtain the key has been implemented.
Definition TopicDataType.hpp:237
eprosima::fastdds::dds::TopicDataType::max_serialized_type_size
uint32_t max_serialized_type_size
Maximum serialized size of the type in bytes.
Definition TopicDataType.hpp:234
eprosima::fastdds::dds::TopicDataType::TopicDataType
FASTDDS_EXPORTED_API TopicDataType()=default
Constructor.
eprosima::fastdds::dds::TopicDataType::calculate_serialized_size
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.
eprosima::fastdds::dds::TopicDataType::type_identifiers_
xtypes::TypeIdentifierPair type_identifiers_
Definition TopicDataType.hpp:241
eprosima::fastdds::dds::TopicDataType::is_plain
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
eprosima::fastdds::dds::TopicDataType::create_data
virtual FASTDDS_EXPORTED_API void * create_data()=0
Create a Data Type.
eprosima::fastdds::dds::TopicDataType::compute_key
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.
eprosima::fastdds::dds::TopicDataType::is_bounded
virtual FASTDDS_EXPORTED_API bool is_bounded() const
Checks if the type is bounded.
Definition TopicDataType.hpp:197
eprosima::fastdds::dds::TopicDataType::deserialize
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.
eprosima::fastdds::dds::TopicDataType::compute_key
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.
eprosima::fastdds::dds::TopicDataType::set_name
FASTDDS_EXPORTED_API void set_name(const std::string &nam)
Set topic data type name.
Definition TopicDataType.hpp:157
eprosima::fastdds::dds::TypeSupport
Class TypeSupport used to provide the DomainRTPSParticipant with the methods to serialize,...
Definition TypeSupport.hpp:47
eprosima::fastdds::dds::xtypes::TypeIdentifierPair
This class represents the structure TypeIdentifierPair defined by the user in the IDL file.
Definition dds_xtypes_typeobject.hpp:24033
eprosima::fastdds::dds
Definition BuiltinTopicKey.hpp:26
eprosima::fastdds::dds::DataRepresentationId_t
enum eprosima::fastdds::dds::DataRepresentationId DataRepresentationId_t
Enum DataRepresentationId, different kinds of topic data representation.
eprosima::fastdds::rtps
Contains the RTPS protocol implementation.
eprosima::fastdds
eprosima
eProsima namespace.
eprosima::fastdds::rtps::InstanceHandle_t
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition InstanceHandle.hpp:154
eprosima::fastdds::rtps::SerializedPayload_t
Structure SerializedPayload_t.
Definition SerializedPayload.hpp:59