CARLA
 
载入中...
搜索中...
未找到
PoseWithCovariancePubSubTypes.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 PoseWithCovariancePubSubTypes.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 geometry_msgs {
31 namespace msg {
32
34 {
35 // 设置消息类型的名称,表示该类型是 geometry_msgs::msg::PoseWithCovariance 类型的 DDS 消息
36 setName("geometry_msgs::msg::dds_::PoseWithCovariance_");
37
38 // 获取 PoseWithCovariance 类型的最大 CDR 序列化大小
40
41 // 为可能存在的子消息进行对齐处理,这里假设每个子消息需要 4 字节对齐
42 type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4);
43
44 // 计算最终类型的大小,并加上 4 字节用于封装(encapsulation)
45 m_typeSize = static_cast<uint32_t>(type_size) + 4;
46
47 // 检查是否已为该类型定义键(key),并将结果保存在 m_isGetKeyDefined 中
48 m_isGetKeyDefined = PoseWithCovariance::isKeyDefined();
49
50 // 计算最大键的 CDR 序列化大小,如果键的大小大于 16 字节,则使用较大的值
51 size_t keyLength = PoseWithCovariance::getKeyMaxCdrSerializedSize() > 16 ?
53
54 // 为键分配内存,并将其初始化为零
55 m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength));
56 memset(m_keyBuffer, 0, keyLength);
57 }
58
66
68 void* data,
69 SerializedPayload_t* payload)
70 {
71 // 将输入数据指针转换为 PoseWithCovariance 类型的指针
72 PoseWithCovariance* p_type = static_cast<PoseWithCovariance*>(data);
73
74 // 创建一个 eprosima::fastcdr::FastBuffer 对象,负责管理序列化过程中的原始缓冲区
75 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size);
76
77 // 创建一个 eprosima::fastcdr::Cdr 对象,负责执行实际的序列化操作
78 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
79
80 // 根据序列化器的字节序设置封装格式(大端或小端)
81 payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
82
83 // 序列化封装头(可能包含字节序和其他元数据)
84 ser.serialize_encapsulation();
85
86 try
87 {
88 // 序列化 PoseWithCovariance 类型的对象
89 p_type->serialize(ser);
90 }
91 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
92 {
93 // 如果序列化过程中发生内存不足的异常,返回 false
94 return false;
95 }
96
97 // 获取序列化后的数据长度,并设置到 payload->length
98 payload->length = static_cast<uint32_t>(ser.getSerializedDataLength());
99
100 // 返回序列化成功
101 return true;
102 }
103
105 SerializedPayload_t* payload,
106 void* data)
107 {
108 try
109 {
110 //Convert DATA to pointer of your type
111 PoseWithCovariance* p_type = static_cast<PoseWithCovariance*>(data);
112
113 // Object that manages the raw buffer.
114 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length);
115
116 // Object that deserializes the data.
117 eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
118
119 // Deserialize encapsulation.
120 deser.read_encapsulation();
121 payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
122
123 // Deserialize the object.
124 p_type->deserialize(deser);
125 }
126 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
127 {
128 return false;
129 }
130
131 return true;
132 }
133
135 void* data)
136 {
137 return [data]() -> uint32_t
138 {
139 return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<PoseWithCovariance*>(data))) +
140 4u /*encapsulation*/;
141 };
142 }
143
145 {
146 return reinterpret_cast<void*>(new PoseWithCovariance());
147 }
148
150 void* data)
151 {
152 delete(reinterpret_cast<PoseWithCovariance*>(data));
153 }
154
156 void* data,
157 InstanceHandle_t* handle,
158 bool force_md5)
159 {
160 if (!m_isGetKeyDefined)
161 {
162 return false;
163 }
164
165 PoseWithCovariance* p_type = static_cast<PoseWithCovariance*>(data);
166
167 // Object that manages the raw buffer.
168 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
170
171 // Object that serializes the data.
172 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS);
173 p_type->serializeKey(ser);
175 {
176 m_md5.init();
177 m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
178 m_md5.finalize();
179 for (uint8_t i = 0; i < 16; ++i)
180 {
181 handle->value[i] = m_md5.digest[i];
182 }
183 }
184 else
185 {
186 for (uint8_t i = 0; i < 16; ++i)
187 {
188 handle->value[i] = m_keyBuffer[i];
189 }
190 }
191 return true;
192 }
193 } //End of namespace msg
194} //End of namespace geometry_msgs
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::rtps::SerializedPayload_t SerializedPayload_t
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 std::function< uint32_t()> getSerializedSizeProvider(void *data) override
virtual eProsima_user_DllExport ~PoseWithCovariancePubSubType() 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
virtual eProsima_user_DllExport bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override
This class represents the structure PoseWithCovariance defined by the user in the IDL file.
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...
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
This function serializes the key members of an object using CDR serialization.
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.
static eProsima_user_DllExport bool isKeyDefined()
This function tells you if the Key has been defined for this type
static eProsima_user_DllExport size_t getCdrSerializedSize(const geometry_msgs::msg::PoseWithCovariance &data, size_t current_alignment=0)
This function returns the serialized size of a data depending on the buffer alignment.
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
This function deserializes an object using CDR serialization.