CARLA
 
载入中...
搜索中...
未找到
Point32PubSubTypes.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 Point32PubSubTypes.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
25#include "Point32PubSubTypes.h"
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 Point32PubSubType::Point32PubSubType() // Point32PubSubType类的构造函数,用于初始化与Point32类型序列化相关的一些属性和资源
33 {
34 setName("geometry_msgs::msg::dds_::Point32_");
35 auto type_size = Point32::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 = Point32::isKeyDefined();
39 size_t keyLength = Point32::getKeyMaxCdrSerializedSize() > 16 ?
41 m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength));
42 memset(m_keyBuffer, 0, keyLength);
43 }
44
45 Point32PubSubType::~Point32PubSubType()// Point32PubSubType类的析构函数,用于释放构造函数中分配的键缓冲区内存资源
46 {
47 if (m_keyBuffer != nullptr)
48 {
49 free(m_keyBuffer);
50 }
51 }
52 // 序列化函数,将给定的Point32类型的数据对象进行序列化,并将结果存储到SerializedPayload_t结构中
54 void* data,
55 SerializedPayload_t* payload)
56 {
57 Point32* p_type = static_cast<Point32*>(data); // 将传入的void*类型数据转换为Point32*类型指针,以便后续进行具体的序列化操作
58 // Object that manages the raw buffer.
59 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size);
60 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);// 创建一个Cdr对象,用于实际的数据序列化操作,设置了字节序(默认字节序)和特定的CDR模式
61 payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
62 // Serialize encapsulation
63 ser.serialize_encapsulation();
64 try
65 {
66 // Serialize the object.
67 p_type->serialize(ser);
68 }
69 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
70 {
71 // 如果在序列化过程中出现内存不足异常,则返回false表示序列化失败
72 return false;
73 }
74 payload->length = static_cast<uint32_t>(ser.getSerializedDataLength());// 获取序列化后的数据实际长度,并设置到payload结构中,以便后续使用者知道有效数据的长度范围
75 return true;
76 }
77 // 反序列化函数,从SerializedPayload_t结构中读取数据,并反序列化到给定的Point32类型对象中
79 SerializedPayload_t* payload,
80 void* data)
81 {
82 try
83 {
84 // 将传入的void*类型数据转换为Point32*类型指针,以便后续进行具体的反序列化操作,将数据填充到对应的对象中
85 Point32* p_type = static_cast<Point32*>(data);
86 // 创建一个FastBuffer对象,关联payload中的数据指针和实际的数据长度,
87 // 用于提供反序列化操作所需的原始缓冲区数据
88 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length);
89 // 创建一个Cdr对象,用于实际的反序列化操作,设置了字节序(默认字节序)和特定的CDR模式(与序列化时对应)
90 eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
91 // 先反序列化封装相关的头部信息,从中获取字节序等信息,以便后续正确解析数据
92 deser.read_encapsulation();
93 payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
94 // 调用Point32对象自身的deserialize函数,从缓冲区中读取数据并填充到对象的各个成员变量中,完成反序列化
95 p_type->deserialize(deser);
96 }
97 catch (eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
98 {
99 // 如果在反序列化过程中出现内存不足异常,则返回false表示反序列化失败
100 return false;
101 }
102
103 return true;
104 }
105 // 返回一个函数对象,该函数对象用于获取给定Point32类型数据对象的序列化大小(包含封装等额外开销)
107 void* data)
108 {
109 return [data]() -> uint32_t
110 {
111 // 计算并返回Point32对象的CDR序列化大小加上封装相关的4字节开销
112 return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<Point32*>(data))) +
113 4u /*encapsulation*/;
114 };
115 }
116// 创建一个新的Point32类型对象,并返回其void*类型的指针,用于在需要动态分配该类型对象的场景中
118 {
119 return reinterpret_cast<void*>(new Point32());
120 }
121// 删除给定的Point32类型对象,释放其占用的内存资源,用于在对象使用完毕后进行清理
123 void* data)
124 {
125 delete(reinterpret_cast<Point32*>(data));
126 }
127// 获取给定Point32类型数据对象的键(Key)信息,并将其填充到InstanceHandle_t结构中,用于基于键的查找等操作
129 void* data,
130 InstanceHandle_t* handle,
131 bool force_md5)
132 {
133 if (!m_isGetKeyDefined)
134 {
135 return false;
136 }
137 Point32* p_type = static_cast<Point32*>(data);
138 // 创建一个FastBuffer对象,关联键缓冲区和Point32类型的最大键CDR序列化大小,用于后续序列化键数据
139 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
141
142 // 创建一个Cdr对象,设置为大端字节序(可能是特定要求),用于将键数据序列化到键缓冲区中
143 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS);
144 p_type->serializeKey(ser);
145 if (force_md5 || Point32::getKeyMaxCdrSerializedSize() > 16)
146 {
147 // 如果强制使用MD5计算或者键序列化大小大于16字节,则进行MD5计算相关操作
148 m_md5.init();
149 m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
150 m_md5.finalize();
151 for (uint8_t i = 0; i < 16; ++i)
152 {
153 handle->value[i] = m_md5.digest[i];
154 }
155 }
156 else
157 {
158 // 如果键序列化大小小于等于16字节,则直接将键缓冲区的数据复制到InstanceHandle_t结构中
159 for (uint8_t i = 0; i < 16; ++i)
160 {
161 handle->value[i] = m_keyBuffer[i];
162 }
163 }
164 return true;
165 }
166 } //End of namespace msg
167} //End of namespace geometry_msgs
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::rtps::SerializedPayload_t SerializedPayload_t
virtual eProsima_user_DllExport ~Point32PubSubType() override
virtual eProsima_user_DllExport bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle, bool force_md5=false) override
virtual eProsima_user_DllExport std::function< uint32_t()> getSerializedSizeProvider(void *data) 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 bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override
eProsima_user_DllExport Point32PubSubType()
virtual eProsima_user_DllExport void * createData() override
This class represents the structure Point32 defined by the user in the IDL file.这个类表示用户在IDL(接口定义语言)文件...
Definition Point32.h:93
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
Definition Point32.cpp:151
static eProsima_user_DllExport size_t getCdrSerializedSize(const geometry_msgs::msg::Point32 &data, size_t current_alignment=0)
Definition Point32.cpp:125
static eProsima_user_DllExport bool isKeyDefined()
Definition Point32.cpp:252
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
Definition Point32.cpp:258
static eProsima_user_DllExport size_t getMaxCdrSerializedSize(size_t current_alignment=0)
Definition Point32.cpp:117
static eProsima_user_DllExport size_t getKeyMaxCdrSerializedSize(size_t current_alignment=0)
Definition Point32.cpp:244
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const
Definition Point32.cpp:142