奥特QT DDS 插件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

768 lines
27KB

  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. * @file DDSSampleMachinePubSubTypes.cpp
  16. * This header file contains the implementation of the serialization functions.
  17. *
  18. * This file was generated by the tool fastddsgen.
  19. */
  20. #include "DDSSampleMachinePubSubTypes.hpp"
  21. #include <fastdds/dds/log/Log.hpp>
  22. #include <fastdds/rtps/common/CdrSerialization.hpp>
  23. #include "DDSSampleMachineCdrAux.hpp"
  24. #include "DDSSampleMachineTypeObjectSupport.hpp"
  25. using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t;
  26. using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t;
  27. using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t;
  28. namespace SampleModule {
  29. SampleConfigPubSubType::SampleConfigPubSubType()
  30. {
  31. set_name("SampleModule::SampleConfig");
  32. uint32_t type_size = SampleModule_SampleConfig_max_cdr_typesize;
  33. type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
  34. max_serialized_type_size = type_size + 4; /*encapsulation*/
  35. is_compute_key_provided = false;
  36. uint32_t key_length = SampleModule_SampleConfig_max_key_cdr_typesize > 16 ? SampleModule_SampleConfig_max_key_cdr_typesize : 16;
  37. key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
  38. memset(key_buffer_, 0, key_length);
  39. }
  40. SampleConfigPubSubType::~SampleConfigPubSubType()
  41. {
  42. if (key_buffer_ != nullptr)
  43. {
  44. free(key_buffer_);
  45. }
  46. }
  47. bool SampleConfigPubSubType::serialize(
  48. const void* const data,
  49. SerializedPayload_t& payload,
  50. DataRepresentationId_t data_representation)
  51. {
  52. const SampleConfig* p_type = static_cast<const SampleConfig*>(data);
  53. // Object that manages the raw buffer.
  54. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
  55. // Object that serializes the data.
  56. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
  57. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  58. eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
  59. payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  60. ser.set_encoding_flag(
  61. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  62. eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
  63. eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
  64. try
  65. {
  66. // Serialize encapsulation
  67. ser.serialize_encapsulation();
  68. // Serialize the object.
  69. ser << *p_type;
  70. ser.set_dds_cdr_options({0,0});
  71. }
  72. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  73. {
  74. return false;
  75. }
  76. // Get the serialized length
  77. payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
  78. return true;
  79. }
  80. bool SampleConfigPubSubType::deserialize(
  81. SerializedPayload_t& payload,
  82. void* data)
  83. {
  84. try
  85. {
  86. // Convert DATA to pointer of your type
  87. SampleConfig* p_type = static_cast<SampleConfig*>(data);
  88. // Object that manages the raw buffer.
  89. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
  90. // Object that deserializes the data.
  91. eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
  92. // Deserialize encapsulation.
  93. deser.read_encapsulation();
  94. payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  95. // Deserialize the object.
  96. deser >> *p_type;
  97. }
  98. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  99. {
  100. return false;
  101. }
  102. return true;
  103. }
  104. uint32_t SampleConfigPubSubType::calculate_serialized_size(
  105. const void* const data,
  106. DataRepresentationId_t data_representation)
  107. {
  108. try
  109. {
  110. eprosima::fastcdr::CdrSizeCalculator calculator(
  111. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  112. eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
  113. size_t current_alignment {0};
  114. return static_cast<uint32_t>(calculator.calculate_serialized_size(
  115. *static_cast<const SampleConfig*>(data), current_alignment)) +
  116. 4u /*encapsulation*/;
  117. }
  118. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  119. {
  120. return 0;
  121. }
  122. }
  123. void* SampleConfigPubSubType::create_data()
  124. {
  125. return reinterpret_cast<void*>(new SampleConfig());
  126. }
  127. void SampleConfigPubSubType::delete_data(
  128. void* data)
  129. {
  130. delete(reinterpret_cast<SampleConfig*>(data));
  131. }
  132. bool SampleConfigPubSubType::compute_key(
  133. SerializedPayload_t& payload,
  134. InstanceHandle_t& handle,
  135. bool force_md5)
  136. {
  137. if (!is_compute_key_provided)
  138. {
  139. return false;
  140. }
  141. SampleConfig data;
  142. if (deserialize(payload, static_cast<void*>(&data)))
  143. {
  144. return compute_key(static_cast<void*>(&data), handle, force_md5);
  145. }
  146. return false;
  147. }
  148. bool SampleConfigPubSubType::compute_key(
  149. const void* const data,
  150. InstanceHandle_t& handle,
  151. bool force_md5)
  152. {
  153. if (!is_compute_key_provided)
  154. {
  155. return false;
  156. }
  157. const SampleConfig* p_type = static_cast<const SampleConfig*>(data);
  158. // Object that manages the raw buffer.
  159. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
  160. SampleModule_SampleConfig_max_key_cdr_typesize);
  161. // Object that serializes the data.
  162. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
  163. ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
  164. eprosima::fastcdr::serialize_key(ser, *p_type);
  165. if (force_md5 || SampleModule_SampleConfig_max_key_cdr_typesize > 16)
  166. {
  167. md5_.init();
  168. md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
  169. md5_.finalize();
  170. for (uint8_t i = 0; i < 16; ++i)
  171. {
  172. handle.value[i] = md5_.digest[i];
  173. }
  174. }
  175. else
  176. {
  177. for (uint8_t i = 0; i < 16; ++i)
  178. {
  179. handle.value[i] = key_buffer_[i];
  180. }
  181. }
  182. return true;
  183. }
  184. void SampleConfigPubSubType::register_type_object_representation()
  185. {
  186. register_SampleConfig_type_identifier(type_identifiers_);
  187. }
  188. SampleCommandPubSubType::SampleCommandPubSubType()
  189. {
  190. set_name("SampleModule::SampleCommand");
  191. uint32_t type_size = SampleModule_SampleCommand_max_cdr_typesize;
  192. type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
  193. max_serialized_type_size = type_size + 4; /*encapsulation*/
  194. is_compute_key_provided = false;
  195. uint32_t key_length = SampleModule_SampleCommand_max_key_cdr_typesize > 16 ? SampleModule_SampleCommand_max_key_cdr_typesize : 16;
  196. key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
  197. memset(key_buffer_, 0, key_length);
  198. }
  199. SampleCommandPubSubType::~SampleCommandPubSubType()
  200. {
  201. if (key_buffer_ != nullptr)
  202. {
  203. free(key_buffer_);
  204. }
  205. }
  206. bool SampleCommandPubSubType::serialize(
  207. const void* const data,
  208. SerializedPayload_t& payload,
  209. DataRepresentationId_t data_representation)
  210. {
  211. const SampleCommand* p_type = static_cast<const SampleCommand*>(data);
  212. // Object that manages the raw buffer.
  213. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
  214. // Object that serializes the data.
  215. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
  216. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  217. eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
  218. payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  219. ser.set_encoding_flag(
  220. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  221. eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
  222. eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
  223. try
  224. {
  225. // Serialize encapsulation
  226. ser.serialize_encapsulation();
  227. // Serialize the object.
  228. ser << *p_type;
  229. ser.set_dds_cdr_options({0,0});
  230. }
  231. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  232. {
  233. return false;
  234. }
  235. // Get the serialized length
  236. payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
  237. return true;
  238. }
  239. bool SampleCommandPubSubType::deserialize(
  240. SerializedPayload_t& payload,
  241. void* data)
  242. {
  243. try
  244. {
  245. // Convert DATA to pointer of your type
  246. SampleCommand* p_type = static_cast<SampleCommand*>(data);
  247. // Object that manages the raw buffer.
  248. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
  249. // Object that deserializes the data.
  250. eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
  251. // Deserialize encapsulation.
  252. deser.read_encapsulation();
  253. payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  254. // Deserialize the object.
  255. deser >> *p_type;
  256. }
  257. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  258. {
  259. return false;
  260. }
  261. return true;
  262. }
  263. uint32_t SampleCommandPubSubType::calculate_serialized_size(
  264. const void* const data,
  265. DataRepresentationId_t data_representation)
  266. {
  267. try
  268. {
  269. eprosima::fastcdr::CdrSizeCalculator calculator(
  270. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  271. eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
  272. size_t current_alignment {0};
  273. return static_cast<uint32_t>(calculator.calculate_serialized_size(
  274. *static_cast<const SampleCommand*>(data), current_alignment)) +
  275. 4u /*encapsulation*/;
  276. }
  277. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  278. {
  279. return 0;
  280. }
  281. }
  282. void* SampleCommandPubSubType::create_data()
  283. {
  284. return reinterpret_cast<void*>(new SampleCommand());
  285. }
  286. void SampleCommandPubSubType::delete_data(
  287. void* data)
  288. {
  289. delete(reinterpret_cast<SampleCommand*>(data));
  290. }
  291. bool SampleCommandPubSubType::compute_key(
  292. SerializedPayload_t& payload,
  293. InstanceHandle_t& handle,
  294. bool force_md5)
  295. {
  296. if (!is_compute_key_provided)
  297. {
  298. return false;
  299. }
  300. SampleCommand data;
  301. if (deserialize(payload, static_cast<void*>(&data)))
  302. {
  303. return compute_key(static_cast<void*>(&data), handle, force_md5);
  304. }
  305. return false;
  306. }
  307. bool SampleCommandPubSubType::compute_key(
  308. const void* const data,
  309. InstanceHandle_t& handle,
  310. bool force_md5)
  311. {
  312. if (!is_compute_key_provided)
  313. {
  314. return false;
  315. }
  316. const SampleCommand* p_type = static_cast<const SampleCommand*>(data);
  317. // Object that manages the raw buffer.
  318. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
  319. SampleModule_SampleCommand_max_key_cdr_typesize);
  320. // Object that serializes the data.
  321. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
  322. ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
  323. eprosima::fastcdr::serialize_key(ser, *p_type);
  324. if (force_md5 || SampleModule_SampleCommand_max_key_cdr_typesize > 16)
  325. {
  326. md5_.init();
  327. md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
  328. md5_.finalize();
  329. for (uint8_t i = 0; i < 16; ++i)
  330. {
  331. handle.value[i] = md5_.digest[i];
  332. }
  333. }
  334. else
  335. {
  336. for (uint8_t i = 0; i < 16; ++i)
  337. {
  338. handle.value[i] = key_buffer_[i];
  339. }
  340. }
  341. return true;
  342. }
  343. void SampleCommandPubSubType::register_type_object_representation()
  344. {
  345. register_SampleCommand_type_identifier(type_identifiers_);
  346. }
  347. SampleMachineInfoPubSubType::SampleMachineInfoPubSubType()
  348. {
  349. set_name("SampleModule::SampleMachineInfo");
  350. uint32_t type_size = SampleModule_SampleMachineInfo_max_cdr_typesize;
  351. type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
  352. max_serialized_type_size = type_size + 4; /*encapsulation*/
  353. is_compute_key_provided = false;
  354. uint32_t key_length = SampleModule_SampleMachineInfo_max_key_cdr_typesize > 16 ? SampleModule_SampleMachineInfo_max_key_cdr_typesize : 16;
  355. key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
  356. memset(key_buffer_, 0, key_length);
  357. }
  358. SampleMachineInfoPubSubType::~SampleMachineInfoPubSubType()
  359. {
  360. if (key_buffer_ != nullptr)
  361. {
  362. free(key_buffer_);
  363. }
  364. }
  365. bool SampleMachineInfoPubSubType::serialize(
  366. const void* const data,
  367. SerializedPayload_t& payload,
  368. DataRepresentationId_t data_representation)
  369. {
  370. const SampleMachineInfo* p_type = static_cast<const SampleMachineInfo*>(data);
  371. // Object that manages the raw buffer.
  372. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
  373. // Object that serializes the data.
  374. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
  375. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  376. eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
  377. payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  378. ser.set_encoding_flag(
  379. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  380. eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
  381. eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
  382. try
  383. {
  384. // Serialize encapsulation
  385. ser.serialize_encapsulation();
  386. // Serialize the object.
  387. ser << *p_type;
  388. ser.set_dds_cdr_options({0,0});
  389. }
  390. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  391. {
  392. return false;
  393. }
  394. // Get the serialized length
  395. payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
  396. return true;
  397. }
  398. bool SampleMachineInfoPubSubType::deserialize(
  399. SerializedPayload_t& payload,
  400. void* data)
  401. {
  402. try
  403. {
  404. // Convert DATA to pointer of your type
  405. SampleMachineInfo* p_type = static_cast<SampleMachineInfo*>(data);
  406. // Object that manages the raw buffer.
  407. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
  408. // Object that deserializes the data.
  409. eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
  410. // Deserialize encapsulation.
  411. deser.read_encapsulation();
  412. payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  413. // Deserialize the object.
  414. deser >> *p_type;
  415. }
  416. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  417. {
  418. return false;
  419. }
  420. return true;
  421. }
  422. uint32_t SampleMachineInfoPubSubType::calculate_serialized_size(
  423. const void* const data,
  424. DataRepresentationId_t data_representation)
  425. {
  426. try
  427. {
  428. eprosima::fastcdr::CdrSizeCalculator calculator(
  429. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  430. eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
  431. size_t current_alignment {0};
  432. return static_cast<uint32_t>(calculator.calculate_serialized_size(
  433. *static_cast<const SampleMachineInfo*>(data), current_alignment)) +
  434. 4u /*encapsulation*/;
  435. }
  436. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  437. {
  438. return 0;
  439. }
  440. }
  441. void* SampleMachineInfoPubSubType::create_data()
  442. {
  443. return reinterpret_cast<void*>(new SampleMachineInfo());
  444. }
  445. void SampleMachineInfoPubSubType::delete_data(
  446. void* data)
  447. {
  448. delete(reinterpret_cast<SampleMachineInfo*>(data));
  449. }
  450. bool SampleMachineInfoPubSubType::compute_key(
  451. SerializedPayload_t& payload,
  452. InstanceHandle_t& handle,
  453. bool force_md5)
  454. {
  455. if (!is_compute_key_provided)
  456. {
  457. return false;
  458. }
  459. SampleMachineInfo data;
  460. if (deserialize(payload, static_cast<void*>(&data)))
  461. {
  462. return compute_key(static_cast<void*>(&data), handle, force_md5);
  463. }
  464. return false;
  465. }
  466. bool SampleMachineInfoPubSubType::compute_key(
  467. const void* const data,
  468. InstanceHandle_t& handle,
  469. bool force_md5)
  470. {
  471. if (!is_compute_key_provided)
  472. {
  473. return false;
  474. }
  475. const SampleMachineInfo* p_type = static_cast<const SampleMachineInfo*>(data);
  476. // Object that manages the raw buffer.
  477. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
  478. SampleModule_SampleMachineInfo_max_key_cdr_typesize);
  479. // Object that serializes the data.
  480. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
  481. ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
  482. eprosima::fastcdr::serialize_key(ser, *p_type);
  483. if (force_md5 || SampleModule_SampleMachineInfo_max_key_cdr_typesize > 16)
  484. {
  485. md5_.init();
  486. md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
  487. md5_.finalize();
  488. for (uint8_t i = 0; i < 16; ++i)
  489. {
  490. handle.value[i] = md5_.digest[i];
  491. }
  492. }
  493. else
  494. {
  495. for (uint8_t i = 0; i < 16; ++i)
  496. {
  497. handle.value[i] = key_buffer_[i];
  498. }
  499. }
  500. return true;
  501. }
  502. void SampleMachineInfoPubSubType::register_type_object_representation()
  503. {
  504. register_SampleMachineInfo_type_identifier(type_identifiers_);
  505. }
  506. SamplePointsPubSubType::SamplePointsPubSubType()
  507. {
  508. set_name("SampleModule::SamplePoints");
  509. uint32_t type_size = SampleModule_SamplePoints_max_cdr_typesize;
  510. type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
  511. max_serialized_type_size = type_size + 4; /*encapsulation*/
  512. is_compute_key_provided = false;
  513. uint32_t key_length = SampleModule_SamplePoints_max_key_cdr_typesize > 16 ? SampleModule_SamplePoints_max_key_cdr_typesize : 16;
  514. key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
  515. memset(key_buffer_, 0, key_length);
  516. }
  517. SamplePointsPubSubType::~SamplePointsPubSubType()
  518. {
  519. if (key_buffer_ != nullptr)
  520. {
  521. free(key_buffer_);
  522. }
  523. }
  524. bool SamplePointsPubSubType::serialize(
  525. const void* const data,
  526. SerializedPayload_t& payload,
  527. DataRepresentationId_t data_representation)
  528. {
  529. const SamplePoints* p_type = static_cast<const SamplePoints*>(data);
  530. // Object that manages the raw buffer.
  531. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
  532. // Object that serializes the data.
  533. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
  534. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  535. eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
  536. payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  537. ser.set_encoding_flag(
  538. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  539. eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
  540. eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
  541. try
  542. {
  543. // Serialize encapsulation
  544. ser.serialize_encapsulation();
  545. // Serialize the object.
  546. ser << *p_type;
  547. ser.set_dds_cdr_options({0,0});
  548. }
  549. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  550. {
  551. return false;
  552. }
  553. // Get the serialized length
  554. payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
  555. return true;
  556. }
  557. bool SamplePointsPubSubType::deserialize(
  558. SerializedPayload_t& payload,
  559. void* data)
  560. {
  561. try
  562. {
  563. // Convert DATA to pointer of your type
  564. SamplePoints* p_type = static_cast<SamplePoints*>(data);
  565. // Object that manages the raw buffer.
  566. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
  567. // Object that deserializes the data.
  568. eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
  569. // Deserialize encapsulation.
  570. deser.read_encapsulation();
  571. payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
  572. // Deserialize the object.
  573. deser >> *p_type;
  574. }
  575. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  576. {
  577. return false;
  578. }
  579. return true;
  580. }
  581. uint32_t SamplePointsPubSubType::calculate_serialized_size(
  582. const void* const data,
  583. DataRepresentationId_t data_representation)
  584. {
  585. try
  586. {
  587. eprosima::fastcdr::CdrSizeCalculator calculator(
  588. data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
  589. eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
  590. size_t current_alignment {0};
  591. return static_cast<uint32_t>(calculator.calculate_serialized_size(
  592. *static_cast<const SamplePoints*>(data), current_alignment)) +
  593. 4u /*encapsulation*/;
  594. }
  595. catch (eprosima::fastcdr::exception::Exception& /*exception*/)
  596. {
  597. return 0;
  598. }
  599. }
  600. void* SamplePointsPubSubType::create_data()
  601. {
  602. return reinterpret_cast<void*>(new SamplePoints());
  603. }
  604. void SamplePointsPubSubType::delete_data(
  605. void* data)
  606. {
  607. delete(reinterpret_cast<SamplePoints*>(data));
  608. }
  609. bool SamplePointsPubSubType::compute_key(
  610. SerializedPayload_t& payload,
  611. InstanceHandle_t& handle,
  612. bool force_md5)
  613. {
  614. if (!is_compute_key_provided)
  615. {
  616. return false;
  617. }
  618. SamplePoints data;
  619. if (deserialize(payload, static_cast<void*>(&data)))
  620. {
  621. return compute_key(static_cast<void*>(&data), handle, force_md5);
  622. }
  623. return false;
  624. }
  625. bool SamplePointsPubSubType::compute_key(
  626. const void* const data,
  627. InstanceHandle_t& handle,
  628. bool force_md5)
  629. {
  630. if (!is_compute_key_provided)
  631. {
  632. return false;
  633. }
  634. const SamplePoints* p_type = static_cast<const SamplePoints*>(data);
  635. // Object that manages the raw buffer.
  636. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
  637. SampleModule_SamplePoints_max_key_cdr_typesize);
  638. // Object that serializes the data.
  639. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
  640. ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
  641. eprosima::fastcdr::serialize_key(ser, *p_type);
  642. if (force_md5 || SampleModule_SamplePoints_max_key_cdr_typesize > 16)
  643. {
  644. md5_.init();
  645. md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
  646. md5_.finalize();
  647. for (uint8_t i = 0; i < 16; ++i)
  648. {
  649. handle.value[i] = md5_.digest[i];
  650. }
  651. }
  652. else
  653. {
  654. for (uint8_t i = 0; i < 16; ++i)
  655. {
  656. handle.value[i] = key_buffer_[i];
  657. }
  658. }
  659. return true;
  660. }
  661. void SamplePointsPubSubType::register_type_object_representation()
  662. {
  663. register_SamplePoints_type_identifier(type_identifiers_);
  664. }
  665. } // namespace SampleModule
  666. // Include auxiliary functions like for serializing/deserializing.
  667. #include "DDSSampleMachineCdrAux.ipp"