Fast DDS  Version 3.6.1.0
Fast DDS
DynamicPubSubType.hpp
1 // Copyright 2023 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 
15 #ifndef FASTDDS_DDS_XTYPES_DYNAMIC_TYPES__DYNAMICPUBSUBTYPE_HPP
16 #define FASTDDS_DDS_XTYPES_DYNAMIC_TYPES__DYNAMICPUBSUBTYPE_HPP
17 
18 #include <fastdds/dds/core/ReturnCode.hpp>
19 #include <fastdds/dds/topic/TopicDataType.hpp>
20 #include <fastdds/dds/xtypes/dynamic_types/Types.hpp>
21 #include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
22 #include <fastdds/rtps/common/InstanceHandle.hpp>
23 #include <fastdds/rtps/common/SerializedPayload.hpp>
24 #include <fastdds/utils/md5.hpp>
25 
26 namespace eprosima {
27 namespace fastdds {
28 namespace dds {
29 
30 class DynamicType;
31 class DynamicData;
32 
34 {
35  traits<DynamicType>::ref_type dynamic_type_;
36 
37  unsigned char* key_buffer_ {nullptr};
38 
39  MD5 md5_;
40 
41 public:
42 
43  //{{{ Public functions
44 
45  FASTDDS_EXPORTED_API DynamicPubSubType() = default;
46 
54  FASTDDS_EXPORTED_API DynamicPubSubType(
56 
73  FASTDDS_EXPORTED_API DynamicPubSubType(
75  const xtypes::TypeInformation& type_information);
76 
77  FASTDDS_EXPORTED_API virtual ~DynamicPubSubType();
78 
86  FASTDDS_EXPORTED_API void* create_data() override;
87 
95  FASTDDS_EXPORTED_API void delete_data(
96  void* data) override;
97 
106  FASTDDS_EXPORTED_API bool deserialize(
108  void* data) override;
109 
115  FASTDDS_EXPORTED_API traits<DynamicType>::ref_type get_dynamic_type() const noexcept;
116 
126  FASTDDS_EXPORTED_API bool compute_key(
127  eprosima::fastdds::rtps::SerializedPayload_t& payload,
128  eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
129  bool force_md5 = false) override;
130 
140  FASTDDS_EXPORTED_API bool compute_key(
141  const void* const data,
142  eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
143  bool force_md5 = false) override;
144 
153  FASTDDS_EXPORTED_API uint32_t calculate_serialized_size(
154  const void* const data,
155  DataRepresentationId_t data_representation) override;
156 
166  FASTDDS_EXPORTED_API bool serialize(
167  const void* const data,
168  eprosima::fastdds::rtps::SerializedPayload_t& payload,
169  fastdds::dds::DataRepresentationId_t data_representation) override;
170 
180  FASTDDS_EXPORTED_API ReturnCode_t set_dynamic_type(
181  traits<DynamicType>::ref_type type);
182 
184  FASTDDS_EXPORTED_API void register_type_object_representation() override;
185 
186  //}}}
187 
188 private:
189 
190  void update_dynamic_type();
191 };
192 
193 } // namespace dds
194 } // namespace fastdds
195 } // namespace eprosima
196 
197 #endif // FASTDDS_DDS_XTYPES_DYNAMIC_TYPES__DYNAMICPUBSUBTYPE_HPP
Class MD5, for calculating MD5 hashes of strings or byte arrays it is not meant to be fast or secure.
Definition: md5.hpp:63
Definition: DynamicPubSubType.hpp:34
FASTDDS_EXPORTED_API bool deserialize(eprosima::fastdds::rtps::SerializedPayload_t &payload, void *data) override
Deserialize an object from the given payload.
FASTDDS_EXPORTED_API DynamicPubSubType(traits< DynamicType >::ref_type type, const xtypes::TypeInformation &type_information)
Constructs a DynamicPubSubType from a DynamicType and a xtypes::TypeInformation.
FASTDDS_EXPORTED_API traits< DynamicType >::ref_type get_dynamic_type() const noexcept
Returns a copy of the internal DynamicType object.
virtual FASTDDS_EXPORTED_API ~DynamicPubSubType()
FASTDDS_EXPORTED_API bool serialize(const void *const data, eprosima::fastdds::rtps::SerializedPayload_t &payload, fastdds::dds::DataRepresentationId_t data_representation) override
Serialize an object into a given payload.
FASTDDS_EXPORTED_API bool compute_key(eprosima::fastdds::rtps::SerializedPayload_t &payload, eprosima::fastdds::rtps::InstanceHandle_t &ihandle, bool force_md5=false) override
Calculate the key associated to a given object.
FASTDDS_EXPORTED_API void register_type_object_representation() override
Register TypeObject representation in Fast DDS TypeObjectRegistry.
FASTDDS_EXPORTED_API void delete_data(void *data) override
Deletes an object previously allocated via create_data.
FASTDDS_EXPORTED_API ReturnCode_t set_dynamic_type(traits< DynamicType >::ref_type type)
Sets up the internal DynamicType object.
FASTDDS_EXPORTED_API uint32_t calculate_serialized_size(const void *const data, DataRepresentationId_t data_representation) override
Provide a functor that calculates a specified object serialized size.
FASTDDS_EXPORTED_API DynamicPubSubType()=default
FASTDDS_EXPORTED_API DynamicPubSubType(traits< DynamicType >::ref_type type)
Constructs a DynamicPubSubType from a DynamicType.
FASTDDS_EXPORTED_API void * create_data() override
Create a new data object of the specified type.
Definition: DynamicType.hpp:33
Class TopicDataType used to provide the DomainRTPSParticipant with the methods to serialize,...
Definition: TopicDataType.hpp:61
This class represents the structure TypeInformation defined by the user in the IDL file.
Definition: dds_xtypes_typeobject.hpp:24606
Definition: DomainParticipant.hpp:46
enum eprosima::fastdds::dds::DataRepresentationId DataRepresentationId_t
Enum DataRepresentationId, different kinds of topic data representation.
int32_t ReturnCode_t
Definition: DDSReturnCode.hpp:59
Definition: type_traits.hpp:28
typename ::std::shared_ptr< T > ref_type
Definition: type_traits.hpp:29
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition: InstanceHandle.hpp:154
Structure SerializedPayload_t.
Definition: SerializedPayload.hpp:59