CARLA
 
载入中...
搜索中...
未找到
ImagePubSubTypes.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 ImagePubSubTypes.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 "ImagePubSubTypes.h"
26// 定义序列化负载类型和实例句柄类型
27using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t;
28using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t;
29
30namespace sensor_msgs {
31 namespace msg {
33 {
34 setName("sensor_msgs::msg::dds_::Image_");
35 auto type_size = Image::getMaxCdrSerializedSize(); // 获取Image类型的最大CDR序列化大小
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 = Image::isKeyDefined(); // 设置是否定义了键
39 size_t keyLength = Image::getKeyMaxCdrSerializedSize() > 16 ? // 计算键缓冲区长度
41 m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength)); // 分配键缓冲区
42 memset(m_keyBuffer, 0, keyLength); // 初始化键缓冲区
43 }
44
45 ImagePubSubType::~ImagePubSubType() // ImagePubSubType析构函数
46 {
47 if (m_keyBuffer != nullptr)
48 {
49 free(m_keyBuffer);
50 }
51 }
52
54 void* data,
55 SerializedPayload_t* payload)
56 {
57 Image* p_type = static_cast<Image*>(data);
58
59 // Object that manages the raw buffer.
60 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size); // 创建FastBuffer对象管理原始缓冲区
61 // Object that serializes the data.
62 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); // 创建Cdr对象序列化数据
63 payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
64 // Serialize encapsulation
65 ser.serialize_encapsulation();
66 p_type->serialize(ser);
67 // Get the serialized length
68 payload->length = static_cast<uint32_t>(ser.getSerializedDataLength());
69 return true;
70 }
71
73 SerializedPayload_t* payload,
74 void* data)
75 {
76 //Convert DATA to pointer of your type
77 Image* p_type = static_cast<Image*>(data); // 将void指针转换为Image指针
78
79 // Object that manages the raw buffer.
80 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length); // 创建FastBuffer对象管理原始缓冲区
81
82 // Object that deserializes the data.
83 eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); // 创建Cdr对象反序列化数据
84
85 // Deserialize encapsulation.
86 deser.read_encapsulation(); // 反序列化封装
87 payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
88
89 // Deserialize the object.
90 p_type->deserialize(deser);
91 return true;
92 }
93
95 void* data)
96 {
97 return [data]() -> uint32_t
98 {
99 return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<Image*>(data))) +
100 4u /*encapsulation*/;
101 };
102 }
103
105 {
106 return reinterpret_cast<void*>(new Image());
107 }
108
110 void* data)
111 {
112 delete(reinterpret_cast<Image*>(data));
113 }
114
116 void* data,
117 InstanceHandle_t* handle,
118 bool force_md5)
119 {
120 if (!m_isGetKeyDefined) // 如果没有定义获取键,则返回false
121 {
122 return false;
123 }
124
125 Image* p_type = static_cast<Image*>(data);
126
127 // Object that manages the raw buffer.
128 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
129 Image::getKeyMaxCdrSerializedSize()); // 将void指针转换为Image指针
130
131 // Object that serializes the data.
132 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // 创建Cdr对象序列化数据
133 p_type->serializeKey(ser); // 序列化Image对象的键
134 if (force_md5 || Image::getKeyMaxCdrSerializedSize() > 16) // 如果需要强制MD5或键大小大于16,则计算MD5
135 {
136 m_md5.init();
137 m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
138 m_md5.finalize();
139 for (uint8_t i = 0; i < 16; ++i)
140 {
141 handle->value[i] = m_md5.digest[i];
142 }
143 }
144 else // 否则直接复制键缓冲区到句柄
145 {
146 for (uint8_t i = 0; i < 16; ++i)
147 {
148 handle->value[i] = m_keyBuffer[i];
149 }
150 }
151 return true;
152 }
153 } //End of namespace msg
154} //End of namespace sensor_msgs
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
eprosima::fastrtps::rtps::SerializedPayload_t SerializedPayload_t
eProsima_user_DllExport ImagePubSubType()
virtual eProsima_user_DllExport bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override
virtual eProsima_user_DllExport std::function< uint32_t()> getSerializedSizeProvider(void *data) override
virtual eProsima_user_DllExport void deleteData(void *data) override
virtual eProsima_user_DllExport bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle, bool force_md5=false) override
virtual eProsima_user_DllExport void * createData() override
virtual eProsima_user_DllExport ~ImagePubSubType() override
virtual eProsima_user_DllExport bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t *payload, void *data) override
This class represents the structure Image defined by the user in the IDL file.这个类表示在 IDL(接口定义语言)文件中由用...
static eProsima_user_DllExport size_t getMaxCdrSerializedSize(size_t current_alignment=0)
Definition Image.cpp:172
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const
Definition Image.cpp:207
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
Definition Image.cpp:220
static eProsima_user_DllExport size_t getCdrSerializedSize(const sensor_msgs::msg::Image &data, size_t current_alignment=0)
Definition Image.cpp:180
static eProsima_user_DllExport bool isKeyDefined()
Definition Image.cpp:461
static eProsima_user_DllExport size_t getKeyMaxCdrSerializedSize(size_t current_alignment=0)
Definition Image.cpp:452
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
Definition Image.cpp:468