-
Notifications
You must be signed in to change notification settings - Fork 800
/
Copy pathTopicDataType.h
112 lines (93 loc) · 3.84 KB
/
TopicDataType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2016 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.h
*/
#ifndef TOPICDATATYPE_H_
#define TOPICDATATYPE_H_
#include "rtps/common/Types.h"
#include "rtps/common/SerializedPayload.h"
#include "rtps/common/InstanceHandle.h"
#include "utils/md5.h"
#include <string>
#include <functional>
namespace eprosima {
namespace fastrtps {
/**
* Class TopicDataType used to provide the DomainRTPSParticipant with the methods to serialize, deserialize and get the key of a specific data type.
* The user should created a class that inherits from this one, where Serialize and deserialize methods MUST be implemented.
* @ingroup FASTRTPS_MODULE
* @snippet fastrtps_example.cpp ex_TopicDataType
*/
class TopicDataType {
public:
RTPS_DllAPI TopicDataType()
: m_typeSize(0), m_isGetKeyDefined(false)
{}
RTPS_DllAPI virtual ~TopicDataType(){};
/**
* Serialize method, it should be implemented by the user, since it is abstract.
* It is VERY IMPORTANT that the user sets the serializedPaylaod length correctly.
* @param[in] data Pointer to the data
* @param[out] payload Pointer to the payload
* @return True if correct.
*/
RTPS_DllAPI virtual bool serialize(void* data, rtps::SerializedPayload_t* payload) = 0;
/**
* Deserialize method, it should be implemented by the user, since it is abstract.
* @param[in] payload Pointer to the payload
* @param[out] data Pointer to the data
* @return True if correct.
*/
RTPS_DllAPI virtual bool deserialize(rtps::SerializedPayload_t* payload, void* data) = 0;
RTPS_DllAPI virtual std::function<uint32_t()> getSerializedSizeProvider(void* data) = 0;
/**
* Create a Data Type.
* @return Void pointer to the created object.
*/
RTPS_DllAPI virtual void * createData() = 0;
/**
* Remove a previously created object.
* @param data Pointer to the created Data.
*/
RTPS_DllAPI virtual void deleteData(void * data) = 0;
/**
* Get the key associated with the data.
* @param[in] data Pointer to the data.
* @param[out] ihandle Pointer to the Handle.
* @return True if correct.
*/
RTPS_DllAPI virtual bool getKey(void* data, rtps::InstanceHandle_t* ihandle){ (void) data; (void) ihandle; return false; }
/**
* Set topic data type name
* @param nam Topic data type name
*/
RTPS_DllAPI inline void setName(const char* nam) { m_topicDataTypeName = std::string(nam); }
/**
* Get topic data type name
* @return Topic data type name
*/
RTPS_DllAPI inline const char* getName() const { return m_topicDataTypeName.c_str(); }
//! Maximum serialized size of the type in bytes.
//! If the type has unbounded fields, and therefore cannot have a maximum size, use 0.
uint32_t m_typeSize;
//! Indicates whether the method to obtain the key has been implemented.
bool m_isGetKeyDefined;
private:
//! Data Type Name.
std::string m_topicDataTypeName;
};
} /* namespace pubsub */
} /* namespace eprosima */
#endif /* RTPSTOPICDATATYPE_H_ */