CARLA
 
载入中...
搜索中...
未找到
TFMessagePubSubTypes.cpp
浏览该文件的文档.
1// Copyright 2016 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/*!
16 * @file TFMessagePubSubTypes.cpp
17 * This header file contains the implementation of the serialization functions.
18 *
19 * This file was generated by the tool fastcdrgen.
20 */
21
22#include <fastcdr/FastBuffer.h>
23#include <fastcdr/Cdr.h>
24
26
27using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t;
28using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t;
29
30namespace tf2_msgs {
31 namespace msg {
33 {
34 setName("tf2_msgs::msg::dds_::TFMessage_");
35 auto type_size = TFMessage::getMaxCdrSerializedSize();
36 type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */
37 m_typeSize = static_cast<uint32_t>(type_size) + 4; /*encapsulation*/
38 m_isGetKeyDefined = TFMessage::isKeyDefined();
39 size_t keyLength = TFMessage::getKeyMaxCdrSerializedSize() > 16 ?
41 m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength));
42 memset(m_keyBuffer, 0, keyLength);
43 }
44
46 {
47 if (m_keyBuffer != nullptr)
48 {
49 free(m_keyBuffer);
50 }
51 }
52
54 void* data,
55 SerializedPayload_t* payload)
56 {
57 TFMessage* p_type = static_cast<TFMessage*>(data);
58
59 // Object that manages the raw buffer.
60 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size);
61 // Object that serializes the data.
62 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
63 payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
64 // Serialize encapsulation
65 ser.serialize_encapsulation();
66
67 try
68 {
69 // Serialize the object.
70 p_type->serialize(ser);
71 }
72 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
73 {
74 return false;
75 }
76
77 // Get the serialized length
78 payload->length = static_cast<uint32_t>(ser.getSerializedDataLength());
79 return true;
80 }
81
83 SerializedPayload_t* payload,
84 void* data)
85 {
86 try
87 {
88 //Convert DATA to pointer of your type
89 TFMessage* p_type = static_cast<TFMessage*>(data);
90
91 // Object that manages the raw buffer.
92 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length);
93
94 // Object that deserializes the data.
95 eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
96
97 // Deserialize encapsulation.
98 deser.read_encapsulation();
99 payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
100
101 // Deserialize the object.
102 p_type->deserialize(deser);
103 }
104 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
105 {
106 return false;
107 }
108
109 return true;
110 }
111
113 void* data)
114 {
115 return [data]() -> uint32_t
116 {
117 return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<TFMessage*>(data))) +
118 4u /*encapsulation*/;
119 };
120 }
121
123 {
124 return reinterpret_cast<void*>(new TFMessage());
125 }
126
128 void* data)
129 {
130 delete(reinterpret_cast<TFMessage*>(data));
131 }
132
134 void* data,
135 InstanceHandle_t* handle,
136 bool force_md5)
137 {
138 if (!m_isGetKeyDefined)
139 {
140 return false;
141 }
142
143 TFMessage* p_type = static_cast<TFMessage*>(data);
144
145 // Object that manages the raw buffer.
146 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
148
149 // Object that serializes the data.
150 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS);
151 p_type->serializeKey(ser);
152 if (force_md5 || TFMessage::getKeyMaxCdrSerializedSize() > 16)
153 {
154 m_md5.init();
155 m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
156 m_md5.finalize();
157 for (uint8_t i = 0; i < 16; ++i)
158 {
159 handle->value[i] = m_md5.digest[i];
160 }
161 }
162 else
163 {
164 for (uint8_t i = 0; i < 16; ++i)
165 {
166 handle->value[i] = m_keyBuffer[i];
167 }
168 }
169 return true;
170 }
171 } //End of namespace msg
172} //End of namespace tf2_msgs
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::rtps::SerializedPayload_t SerializedPayload_t
eProsima_user_DllExport TFMessagePubSubType()
virtual eProsima_user_DllExport std::function< uint32_t()> getSerializedSizeProvider(void *data) override
virtual eProsima_user_DllExport bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override
virtual eProsima_user_DllExport bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t *payload, void *data) override
virtual eProsima_user_DllExport void deleteData(void *data) override
virtual eProsima_user_DllExport ~TFMessagePubSubType() override
virtual eProsima_user_DllExport void * createData() override
virtual eProsima_user_DllExport bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle, bool force_md5=false) override
This class represents the structure TFMessage defined by the user in the IDL file.
Definition TFMessage.h:74
static eProsima_user_DllExport size_t getCdrSerializedSize(const tf2_msgs::msg::TFMessage &data, size_t current_alignment=0)
This function returns the serialized size of a data depending on the buffer alignment.
static eProsima_user_DllExport bool isKeyDefined()
This function tells you if the Key has been defined for this type
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
This function serializes the key members of an object using CDR serialization.
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
This function deserializes an object using CDR serialization.
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const
This function serializes an object using CDR serialization.
static eProsima_user_DllExport size_t getKeyMaxCdrSerializedSize(size_t current_alignment=0)
This function returns the maximum serialized size of the Key of an object depending on the buffer ali...
static eProsima_user_DllExport size_t getMaxCdrSerializedSize(size_t current_alignment=0)
This function returns the maximum serialized size of an object depending on the buffer alignment.