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