| Fast CDR Version 2.3.5 Fast CDR

Loading...
Searching...
No Matches
Cdr.h
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#ifndef _FASTCDR_CDR_H_
16#define _FASTCDR_CDR_H_
17
18#include <array>
19#include <bitset>
20#include <cassert>
21#include <cstdint>
22#include <cstring>
23#include <functional>
24#include <map>
25#include <string>
26#include <type_traits>
27#include <utility>
28#include <vector>
29
30#include "fastcdr_dll.h"
31
32#include "CdrEncoding.hpp"
33#include "cdr/fixed_size_string.hpp"
34#include "detail/container_recursive_inspector.hpp"
35#include "exceptions/BadParamException.h"
36#include "exceptions/Exception.h"
37#include "exceptions/NotEnoughMemoryException.h"
38#include "FastBuffer.h"
39#include "xcdr/external.hpp"
40#include "xcdr/MemberId.hpp"
41#include "xcdr/optional.hpp"
42
43#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
44#include <malloc.h>
45#else
46#include <stdlib.h>
47#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
48
49 namespace eprosima {
50 namespace fastcdr {
51
52 class Cdr;
53
54 template<class _T>
55 extern void serialize(
56 Cdr&,
57 const _T&);
58
59 template<class _T>
60 extern void deserialize(
61 Cdr&,
62 _T&);
63
68 class Cdr
69{
70 public:
71
75 typedef enum : uint8_t
76 {
78 BIG_ENDIANNESS = 0x0,
80 LITTLE_ENDIANNESS = 0x1
81 } Endianness;
82
84 Cdr_DllAPI static const Endianness DEFAULT_ENDIAN;
85
90 typedef enum
91 {
93 SHORT_HEADER,
95 LONG_HEADER,
97 AUTO_WITH_SHORT_HEADER_BY_DEFAULT,
99 AUTO_WITH_LONG_HEADER_BY_DEFAULT
100 } XCdrHeaderSelection;
101
105 class state
106 {
107 friend class Cdr;
108
109 public:
110
112 Cdr_DllAPI state(
113 const Cdr& cdr);
114
116 Cdr_DllAPI state(
117 const state& state);
118
119
121 Cdr_DllAPI bool operator ==(
122 const state& other_state) const;
123
124 private:
125
126 state& operator =(
127 const state& state) = delete;
128
130 const FastBuffer::iterator offset_;
131
133 const FastBuffer::iterator origin_;
134
136 bool swap_bytes_ {false};
137
139 size_t last_data_size_ {0};
140
142 MemberId next_member_id_;
143
145 uint32_t member_size_ {0};
146
148 XCdrHeaderSelection header_selection_ {XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT};
149
151 XCdrHeaderSelection header_serialized_ {XCdrHeaderSelection::SHORT_HEADER};
152
154 EncodingAlgorithmFlag previous_encoding_ {EncodingAlgorithmFlag::PLAIN_CDR2};
155 };
156
165 Cdr_DllAPI Cdr(
166 FastBuffer& cdr_buffer,
167 const Endianness endianness = DEFAULT_ENDIAN,
168 const CdrVersion cdr_version = XCDRv2);
169
179 Cdr_DllAPI Cdr& read_encapsulation();
180
187 Cdr_DllAPI Cdr& serialize_encapsulation();
188
193 Cdr_DllAPI CdrVersion get_cdr_version() const;
194
200 Cdr_DllAPI EncodingAlgorithmFlag get_encoding_flag() const;
201
209 Cdr_DllAPI bool set_encoding_flag(
210 EncodingAlgorithmFlag encoding_flag);
211
216 Cdr_DllAPI std::array<uint8_t, 2> get_dds_cdr_options() const;
217
222 Cdr_DllAPI void set_dds_cdr_options(
223 const std::array<uint8_t, 2>& options);
224
229 Cdr_DllAPI void change_endianness(
230 Endianness endianness);
231
236 Cdr_DllAPI Endianness endianness() const;
237
243 Cdr_DllAPI bool jump(
244 size_t num_bytes);
245
249 Cdr_DllAPI void reset();
250
255 Cdr_DllAPI char* get_buffer_pointer();
256
261 Cdr_DllAPI char* get_current_position();
262
267 Cdr_DllAPI size_t get_serialized_data_length() const;
268
275 inline static size_t alignment(
276 size_t current_alignment,
277 size_t data_size)
278 {
279 return (data_size - (current_alignment % data_size)) & (data_size - 1);
280 }
281
286 Cdr_DllAPI state get_state() const;
287
292 Cdr_DllAPI void set_state(
293 const state& state);
294
300 Cdr_DllAPI bool move_alignment_forward(
301 size_t num_bytes);
302
306 inline void reset_alignment()
307 {
308 origin_ = offset_;
309 last_data_size_ = 0;
310 }
311
325 template<class _T>
326 inline Cdr& operator <<(
327 const _T& value)
328 {
329 if (MEMBER_ID_INVALID == next_member_id_)
330 {
331 serialize(value);
332 }
333 else
334 {
335 serialize_member(next_member_id_, value);
336
337 }
338
339 return *this;
340 }
341
355 template<class _T>
356 inline Cdr& operator >>(
357 _T& value)
358 {
359 if (MEMBER_ID_INVALID == next_member_id_)
360 {
361 deserialize(value);
362 }
363 else
364 {
365 deserialize_member(value);
366 }
367 return *this;
368 }
369
380 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* = nullptr, typename = void>
381 Cdr& serialize(
382 const _T& value)
383 {
384 eprosima::fastcdr::serialize(*this, value);
385 return *this;
386 }
387
396 template<class _T>
397 Cdr& serialize(
398 const _T& value,
399 Endianness endianness)
400 {
401 bool aux_swap = swap_bytes_;
402 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
403 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
404
405 try
406 {
407 serialize(value);
408 swap_bytes_ = aux_swap;
409 }
410 catch (exception::Exception& ex)
411 {
412 swap_bytes_ = aux_swap;
413 ex.raise();
414 }
415
416 return *this;
417 }
418
427 template<class _T,
428 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
429 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
430 int32_t>::value>::type* = nullptr>
431 Cdr& serialize(
432 const _T& value)
433 {
434 return serialize(static_cast<int32_t>(value));
435 }
436
445 template<class _T,
446 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
447 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
448 uint32_t>::value>::type* = nullptr>
449 Cdr& serialize(
450 const _T& value)
451 {
452 return serialize(static_cast<uint32_t>(value));
453 }
454
463 template<class _T,
464 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
465 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
466 int16_t>::value>::type* = nullptr>
467 Cdr& serialize(
468 const _T& value)
469 {
470 return serialize(static_cast<int16_t>(value));
471 }
472
481 template<class _T,
482 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
483 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
484 uint16_t>::value>::type* = nullptr>
485 Cdr& serialize(
486 const _T& value)
487 {
488 return serialize(static_cast<uint16_t>(value));
489 }
490
499 template<class _T,
500 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
501 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
502 int8_t>::value>::type* = nullptr>
503 Cdr& serialize(
504 const _T& value)
505 {
506 return serialize(static_cast<int8_t>(value));
507 }
508
517 template<class _T,
518 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
519 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
520 uint8_t>::value>::type* = nullptr>
521 Cdr& serialize(
522 const _T& value)
523 {
524 return serialize(static_cast<uint8_t>(value));
525 }
526
533 Cdr_DllAPI Cdr& serialize(
534 const uint8_t& octet_t);
535
542 Cdr_DllAPI Cdr& serialize(
543 const char char_t);
544
551 Cdr_DllAPI Cdr& serialize(
552 const int8_t int8);
553
560 Cdr_DllAPI Cdr& serialize(
561 const uint16_t ushort_t);
562
569 Cdr_DllAPI Cdr& serialize(
570 const int16_t short_t);
571
578 Cdr_DllAPI Cdr& serialize(
579 const uint32_t ulong_t);
580
587 Cdr_DllAPI Cdr& serialize(
588 const int32_t long_t);
589
596 Cdr_DllAPI Cdr& serialize(
597 const wchar_t wchar);
598
605 Cdr_DllAPI Cdr& serialize(
606 const uint64_t ulonglong_t);
607
614 Cdr_DllAPI Cdr& serialize(
615 const int64_t longlong_t);
616
623 Cdr_DllAPI Cdr& serialize(
624 const float float_t);
625
632 Cdr_DllAPI Cdr& serialize(
633 const double double_t);
634
642 Cdr_DllAPI Cdr& serialize(
643 const long double ldouble_t);
644
651 Cdr_DllAPI Cdr& serialize(
652 const bool bool_t);
653
660 Cdr_DllAPI Cdr& serialize(
661 char* string_t);
662
669 Cdr_DllAPI Cdr& serialize(
670 const char* string_t);
671
678 Cdr_DllAPI Cdr& serialize(
679 const wchar_t* string_t);
680
688 TEMPLATE_SPEC
689 Cdr& serialize(
690 const std::string& string_t)
691 {
692 // Check there are no null characters in the string.
693 const char* c_str = string_t.c_str();
694 const auto str_len = strlen(c_str);
695 if (string_t.size() > str_len)
696 {
697 throw exception::BadParamException("The string contains null characters");
698 }
699
700 return serialize_sequence(c_str, str_len + 1);
701 }
702
709 TEMPLATE_SPEC
710 Cdr& serialize(
711 const std::wstring& string_t)
712 {
713 return serialize(string_t.c_str());
714 }
715
723 template <size_t MAX_CHARS>
724 Cdr& serialize(
725 const fixed_string<MAX_CHARS>& value)
726 {
727 return serialize(value.c_str());
728 }
729
736 template<class _T, size_t _Size>
737 Cdr& serialize(
738 const std::array<_T, _Size>& array_t)
739 {
740 if (!is_multi_array_primitive(&array_t))
741 {
742 Cdr::state dheader_state {allocate_xcdrv2_dheader()};
743
744 serialize_array(array_t.data(), array_t.size());
745
746 set_xcdrv2_dheader(dheader_state);
747 }
748 else
749 {
750 serialize_array(array_t.data(), array_t.size());
751 }
752
753 return *this;
754 }
755
762 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
763 !std::is_arithmetic<_T>::value>::type* = nullptr>
764 Cdr& serialize(
765 const std::vector<_T>& vector_t)
766 {
767 Cdr::state dheader_state {allocate_xcdrv2_dheader()};
768
769 serialize(static_cast<int32_t>(vector_t.size()));
770
771 try
772 {
773 serialize_array(vector_t.data(), vector_t.size());
774 }
775 catch (exception::Exception& ex)
776 {
777 set_state(dheader_state);
778 ex.raise();
779 }
780
781 set_xcdrv2_dheader(dheader_state);
782
783 return *this;
784 }
785
792 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
793 std::is_arithmetic<_T>::value>::type* = nullptr>
794 Cdr& serialize(
795 const std::vector<_T>& vector_t)
796 {
797 state state_before_error(*this);
798
799 serialize(static_cast<int32_t>(vector_t.size()));
800
801 try
802 {
803 serialize_array(vector_t.data(), vector_t.size());
804 }
805 catch (exception::Exception& ex)
806 {
807 set_state(state_before_error);
808 ex.raise();
809 }
810
811 if (CdrVersion::XCDRv2 == cdr_version_)
812 {
813 serialized_member_size_ = get_serialized_member_size<_T>();
814 }
815
816 return *this;
817 }
818
825 TEMPLATE_SPEC
826 Cdr& serialize(
827 const std::vector<bool>& vector_t)
828 {
829 return serialize_bool_sequence(vector_t);
830 }
831
838 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
839 !std::is_arithmetic<_T>::value>::type* = nullptr>
840 Cdr& serialize(
841 const std::map<_K, _T>& map_t)
842 {
843 Cdr::state dheader_state {allocate_xcdrv2_dheader()};
844
845 serialize(static_cast<int32_t>(map_t.size()));
846
847 try
848 {
849 for (auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair)
850 {
851 serialize(it_pair->first);
852 serialize(it_pair->second);
853 }
854 }
855 catch (exception::Exception& ex)
856 {
857 set_state(dheader_state);
858 ex.raise();
859 }
860
861 set_xcdrv2_dheader(dheader_state);
862
863 return *this;
864 }
865
872 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
873 std::is_arithmetic<_T>::value>::type* = nullptr>
874 Cdr& serialize(
875 const std::map<_K, _T>& map_t)
876 {
877 state state_(*this);
878
879 serialize(static_cast<int32_t>(map_t.size()));
880
881 try
882 {
883 for (auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair)
884 {
885 serialize(it_pair->first);
886 serialize(it_pair->second);
887 }
888 }
889 catch (exception::Exception& ex)
890 {
891 set_state(state_);
892 ex.raise();
893 }
894
895 return *this;
896 }
897
906 template<size_t N, typename std::enable_if < (N < 9) > ::type* = nullptr>
907 Cdr& serialize(
908 const std::bitset<N>& value)
909 {
910 return serialize(static_cast<uint8_t>(value.to_ulong()));
911 }
912
913 template<size_t N, typename std::enable_if < (8 < N && N < 17) > ::type* = nullptr>
914 Cdr& serialize(
915 const std::bitset<N>& value)
916 {
917 return serialize(static_cast<uint16_t>(value.to_ulong()));
918 }
919
920 template<size_t N, typename std::enable_if < (16 < N && N < 33) > ::type* = nullptr>
921 Cdr& serialize(
922 const std::bitset<N>& value)
923 {
924 return serialize(static_cast<uint32_t>(value.to_ulong()));
925 }
926
927 template<size_t N, typename std::enable_if < (32 < N && N < 65) > ::type* = nullptr>
928 Cdr& serialize(
929 const std::bitset<N>& value)
930 {
931 return serialize(static_cast<uint64_t>(value.to_ullong()));
932 }
933
945 template<class _T>
946 Cdr& serialize_array(
947 const _T* value,
948 size_t num_elements)
949 {
950 for (size_t count = 0; count < num_elements; ++count)
951 {
952 serialize(value[count]);
953 }
954 return *this;
955 }
956
965 template<class _T>
966 Cdr& serialize_array(
967 const _T* type_t,
968 size_t num_elements,
969 Endianness endianness)
970 {
971 bool aux_swap = swap_bytes_;
972 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
973 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
974
975 try
976 {
977 serialize_array(type_t, num_elements);
978 swap_bytes_ = aux_swap;
979 }
980 catch (exception::Exception& ex)
981 {
982 swap_bytes_ = aux_swap;
983 ex.raise();
984 }
985
986 return *this;
987 }
988
996 TEMPLATE_SPEC
997 Cdr& serialize_array(
998 const uint8_t* octet_t,
999 size_t num_elements)
1000 {
1001 return serialize_array(reinterpret_cast<const char*>(octet_t), num_elements);
1002 }
1003
1011 Cdr_DllAPI Cdr& serialize_array(
1012 const char* char_t,
1013 size_t num_elements);
1014
1022 TEMPLATE_SPEC
1023 Cdr& serialize_array(
1024 const int8_t* int8,
1025 size_t num_elements)
1026 {
1027 return serialize_array(reinterpret_cast<const char*>(int8), num_elements);
1028 }
1029
1037 TEMPLATE_SPEC
1038 Cdr& serialize_array(
1039 const uint16_t* ushort_t,
1040 size_t num_elements)
1041 {
1042 return serialize_array(reinterpret_cast<const int16_t*>(ushort_t), num_elements);
1043 }
1044
1052 Cdr_DllAPI Cdr& serialize_array(
1053 const int16_t* short_t,
1054 size_t num_elements);
1055
1063 TEMPLATE_SPEC
1064 Cdr& serialize_array(
1065 const uint32_t* ulong_t,
1066 size_t num_elements)
1067 {
1068 return serialize_array(reinterpret_cast<const int32_t*>(ulong_t), num_elements);
1069 }
1070
1078 Cdr_DllAPI Cdr& serialize_array(
1079 const int32_t* long_t,
1080 size_t num_elements);
1081
1089 Cdr_DllAPI Cdr& serialize_array(
1090 const wchar_t* wchar,
1091 size_t num_elements);
1092
1100 TEMPLATE_SPEC
1101 Cdr& serialize_array(
1102 const uint64_t* ulonglong_t,
1103 size_t num_elements)
1104 {
1105 return serialize_array(reinterpret_cast<const int64_t*>(ulonglong_t), num_elements);
1106 }
1107
1115 Cdr_DllAPI Cdr& serialize_array(
1116 const int64_t* longlong_t,
1117 size_t num_elements);
1118
1126 Cdr_DllAPI Cdr& serialize_array(
1127 const float* float_t,
1128 size_t num_elements);
1129
1137 Cdr_DllAPI Cdr& serialize_array(
1138 const double* double_t,
1139 size_t num_elements);
1140
1149 Cdr_DllAPI Cdr& serialize_array(
1150 const long double* ldouble_t,
1151 size_t num_elements);
1152
1160 Cdr_DllAPI Cdr& serialize_array(
1161 const bool* bool_t,
1162 size_t num_elements);
1163
1171 TEMPLATE_SPEC
1172 Cdr& serialize_array(
1173 const std::string* string_t,
1174 size_t num_elements)
1175 {
1176 for (size_t count = 0; count < num_elements; ++count)
1177 {
1178 serialize(string_t[count].c_str());
1179 }
1180 return *this;
1181 }
1182
1190 TEMPLATE_SPEC
1191 Cdr& serialize_array(
1192 const std::wstring* string_t,
1193 size_t num_elements)
1194 {
1195 for (size_t count = 0; count < num_elements; ++count)
1196 {
1197 serialize(string_t[count].c_str());
1198 }
1199 return *this;
1200 }
1201
1210 template<size_t MAX_CHARS>
1211 Cdr& serialize_array(
1212 const fixed_string<MAX_CHARS>* value,
1213 size_t num_elements)
1214 {
1215 for (size_t count = 0; count < num_elements; ++count)
1216 {
1217 serialize(value[count].c_str());
1218 }
1219 return *this;
1220 }
1221
1229 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1230 std::is_arithmetic<_T>::value>::type* = nullptr>
1231 Cdr& serialize_array(
1232 const std::vector<_T>& value)
1233 {
1234 serialize_array(value.data(), value.size());
1235
1236 return *this;
1237 }
1238
1246 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1247 !std::is_arithmetic<_T>::value>::type* = nullptr>
1248 Cdr& serialize_array(
1249 const std::vector<_T>& value)
1250 {
1251 Cdr::state dheader_state {allocate_xcdrv2_dheader()};
1252
1253 serialize_array(value.data(), value.size());
1254
1255 set_xcdrv2_dheader(dheader_state);
1256
1257 return *this;
1258 }
1259
1268 template<class _T>
1269 Cdr& serialize_array(
1270 const std::vector<_T>& value,
1271 Endianness endianness)
1272 {
1273 bool aux_swap = swap_bytes_;
1274 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
1275 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
1276
1277 try
1278 {
1279 serialize_array(value);
1280 swap_bytes_ = aux_swap;
1281 }
1282 catch (exception::Exception& ex)
1283 {
1284 swap_bytes_ = aux_swap;
1285 ex.raise();
1286 }
1287
1288 return *this;
1289 }
1290
1298 TEMPLATE_SPEC
1299 Cdr& serialize_array(
1300 const std::vector<bool>& value)
1301 {
1302 serialize_bool_array(value);
1303
1304 return *this;
1305 }
1306
1314 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1315 !std::is_arithmetic<_T>::value>::type* = nullptr>
1316 Cdr& serialize_sequence(
1317 const _T* sequence_t,
1318 size_t num_elements)
1319 {
1320 Cdr::state dheader_state {allocate_xcdrv2_dheader()};
1321
1322 serialize(static_cast<int32_t>(num_elements));
1323
1324 try
1325 {
1326 serialize_array(sequence_t, num_elements);
1327 }
1328 catch (exception::Exception& ex)
1329 {
1330 set_state(dheader_state);
1331 ex.raise();
1332 }
1333
1334 set_xcdrv2_dheader(dheader_state);
1335
1336 return *this;
1337 }
1338
1346 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1347 std::is_arithmetic<_T>::value>::type* = nullptr>
1348 Cdr& serialize_sequence(
1349 const _T* sequence_t,
1350 size_t num_elements)
1351 {
1352 state state_before_error(*this);
1353
1354 serialize(static_cast<int32_t>(num_elements));
1355
1356 try
1357 {
1358 serialize_array(sequence_t, num_elements);
1359 }
1360 catch (exception::Exception& ex)
1361 {
1362 set_state(state_before_error);
1363 ex.raise();
1364 }
1365
1366 if (CdrVersion::XCDRv2 == cdr_version_)
1367 {
1368 serialized_member_size_ = get_serialized_member_size<_T>();
1369 }
1370
1371 return *this;
1372 }
1373
1382 template<class _T>
1383 Cdr& serialize_sequence(
1384 const _T* sequence_t,
1385 size_t num_elements,
1386 Endianness endianness)
1387 {
1388 bool aux_swap = swap_bytes_;
1389 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
1390 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
1391
1392 try
1393 {
1394 serialize_sequence(sequence_t, num_elements);
1395 swap_bytes_ = aux_swap;
1396 }
1397 catch (exception::Exception& ex)
1398 {
1399 swap_bytes_ = aux_swap;
1400 ex.raise();
1401 }
1402
1403 return *this;
1404 }
1405
1416 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* = nullptr, typename = void>
1417 Cdr& deserialize(
1418 _T& value)
1419 {
1420 eprosima::fastcdr::deserialize(*this, value);
1421 return *this;
1422 }
1423
1432 template<class _T>
1433 Cdr& deserialize(
1434 _T& value,
1435 Endianness endianness)
1436 {
1437 bool aux_swap = swap_bytes_;
1438 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
1439 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
1440
1441 try
1442 {
1443 deserialize(value);
1444 swap_bytes_ = aux_swap;
1445 }
1446 catch (exception::Exception& ex)
1447 {
1448 swap_bytes_ = aux_swap;
1449 ex.raise();
1450 }
1451
1452 return *this;
1453 }
1454
1462 template<class _T,
1463 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1464 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1465 int32_t>::value>::type* = nullptr>
1466 Cdr& deserialize(
1467 _T& value)
1468 {
1469 int32_t decode_value {0};
1470 deserialize(decode_value);
1471 value = static_cast<_T>(decode_value);
1472 return *this;
1473 }
1474
1482 template<class _T,
1483 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1484 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1485 uint32_t>::value>::type* = nullptr>
1486 Cdr& deserialize(
1487 _T& value)
1488 {
1489 uint32_t decode_value {0};
1490 deserialize(decode_value);
1491 value = static_cast<_T>(decode_value);
1492 return *this;
1493 }
1494
1502 template<class _T,
1503 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1504 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1505 int16_t>::value>::type* = nullptr>
1506 Cdr& deserialize(
1507 _T& value)
1508 {
1509 int16_t decode_value {0};
1510 deserialize(decode_value);
1511 value = static_cast<_T>(decode_value);
1512 return *this;
1513 }
1514
1522 template<class _T,
1523 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1524 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1525 uint16_t>::value>::type* = nullptr>
1526 Cdr& deserialize(
1527 _T& value)
1528 {
1529 uint16_t decode_value {0};
1530 deserialize(decode_value);
1531 value = static_cast<_T>(decode_value);
1532 return *this;
1533 }
1534
1542 template<class _T,
1543 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1544 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1545 int8_t>::value>::type* = nullptr>
1546 Cdr& deserialize(
1547 _T& value)
1548 {
1549 int8_t decode_value {0};
1550 deserialize(decode_value);
1551 value = static_cast<_T>(decode_value);
1552 return *this;
1553 }
1554
1562 template<class _T,
1563 typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr,
1564 typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type,
1565 uint8_t>::value>::type* = nullptr>
1566 Cdr& deserialize(
1567 _T& value)
1568 {
1569 uint8_t decode_value {0};
1570 deserialize(decode_value);
1571 value = static_cast<_T>(decode_value);
1572 return *this;
1573 }
1574
1581 TEMPLATE_SPEC
1582 Cdr& deserialize(
1583 uint8_t& octet_t)
1584 {
1585 return deserialize(reinterpret_cast<char&>(octet_t));
1586 }
1587
1594 Cdr_DllAPI Cdr& deserialize(
1595 char& char_t);
1596
1603 TEMPLATE_SPEC
1604 Cdr& deserialize(
1605 int8_t& int8)
1606 {
1607 return deserialize(reinterpret_cast<char&>(int8));
1608 }
1609
1616 TEMPLATE_SPEC
1617 Cdr& deserialize(
1618 uint16_t& ushort_t)
1619 {
1620 return deserialize(reinterpret_cast<int16_t&>(ushort_t));
1621 }
1622
1629 Cdr_DllAPI Cdr& deserialize(
1630 int16_t& short_t);
1631
1638 TEMPLATE_SPEC
1639 Cdr& deserialize(
1640 uint32_t& ulong_t)
1641 {
1642 return deserialize(reinterpret_cast<int32_t&>(ulong_t));
1643 }
1644
1651 Cdr_DllAPI Cdr& deserialize(
1652 int32_t& long_t);
1653
1660 TEMPLATE_SPEC
1661 Cdr& deserialize(
1662 wchar_t& wchar)
1663 {
1664 uint16_t ret;
1665 deserialize(ret);
1666 wchar = static_cast<wchar_t>(ret);
1667 return *this;
1668 }
1669
1676 TEMPLATE_SPEC
1677 Cdr& deserialize(
1678 uint64_t& ulonglong_t)
1679 {
1680 return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
1681 }
1682
1689 Cdr_DllAPI Cdr& deserialize(
1690 int64_t& longlong_t);
1691
1698 Cdr_DllAPI Cdr& deserialize(
1699 float& float_t);
1700
1707 Cdr_DllAPI Cdr& deserialize(
1708 double& double_t);
1709
1717 Cdr_DllAPI Cdr& deserialize(
1718 long double& ldouble_t);
1719
1727 Cdr_DllAPI Cdr& deserialize(
1728 bool& bool_t);
1729
1738 Cdr_DllAPI Cdr& deserialize(
1739 char*& string_t);
1740
1749 Cdr_DllAPI Cdr& deserialize(
1750 wchar_t*& string_t);
1751
1758 TEMPLATE_SPEC
1759 Cdr& deserialize(
1760 std::string& string_t)
1761 {
1762 uint32_t length = 0;
1763 const char* str = read_string(length);
1764 string_t.assign(str, length);
1765 return *this;
1766 }
1767
1774 TEMPLATE_SPEC
1775 Cdr& deserialize(
1776 std::wstring& string_t)
1777 {
1778 uint32_t length = 0;
1779 string_t = read_wstring(length);
1780 return *this;
1781 }
1782
1790 template <size_t MAX_CHARS>
1791 Cdr& deserialize(
1792 fixed_string<MAX_CHARS>& value)
1793 {
1794 uint32_t length = 0;
1795 const char* str = read_string(length);
1796 value.assign(str, length);
1797 return *this;
1798 }
1799
1806 template<class _T, size_t _Size>
1807 Cdr& deserialize(
1808 std::array<_T, _Size>& array_t)
1809 {
1810 if (CdrVersion::XCDRv2 == cdr_version_ && !is_multi_array_primitive(&array_t))
1811 {
1812 uint32_t dheader {0};
1813 deserialize(dheader);
1814
1815 uint32_t count {0};
1816 auto offset = offset_;
1817 while (offset_ - offset < dheader && count < _Size)
1818 {
1819 deserialize_array(&array_t.data()[count], 1);
1820 ++count;
1821 }
1822
1823 if (offset_ - offset != dheader)
1824 {
1825 throw exception::BadParamException("Member size greater than size specified by DHEADER");
1826 }
1827 }
1828 else
1829 {
1830 return deserialize_array(array_t.data(), array_t.size());
1831 }
1832
1833 return *this;
1834 }
1835
1842 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1843 !std::is_arithmetic<_T>::value>::type* = nullptr>
1844 Cdr& deserialize(
1845 std::vector<_T>& vector_t)
1846 {
1847 uint32_t sequence_length {0};
1848
1849 if (CdrVersion::XCDRv2 == cdr_version_)
1850 {
1851 uint32_t dheader {0};
1852 deserialize(dheader);
1853
1854 auto offset = offset_;
1855
1856 deserialize(sequence_length);
1857
1858 if (0 == sequence_length)
1859 {
1860 vector_t.clear();
1861 return *this;
1862 }
1863 else
1864 {
1865 vector_t.resize(sequence_length);
1866 }
1867
1868 uint32_t count {0};
1869 while (offset_ - offset < dheader && count < sequence_length)
1870 {
1871 deserialize(vector_t.data()[count]);
1872 ++count;
1873 }
1874
1875 if (offset_ - offset != dheader)
1876 {
1877 throw exception::BadParamException("Member size differs from the size specified by DHEADER");
1878 }
1879 }
1880 else
1881 {
1882 state state_before_error(*this);
1883
1884 deserialize(sequence_length);
1885
1886 if (sequence_length == 0)
1887 {
1888 vector_t.clear();
1889 return *this;
1890 }
1891
1892 if ((end_ - offset_) < sequence_length)
1893 {
1894 set_state(state_before_error);
1895 throw exception::NotEnoughMemoryException(
1896 exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1897 }
1898
1899 try
1900 {
1901 vector_t.resize(sequence_length);
1902 return deserialize_array(vector_t.data(), vector_t.size());
1903 }
1904 catch (exception::Exception& ex)
1905 {
1906 set_state(state_before_error);
1907 ex.raise();
1908 }
1909 }
1910
1911 return *this;
1912 }
1913
1920 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1921 std::is_arithmetic<_T>::value>::type* = nullptr>
1922 Cdr& deserialize(
1923 std::vector<_T>& vector_t)
1924 {
1925 uint32_t sequence_length = 0;
1926 state state_before_error(*this);
1927
1928 deserialize(sequence_length);
1929
1930 if (sequence_length == 0)
1931 {
1932 vector_t.clear();
1933 return *this;
1934 }
1935
1936 if ((end_ - offset_) < sequence_length)
1937 {
1938 set_state(state_before_error);
1939 throw exception::NotEnoughMemoryException(
1940 exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1941 }
1942
1943 try
1944 {
1945 vector_t.resize(sequence_length);
1946 return deserialize_array(vector_t.data(), vector_t.size());
1947 }
1948 catch (exception::Exception& ex)
1949 {
1950 set_state(state_before_error);
1951 ex.raise();
1952 }
1953
1954 return *this;
1955 }
1956
1963 TEMPLATE_SPEC
1964 Cdr& deserialize(
1965 std::vector<bool>& vector_t)
1966 {
1967 return deserialize_bool_sequence(vector_t);
1968 }
1969
1976 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1977 !std::is_arithmetic<_T>::value>::type* = nullptr>
1978 Cdr& deserialize(
1979 std::map<_K, _T>& map_t)
1980 {
1981 if (CdrVersion::XCDRv2 == cdr_version_)
1982 {
1983 uint32_t dheader {0};
1984 deserialize(dheader);
1985
1986 auto offset = offset_;
1987
1988 uint32_t map_length {0};
1989 deserialize(map_length);
1990
1991 map_t.clear();
1992
1993 uint32_t count {0};
1994 while (offset_ - offset < dheader && count < map_length)
1995 {
1996 _K key;
1997 _T val;
1998 deserialize(key);
1999 deserialize(val);
2000 map_t.emplace(std::pair<_K, _T>(std::move(key), std::move(val)));
2001 ++count;
2002 }
2003
2004 if (offset_ - offset != dheader)
2005 {
2006 throw exception::BadParamException("Member size greater than size specified by DHEADER");
2007 }
2008 }
2009 else
2010 {
2011 uint32_t sequence_length = 0;
2012 state state_(*this);
2013
2014 deserialize(sequence_length);
2015
2016 map_t.clear();
2017
2018 try
2019 {
2020 for (uint32_t i = 0; i < sequence_length; ++i)
2021 {
2022 _K key;
2023 _T value;
2024 deserialize(key);
2025 deserialize(value);
2026 map_t.emplace(std::pair<_K, _T>(std::move(key), std::move(value)));
2027 }
2028 }
2029 catch (exception::Exception& ex)
2030 {
2031 set_state(state_);
2032 ex.raise();
2033 }
2034 }
2035
2036 return *this;
2037 }
2038
2045 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
2046 std::is_arithmetic<_T>::value>::type* = nullptr>
2047 Cdr& deserialize(
2048 std::map<_K, _T>& map_t)
2049 {
2050 uint32_t sequence_length = 0;
2051 state state_(*this);
2052
2053 deserialize(sequence_length);
2054
2055 try
2056 {
2057 for (uint32_t i = 0; i < sequence_length; ++i)
2058 {
2059 _K key;
2060 _T value;
2061 deserialize(key);
2062 deserialize(value);
2063 map_t.emplace(std::pair<_K, _T>(std::move(key), std::move(value)));
2064 }
2065 }
2066 catch (exception::Exception& ex)
2067 {
2068 set_state(state_);
2069 ex.raise();
2070 }
2071
2072 return *this;
2073 }
2074
2082 template<size_t N, typename std::enable_if < (N < 9) > ::type* = nullptr>
2083 Cdr& deserialize(
2084 std::bitset<N>& value)
2085 {
2086 uint8_t decode_value {0};
2087 deserialize(decode_value);
2088 value = decode_value;
2089 return *this;
2090 }
2091
2092 template<size_t N, typename std::enable_if < (8 < N && N < 17) > ::type* = nullptr>
2093 Cdr& deserialize(
2094 std::bitset<N>& value)
2095 {
2096 uint16_t decode_value {0};
2097 deserialize(decode_value);
2098 value = decode_value;
2099 return *this;
2100 }
2101
2102 template<size_t N, typename std::enable_if < (16 < N && N < 33) > ::type* = nullptr>
2103 Cdr& deserialize(
2104 std::bitset<N>& value)
2105 {
2106 uint32_t decode_value {0};
2107 deserialize(decode_value);
2108 value = decode_value;
2109 return *this;
2110 }
2111
2112 template<size_t N, typename std::enable_if < (32 < N && N < 65) > ::type* = nullptr>
2113 Cdr& deserialize(
2114 std::bitset<N>& value)
2115 {
2116 uint64_t decode_value {0};
2117 deserialize(decode_value);
2118 value = decode_value;
2119 return *this;
2120 }
2121
2133 template<class _T>
2134 Cdr& deserialize_array(
2135 _T* value,
2136 size_t num_elements)
2137 {
2138 for (size_t count = 0; count < num_elements; ++count)
2139 {
2140 deserialize(value[count]);
2141 }
2142 return *this;
2143 }
2144
2153 template<class _T>
2154 Cdr& deserialize_array(
2155 _T* type_t,
2156 size_t num_elements,
2157 Endianness endianness)
2158 {
2159 bool aux_swap = swap_bytes_;
2160 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
2161 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
2162
2163 try
2164 {
2165 deserialize_array(type_t, num_elements);
2166 swap_bytes_ = aux_swap;
2167 }
2168 catch (exception::Exception& ex)
2169 {
2170 swap_bytes_ = aux_swap;
2171 ex.raise();
2172 }
2173
2174 return *this;
2175 }
2176
2184 TEMPLATE_SPEC
2185 Cdr& deserialize_array(
2186 uint8_t* octet_t,
2187 size_t num_elements)
2188 {
2189 return deserialize_array(reinterpret_cast<char*>(octet_t), num_elements);
2190 }
2191
2199 Cdr_DllAPI Cdr& deserialize_array(
2200 char* char_t,
2201 size_t num_elements);
2202
2210 TEMPLATE_SPEC
2211 Cdr& deserialize_array(
2212 int8_t* int8,
2213 size_t num_elements)
2214 {
2215 return deserialize_array(reinterpret_cast<char*>(int8), num_elements);
2216 }
2217
2225 TEMPLATE_SPEC
2226 Cdr& deserialize_array(
2227 uint16_t* ushort_t,
2228 size_t num_elements)
2229 {
2230 return deserialize_array(reinterpret_cast<int16_t*>(ushort_t), num_elements);
2231 }
2232
2240 Cdr_DllAPI Cdr& deserialize_array(
2241 int16_t* short_t,
2242 size_t num_elements);
2243
2251 TEMPLATE_SPEC
2252 Cdr& deserialize_array(
2253 uint32_t* ulong_t,
2254 size_t num_elements)
2255 {
2256 return deserialize_array(reinterpret_cast<int32_t*>(ulong_t), num_elements);
2257 }
2258
2266 Cdr_DllAPI Cdr& deserialize_array(
2267 int32_t* long_t,
2268 size_t num_elements);
2269
2277 Cdr_DllAPI Cdr& deserialize_array(
2278 wchar_t* wchar,
2279 size_t num_elements);
2280
2288 TEMPLATE_SPEC
2289 Cdr& deserialize_array(
2290 uint64_t* ulonglong_t,
2291 size_t num_elements)
2292 {
2293 return deserialize_array(reinterpret_cast<int64_t*>(ulonglong_t), num_elements);
2294 }
2295
2303 Cdr_DllAPI Cdr& deserialize_array(
2304 int64_t* longlong_t,
2305 size_t num_elements);
2306
2314 Cdr_DllAPI Cdr& deserialize_array(
2315 float* float_t,
2316 size_t num_elements);
2317
2325 Cdr_DllAPI Cdr& deserialize_array(
2326 double* double_t,
2327 size_t num_elements);
2328
2337 Cdr_DllAPI Cdr& deserialize_array(
2338 long double* ldouble_t,
2339 size_t num_elements);
2340
2348 Cdr_DllAPI Cdr& deserialize_array(
2349 bool* bool_t,
2350 size_t num_elements);
2351
2362 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2363 std::is_arithmetic<_T>::value>::type* = nullptr>
2364 Cdr& deserialize_array(
2365 std::vector<_T>& value)
2366 {
2367 deserialize_array(value.data(), value.size());
2368
2369 return *this;
2370 }
2371
2382 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2383 !std::is_arithmetic<_T>::value>::type* = nullptr>
2384 Cdr& deserialize_array(
2385 std::vector<_T>& value)
2386 {
2387 if (CdrVersion::XCDRv2 == cdr_version_)
2388 {
2389 uint32_t dheader {0};
2390 deserialize(dheader);
2391
2392 uint32_t count {0};
2393 auto offset = offset_;
2394 while (offset_ - offset < dheader && count < value.size())
2395 {
2396 deserialize_array(&value.data()[count], 1);
2397 ++count;
2398 }
2399
2400 if (offset_ - offset != dheader)
2401 {
2402 throw exception::BadParamException("Member size greater than size specified by DHEADER");
2403 }
2404 }
2405 else
2406 {
2407 return deserialize_array(value.data(), value.size());
2408 }
2409
2410 return *this;
2411 }
2412
2424 template<class _T>
2425 Cdr& deserialize_array(
2426 std::vector<_T>& value,
2427 Endianness endianness)
2428 {
2429 bool aux_swap = swap_bytes_;
2430 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
2431 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
2432
2433 try
2434 {
2435 deserialize_array(value);
2436 swap_bytes_ = aux_swap;
2437 }
2438 catch (exception::Exception& ex)
2439 {
2440 swap_bytes_ = aux_swap;
2441 ex.raise();
2442 }
2443
2444 return *this;
2445 }
2446
2457 TEMPLATE_SPEC
2458 Cdr& deserialize_array(
2459 std::vector<bool>& value)
2460 {
2461 deserialize_bool_array(value);
2462
2463 return *this;
2464 }
2465
2475 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2476 !std::is_arithmetic<_T>::value>::type* = nullptr>
2477 Cdr& deserialize_sequence(
2478 _T*& sequence_t,
2479 size_t& num_elements)
2480 {
2481 uint32_t sequence_length {0};
2482
2483 if (CdrVersion::XCDRv2 == cdr_version_)
2484 {
2485 uint32_t dheader {0};
2486 deserialize(dheader);
2487
2488 auto offset = offset_;
2489
2490 deserialize(sequence_length);
2491
2492 try
2493 {
2494 sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
2495
2496 uint32_t count {0};
2497 while (offset_ - offset < dheader && count < sequence_length)
2498 {
2499 deserialize(sequence_t[count]);
2500 ++count;
2501 }
2502
2503 if (offset_ - offset != dheader)
2504 {
2505 throw exception::BadParamException("Member size greater than size specified by DHEADER");
2506 }
2507 }
2508 catch (exception::Exception& ex)
2509 {
2510 free(sequence_t);
2511 sequence_t = NULL;
2512 ex.raise();
2513 }
2514 }
2515 else
2516 {
2517 state state_before_error(*this);
2518
2519 deserialize(sequence_length);
2520
2521 if ((end_ - offset_) < sequence_length)
2522 {
2523 set_state(state_before_error);
2524 throw exception::NotEnoughMemoryException(
2525 exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2526 }
2527
2528 try
2529 {
2530 sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
2531 deserialize_array(sequence_t, sequence_length);
2532 }
2533 catch (exception::Exception& ex)
2534 {
2535 free(sequence_t);
2536 sequence_t = NULL;
2537 set_state(state_before_error);
2538 ex.raise();
2539 }
2540 }
2541
2542 num_elements = sequence_length;
2543 return *this;
2544 }
2545
2555 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2556 std::is_arithmetic<_T>::value>::type* = nullptr>
2557 Cdr& deserialize_sequence(
2558 _T*& sequence_t,
2559 size_t& num_elements)
2560 {
2561 uint32_t sequence_length = 0;
2562 state state_before_error(*this);
2563
2564 deserialize(sequence_length);
2565
2566 try
2567 {
2568 sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
2569 deserialize_array(sequence_t, sequence_length);
2570 }
2571 catch (exception::Exception& ex)
2572 {
2573 free(sequence_t);
2574 sequence_t = NULL;
2575 set_state(state_before_error);
2576 ex.raise();
2577 }
2578
2579 num_elements = sequence_length;
2580 return *this;
2581 }
2582
2593 template<class _T>
2594 Cdr& deserialize_sequence(
2595 _T*& sequence_t,
2596 size_t& num_elements,
2597 Endianness endianness)
2598 {
2599 bool aux_swap = swap_bytes_;
2600 swap_bytes_ = (swap_bytes_ && (static_cast<Endianness>(endianness_) == endianness)) ||
2601 (!swap_bytes_ && (static_cast<Endianness>(endianness_) != endianness));
2602
2603 try
2604 {
2605 deserialize_sequence(sequence_t, num_elements);
2606 swap_bytes_ = aux_swap;
2607 }
2608 catch (exception::Exception& ex)
2609 {
2610 swap_bytes_ = aux_swap;
2611 ex.raise();
2612 }
2613
2614 return *this;
2615 }
2616
2626 TEMPLATE_SPEC
2627 Cdr& deserialize_sequence(
2628 std::string*& sequence_t,
2629 size_t& num_elements)
2630 {
2631 return deserialize_string_sequence(sequence_t, num_elements);
2632 }
2633
2643 TEMPLATE_SPEC
2644 Cdr& deserialize_sequence(
2645 std::wstring*& sequence_t,
2646 size_t& num_elements)
2647 {
2648 return deserialize_wstring_sequence(sequence_t, num_elements);
2649 }
2650
2654
2665 template<class _T>
2666 Cdr& serialize_member(
2667 const MemberId& member_id,
2668 const _T& member_value,
2669 XCdrHeaderSelection header_selection = XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
2670 {
2671 Cdr::state current_state(*this);
2672 (this->*begin_serialize_member_)(member_id, true, current_state, header_selection);
2673 serialize(member_value);
2674 return (this->*end_serialize_member_)(current_state);
2675 }
2676
2687 template<class _T>
2688 Cdr& serialize_member(
2689 const MemberId& member_id,
2690 const optional<_T>& member_value,
2691 XCdrHeaderSelection header_selection = XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
2692 {
2693 Cdr::state current_state(*this);
2694 (this->*begin_serialize_opt_member_)(member_id, member_value.has_value(), current_state, header_selection);
2695 serialize(member_value);
2696 return (this->*end_serialize_opt_member_)(current_state);
2697 }
2698
2706 template<class _T>
2707 Cdr& deserialize_member(
2708 _T& member_value)
2709 {
2710 return deserialize(member_value);
2711 }
2712
2720 template<class _T>
2721 Cdr& deserialize_member(
2722 optional<_T>& member_value)
2723 {
2724 if (EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_)
2725 {
2726 Cdr::state current_state(*this);
2727 MemberId member_id;
2728 xcdr1_deserialize_member_header(member_id, current_state);
2729 auto prev_offset = offset_;
2730 if (0 < current_state.member_size_)
2731 {
2732 deserialize(member_value);
2733 }
2734 size_t member_size {current_state.member_size_};
2735 size_t diff {offset_ - prev_offset};
2736 if (member_size < diff)
2737 {
2738 throw exception::BadParamException(
2739 "Member size provided by member header is lower than real decoded member size");
2740 }
2741
2742 // Skip unused bytes
2743 offset_ += (member_size - diff);
2744 }
2745 else
2746 {
2747 deserialize(member_value);
2748 }
2749 return *this;
2750 }
2751
2760 Cdr_DllAPI Cdr& begin_serialize_type(
2761 Cdr::state& current_state,
2762 EncodingAlgorithmFlag type_encoding);
2763
2771 Cdr_DllAPI Cdr& end_serialize_type(
2772 Cdr::state& current_state);
2773
2782 Cdr_DllAPI Cdr& deserialize_type(
2783 EncodingAlgorithmFlag type_encoding,
2784 std::function<bool (Cdr&, const MemberId&)> functor);
2785
2793 template<class _T>
2794 Cdr& serialize(
2795 const optional<_T>& value)
2796 {
2797 if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 != current_encoding_)
2798 {
2799 serialize(value.has_value());
2800 }
2801
2802 if (value.has_value())
2803 {
2804 serialize(*value);
2805 }
2806 return *this;
2807 }
2808
2817 template<class _T>
2818 Cdr& serialize(
2819 const external<_T>& value)
2820 {
2821 if (!value)
2822 {
2823 throw exception::BadParamException("External member is null");
2824 }
2825
2826 serialize(*value);
2827 return *this;
2828 }
2829
2837 Cdr_DllAPI Cdr& operator <<(
2838 const MemberId& member_id);
2839
2847 template<class _T>
2848 Cdr& deserialize(
2849 optional<_T>& value)
2850 {
2851 bool is_present = true;
2852 if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 != current_encoding_)
2853 {
2854 deserialize(is_present);
2855 }
2856 value.reset(is_present);
2857 if (is_present)
2858 {
2859 deserialize(*value);
2860 }
2861 return *this;
2862 }
2863
2872 template<class _T>
2873 Cdr& deserialize(
2874 external<_T>& value)
2875 {
2876 if (value.is_locked())
2877 {
2878 throw exception::BadParamException("External member is locked");
2879 }
2880
2881 if (!value)
2882 {
2883 value = external<_T>{new typename external<_T>::type()};
2884 }
2885
2886 deserialize(*value);
2887 return *this;
2888 }
2889
2898 template<class _T>
2899 Cdr& deserialize(
2900 optional<external<_T>>& value)
2901 {
2902 if (value.has_value() && value.value().is_locked())
2903 {
2904 throw exception::BadParamException("External member is locked");
2905 }
2906
2907 bool is_present = true;
2908 if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 != current_encoding_)
2909 {
2910 deserialize(is_present);
2911 }
2912 value.reset(is_present);
2913 if (is_present)
2914 {
2915 deserialize(*value);
2916 }
2917 return *this;
2918 }
2919
2925 Cdr_DllAPI state allocate_xcdrv2_dheader();
2926
2933 Cdr_DllAPI void set_xcdrv2_dheader(
2934 const state& state);
2935
2936 private:
2937
2938 Cdr(
2939 const Cdr&) = delete;
2940
2941 Cdr& operator =(
2942 const Cdr&) = delete;
2943
2944 Cdr_DllAPI Cdr& serialize_bool_array(
2945 const std::vector<bool>& vector_t);
2946
2947 Cdr_DllAPI Cdr& serialize_bool_sequence(
2948 const std::vector<bool>& vector_t);
2949
2950 Cdr_DllAPI Cdr& deserialize_bool_array(
2951 std::vector<bool>& vector_t);
2952
2953 Cdr_DllAPI Cdr& deserialize_bool_sequence(
2954 std::vector<bool>& vector_t);
2955
2956 Cdr_DllAPI Cdr& deserialize_string_sequence(
2957 std::string*& sequence_t,
2958 size_t& num_elements);
2959
2960 Cdr_DllAPI Cdr& deserialize_wstring_sequence(
2961 std::wstring*& sequence_t,
2962 size_t& num_elements);
2963
2971 template<class _T, size_t _Size>
2972 Cdr& serialize_array(
2973 const std::array<_T, _Size>* array_t,
2974 size_t num_elements)
2975 {
2976 return serialize_array(array_t->data(), num_elements * array_t->size());
2977 }
2978
2986 template<class _T, size_t _Size>
2987 Cdr& deserialize_array(
2988 std::array<_T, _Size>* array_t,
2989 size_t num_elements)
2990 {
2991 return deserialize_array(array_t->data(), num_elements * array_t->size());
2992 }
2993
3002 template<class _T, size_t _Size>
3003 Cdr& deserialize_array(
3004 std::array<_T, _Size>* array_t,
3005 size_t num_elements,
3006 Endianness endianness)
3007 {
3008 return deserialize_array(array_t->data(), num_elements * array_t->size(), endianness);
3009 }
3010
3017 inline size_t alignment(
3018 size_t data_size) const
3019 {
3020 return data_size > last_data_size_ ? (data_size - ((offset_ - origin_) % data_size)) & (data_size - 1) : 0;
3021 }
3022
3027 inline void make_alignment(
3028 size_t align)
3029 {
3030 offset_ += align;
3031 last_data_size_ = 0;
3032 }
3033
3039 bool resize(
3040 size_t min_size_inc);
3041
3042 Cdr_DllAPI const char* read_string(
3043 uint32_t& length);
3044 Cdr_DllAPI const std::wstring read_wstring(
3045 uint32_t& length);
3046
3050
3057 void xcdr1_serialize_short_member_header(
3058 const MemberId& member_id);
3059
3069 void xcdr1_end_short_member_header(
3070 const MemberId& member_id,
3071 size_t member_serialized_size);
3072
3079 void xcdr1_serialize_long_member_header(
3080 const MemberId& member_id);
3081
3089 void xcdr1_end_long_member_header(
3090 const MemberId& member_id,
3091 size_t member_serialized_size);
3092
3102 void xcdr1_change_to_short_member_header(
3103 const MemberId& member_id,
3104 size_t member_serialized_size);
3105
3113 void xcdr1_change_to_long_member_header(
3114 const MemberId& member_id,
3115 size_t member_serialized_size);
3116
3125 Cdr_DllAPI bool xcdr1_deserialize_member_header(
3126 MemberId& member_id,
3127 Cdr::state& current_state);
3128
3136 void xcdr2_serialize_short_member_header(
3137 const MemberId& member_id);
3138
3148 void xcdr2_end_short_member_header(
3149 const MemberId& member_id,
3150 size_t member_serialized_size);
3151
3159 void xcdr2_serialize_long_member_header(
3160 const MemberId& member_id);
3161
3170 void xcdr2_end_long_member_header(
3171 const MemberId& member_id,
3172 size_t member_serialized_size);
3173
3183 void xcdr2_change_to_short_member_header(
3184 const MemberId& member_id,
3185 size_t member_serialized_size);
3186
3195 void xcdr2_change_to_long_member_header(
3196 const MemberId& member_id,
3197 size_t member_serialized_size);
3198
3207 void xcdr2_shrink_to_long_member_header(
3208 const MemberId& member_id,
3209 const FastBuffer::iterator& offset);
3210
3219 void xcdr2_deserialize_member_header(
3220 MemberId& member_id,
3221 Cdr::state& current_state);
3222
3239 Cdr& xcdr1_begin_serialize_member(
3240 const MemberId& member_id,
3241 bool is_present,
3242 Cdr::state& current_state,
3243 XCdrHeaderSelection header_selection);
3244
3255 Cdr& xcdr1_end_serialize_member(
3256 const Cdr::state& current_state);
3257
3273 Cdr& xcdr1_begin_serialize_opt_member(
3274 const MemberId& member_id,
3275 bool is_present,
3276 Cdr::state& current_state,
3277 XCdrHeaderSelection header_selection);
3278
3289 Cdr& xcdr1_end_serialize_opt_member(
3290 const Cdr::state& current_state);
3291
3308 Cdr& xcdr2_begin_serialize_member(
3309 const MemberId& member_id,
3310 bool is_present,
3311 Cdr::state& current_state,
3312 XCdrHeaderSelection header_selection);
3313
3324 Cdr& xcdr2_end_serialize_member(
3325 const Cdr::state& current_state);
3326
3336 Cdr& xcdr1_begin_serialize_type(
3337 Cdr::state& current_state,
3338 EncodingAlgorithmFlag type_encoding) noexcept;
3339
3348 Cdr& xcdr1_end_serialize_type(
3349 const Cdr::state& current_state);
3350
3364 Cdr& xcdr2_begin_serialize_type(
3365 Cdr::state& current_state,
3366 EncodingAlgorithmFlag type_encoding);
3367
3377 Cdr& xcdr2_end_serialize_type(
3378 const Cdr::state& current_state);
3379
3392 Cdr& xcdr1_deserialize_type(
3393 EncodingAlgorithmFlag type_encoding,
3394 std::function<bool (Cdr&, const MemberId&)> functor);
3395
3409 Cdr& xcdr2_deserialize_type(
3410 EncodingAlgorithmFlag type_encoding,
3411 std::function<bool (Cdr&, const MemberId&)> functor);
3412
3413 Cdr& cdr_begin_serialize_member(
3414 const MemberId& member_id,
3415 bool is_present,
3416 Cdr::state& current_state,
3417 XCdrHeaderSelection header_selection);
3418
3419 Cdr& cdr_end_serialize_member(
3420 const Cdr::state& current_state);
3421
3422 Cdr& cdr_begin_serialize_type(
3423 Cdr::state& current_state,
3424 EncodingAlgorithmFlag type_encoding);
3425
3426 Cdr& cdr_end_serialize_type(
3427 const Cdr::state& current_state);
3428
3429 Cdr& cdr_deserialize_type(
3430 EncodingAlgorithmFlag type_encoding,
3431 std::function<bool (Cdr&, const MemberId&)> functor);
3432
3436 void reset_callbacks();
3437
3438 using begin_serialize_member_functor = Cdr& (Cdr::*)(
3439 const MemberId&,
3440 bool,
3441 Cdr::state&,
3442 XCdrHeaderSelection);
3443 begin_serialize_member_functor begin_serialize_member_ { nullptr };
3444
3445 using end_serialize_member_functor = Cdr& (Cdr::*)(
3446 const Cdr::state&);
3447 end_serialize_member_functor end_serialize_member_ { nullptr };
3448
3449 using begin_serialize_opt_member_functor = Cdr& (Cdr::*)(
3450 const MemberId&,
3451 bool,
3452 Cdr::state&,
3453 XCdrHeaderSelection);
3454 begin_serialize_opt_member_functor begin_serialize_opt_member_ { nullptr };
3455
3456 using end_serialize_memberopt__functor = Cdr& (Cdr::*)(
3457 const Cdr::state&);
3458 end_serialize_member_functor end_serialize_opt_member_ { nullptr };
3459
3460 using begin_serialize_type_functor = Cdr& (Cdr::*)(
3461 Cdr::state&,
3462 EncodingAlgorithmFlag);
3463 begin_serialize_type_functor begin_serialize_type_ { nullptr };
3464
3465 using end_serialize_type_functor = Cdr& (Cdr::*)(
3466 const Cdr::state&);
3467 end_serialize_type_functor end_serialize_type_ { nullptr };
3468
3469 using deserialize_type_functor = Cdr& (Cdr::*)(
3470 EncodingAlgorithmFlag,
3471 std::function<bool (Cdr&, const MemberId&)>);
3472 deserialize_type_functor deserialize_type_ { nullptr };
3473
3475 FastBuffer& cdr_buffer_;
3476
3478 CdrVersion cdr_version_ {CdrVersion::XCDRv2};
3479
3481 EncodingAlgorithmFlag encoding_flag_ {EncodingAlgorithmFlag::PLAIN_CDR2};
3482
3484 EncodingAlgorithmFlag current_encoding_ {EncodingAlgorithmFlag::PLAIN_CDR2};
3485
3487 std::array<uint8_t, 2> options_{{0}};
3488
3490 uint8_t endianness_ {Endianness::LITTLE_ENDIANNESS};
3491
3493 bool swap_bytes_ {false};
3494
3496 size_t last_data_size_ {0};
3497
3499 FastBuffer::iterator offset_;
3500
3502 FastBuffer::iterator origin_;
3503
3505 FastBuffer::iterator end_;
3506
3508 MemberId next_member_id_;
3509
3511 size_t align64_ {4};
3512
3517 enum SerializedMemberSizeForNextInt
3518 {
3519 NO_SERIALIZED_MEMBER_SIZE,
3520 SERIALIZED_MEMBER_SIZE,
3521 SERIALIZED_MEMBER_SIZE_4,
3522 SERIALIZED_MEMBER_SIZE_8
3523 }
3525 serialized_member_size_ {NO_SERIALIZED_MEMBER_SIZE};
3526
3528 state initial_state_;
3529
3531 bool encapsulation_serialized_ {false};
3532
3533
3534 uint32_t get_long_lc(
3535 SerializedMemberSizeForNextInt serialized_member_size);
3536
3537 uint32_t get_short_lc(
3538 size_t member_serialized_size);
3539
3540 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
3541 std::is_arithmetic<_T>::value>::type* = nullptr>
3542 constexpr SerializedMemberSizeForNextInt get_serialized_member_size() const
3543 {
3544 return (1 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE :
3545 (4 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE_4 :
3546 (8 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE_8 : NO_SERIALIZED_MEMBER_SIZE)));
3547 }
3548
3549};
3550
3551} //namespace fastcdr
3552} //namespace eprosima
3553
3554#endif // _CDR_CDR_H_
eprosima::fastcdr::Cdr::state
This class stores the current state of a CDR serialization.
Definition Cdr.h:106
eprosima::fastcdr::Cdr::state::Cdr
friend class Cdr
Definition Cdr.h:107
eprosima::fastcdr::Cdr::state::state
Cdr_DllAPI state(const Cdr &cdr)
Default constructor.
eprosima::fastcdr::Cdr::state::state
Cdr_DllAPI state(const state &state)
Copy constructor.
eprosima::fastcdr::Cdr::state::operator==
Cdr_DllAPI bool operator==(const state &other_state) const
Compares two states.
eprosima::fastcdr::Cdr
This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an...
Definition Cdr.h:69
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const int16_t short_t)
This function serializes a short.
eprosima::fastcdr::Cdr::reset_alignment
void reset_alignment()
This function resets the alignment to the current position in the buffer.
Definition Cdr.h:306
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wide-strings.
Definition Cdr.h:1191
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(char *char_t, size_t num_elements)
This function deserializes an array of characters.
eprosima::fastcdr::Cdr::serialize
TEMPLATE_SPEC Cdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
Definition Cdr.h:710
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const int32_t long_t)
This function serializes a long.
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const long double ldouble_t)
This function serializes a long double.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const optional< _T > &value)
Encodes an optional in the buffer.
Definition Cdr.h:2794
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Definition Cdr.h:2226
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
Definition Cdr.h:1617
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(long double *ldouble_t, size_t num_elements)
This function deserializes an array of long doubles.
eprosima::fastcdr::Cdr::change_endianness
Cdr_DllAPI void change_endianness(Endianness endianness)
This function sets the current endianness used by the CDR type.
eprosima::fastcdr::Cdr::begin_serialize_type
Cdr_DllAPI Cdr & begin_serialize_type(Cdr::state &current_state, EncodingAlgorithmFlag type_encoding)
Tells to the encoder a new type and its members starts to be encoded.
eprosima::fastcdr::Cdr::deserialize_array
Cdr & deserialize_array(std::vector< _T > &value)
Decodes an array of primitives on a std::vector.
Definition Cdr.h:2364
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Definition Cdr.h:1101
eprosima::fastcdr::Cdr::DEFAULT_ENDIAN
static Cdr_DllAPI const Endianness DEFAULT_ENDIAN
Default endianess in the system.
Definition Cdr.h:84
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
Definition Cdr.h:1064
eprosima::fastcdr::Cdr::deserialize_member
Cdr & deserialize_member(optional< _T > &member_value)
Decodes an optional member of a type according to the encoding algorithm used.
Definition Cdr.h:2721
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const float float_t)
This function serializes a float.
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
Definition Cdr.h:1807
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Definition Cdr.h:1604
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const float *float_t, size_t num_elements)
This function serializes an array of floats.
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Definition Cdr.h:1759
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(bool &bool_t)
This function deserializes a boolean.
eprosima::fastcdr::Cdr::get_serialized_data_length
Cdr_DllAPI size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const int32_t *long_t, size_t num_elements)
This function serializes an array of longs.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence of non-primitive.
Definition Cdr.h:764
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(int32_t *long_t, size_t num_elements)
This function deserializes an array of longs.
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(wchar_t *wchar, size_t num_elements)
This function deserializes an array of wide-chars.
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const uint8_t &octet_t)
This function serializes an octet.
eprosima::fastcdr::Cdr::XCdrHeaderSelection
XCdrHeaderSelection
Used to decide, in encoding algorithms where member headers support a short header version and a long...
Definition Cdr.h:91
eprosima::fastcdr::Cdr::AUTO_WITH_SHORT_HEADER_BY_DEFAULT
@ AUTO_WITH_SHORT_HEADER_BY_DEFAULT
Initially a short member header is allocated but can be changed to the longer version.
Definition Cdr.h:97
eprosima::fastcdr::Cdr::SHORT_HEADER
@ SHORT_HEADER
Initially a short member header is allocated and cannot be changed. This option may cause an exceptio...
Definition Cdr.h:93
eprosima::fastcdr::Cdr::AUTO_WITH_LONG_HEADER_BY_DEFAULT
@ AUTO_WITH_LONG_HEADER_BY_DEFAULT
Initially a long member header is allocated but can be changed to the shorter version.
Definition Cdr.h:99
eprosima::fastcdr::Cdr::LONG_HEADER
@ LONG_HEADER
Initially a long member header is allocated and cannot be changed.
Definition Cdr.h:95
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const bool *bool_t, size_t num_elements)
This function serializes an array of booleans.
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
Definition Cdr.h:1639
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const int16_t *short_t, size_t num_elements)
This function serializes an array of shorts.
eprosima::fastcdr::Cdr::deserialize_sequence
Cdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements, Endianness endianness)
This function template deserializes a raw sequence with a different endianness.
Definition Cdr.h:2594
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
Definition Cdr.h:997
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(std::map< _K, _T > &map_t)
This function template deserializes a map of non-primitive.
Definition Cdr.h:1978
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(char *&string_t)
This function deserializes a string.
eprosima::fastcdr::Cdr::set_dds_cdr_options
Cdr_DllAPI void set_dds_cdr_options(const std::array< uint8_t, 2 > &options)
This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
eprosima::fastcdr::Cdr::end_serialize_type
Cdr_DllAPI Cdr & end_serialize_type(Cdr::state &current_state)
Tells to the encoder the encoding of the type finishes.
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(long double &ldouble_t)
This function deserializes a long double.
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(double &double_t)
This function deserializes a double.
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
Definition Cdr.h:1661
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(optional< external< _T > > &value)
Decodes an optional of an external from the buffer.
Definition Cdr.h:2899
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const _T *value, size_t num_elements)
Encodes an array of a type not managed by this encoder into the buffer.
Definition Cdr.h:946
eprosima::fastcdr::Cdr::get_dds_cdr_options
Cdr_DllAPI std::array< uint8_t, 2 > get_dds_cdr_options() const
This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
eprosima::fastcdr::Cdr::deserialize_member
Cdr & deserialize_member(_T &member_value)
Decodes a member of a type according to the encoding algorithm used.
Definition Cdr.h:2707
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const char *char_t, size_t num_elements)
This function serializes an array of characters.
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(_T &value, Endianness endianness)
Decodes the value of a type with a different endianness.
Definition Cdr.h:1433
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
Definition Cdr.h:2211
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const int64_t longlong_t)
This function serializes a long long.
eprosima::fastcdr::Cdr::get_current_position
Cdr_DllAPI char * get_current_position()
This function returns the current position in the CDR stream.
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const char *string_t)
This function serializes a string.
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
Definition Cdr.h:1417
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(wchar_t *&string_t)
This function deserializes a wide-string.
eprosima::fastcdr::Cdr::Endianness
Endianness
This enumeration represents endianness types.
Definition Cdr.h:76
eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS
@ LITTLE_ENDIANNESS
Little endianness.
Definition Cdr.h:80
eprosima::fastcdr::Cdr::BIG_ENDIANNESS
@ BIG_ENDIANNESS
Big endianness.
Definition Cdr.h:78
eprosima::fastcdr::Cdr::endianness
Cdr_DllAPI Endianness endianness() const
This function returns the current endianness used by the CDR type.
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const std::vector< _T > &value, Endianness endianness)
Encodes an std::vector as an array with a different endianness.
Definition Cdr.h:1269
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Definition Cdr.h:1677
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const double double_t)
This function serializes a double.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const std::map< _K, _T > &map_t)
This function template serializes a map of non-primitive.
Definition Cdr.h:840
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(float *float_t, size_t num_elements)
This function deserializes an array of floats.
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
Definition Cdr.h:1023
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const std::vector< bool > &value)
Encodes an std::vector of booleans as an array.
Definition Cdr.h:1299
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const int64_t *longlong_t, size_t num_elements)
This function serializes an array of long longs.
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(int16_t *short_t, size_t num_elements)
This function deserializes an array of shorts.
eprosima::fastcdr::Cdr::deserialize_array
Cdr & deserialize_array(_T *type_t, size_t num_elements, Endianness endianness)
This function template deserializes an array of non-basic objects with a different endianness.
Definition Cdr.h:2154
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const fixed_string< MAX_CHARS > *value, size_t num_elements)
Encodes an array of fixed strings.
Definition Cdr.h:1211
eprosima::fastcdr::Cdr::serialize_sequence
Cdr & serialize_sequence(const _T *sequence_t, size_t num_elements, Endianness endianness)
This function template serializes a raw sequence with a different endianness.
Definition Cdr.h:1383
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(char &char_t)
This function deserializes a character.
eprosima::fastcdr::Cdr::deserialize_sequence
Cdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence of non-primitives.
Definition Cdr.h:2477
eprosima::fastcdr::Cdr::deserialize_array
Cdr & deserialize_array(_T *value, size_t num_elements)
Decodes an array of a type not managed by this encoder from the buffer.
Definition Cdr.h:2134
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const wchar_t *string_t)
This function serializes a wstring.
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
Definition Cdr.h:2185
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const std::vector< _T > &value)
Encodes an std::vector of primitives as an array.
Definition Cdr.h:1231
eprosima::fastcdr::Cdr::jump
Cdr_DllAPI bool jump(size_t num_bytes)
This function skips a number of bytes in the CDR stream buffer.
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
Definition Cdr.h:2289
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const fixed_string< MAX_CHARS > &value)
Encodes a eprosima::fastcdr::fixed_string in the buffer.
Definition Cdr.h:724
eprosima::fastcdr::Cdr::deserialize_sequence
TEMPLATE_SPEC Cdr & deserialize_sequence(std::string *&sequence_t, size_t &num_elements)
This function template deserializes a string sequence.
Definition Cdr.h:2627
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence.
Definition Cdr.h:1964
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const char char_t)
This function serializes a character.
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(std::vector< bool > &value)
Decodes an array of booleans on a std::vector.
Definition Cdr.h:2458
eprosima::fastcdr::Cdr::serialize_encapsulation
Cdr_DllAPI Cdr & serialize_encapsulation()
This function writes the encapsulation of the CDR stream.
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition Cdr.h:1582
eprosima::fastcdr::Cdr::reset
Cdr_DllAPI void reset()
This function resets the current position in the buffer to the beginning.
eprosima::fastcdr::Cdr::deserialize_type
Cdr_DllAPI Cdr & deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members starts to be decoded.
eprosima::fastcdr::Cdr::serialize
TEMPLATE_SPEC Cdr & serialize(const std::string &string_t)
This function serializes a std::string.
Definition Cdr.h:689
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const wchar_t *wchar, size_t num_elements)
This function serializes an array of wide-chars.
eprosima::fastcdr::Cdr::get_buffer_pointer
Cdr_DllAPI char * get_buffer_pointer()
This function returns the pointer to the current used buffer.
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(optional< _T > &value)
Decodes an optional from the buffer.
Definition Cdr.h:2848
eprosima::fastcdr::Cdr::get_state
Cdr_DllAPI state get_state() const
Returns the current state of the CDR serialization process.
eprosima::fastcdr::Cdr::get_encoding_flag
Cdr_DllAPI EncodingAlgorithmFlag get_encoding_flag() const
Returns the EncodingAlgorithmFlag set in the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
eprosima::fastcdr::Cdr::operator>>
Cdr & operator>>(_T &value)
Decodes the value from the buffer.
Definition Cdr.h:356
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(double *double_t, size_t num_elements)
This function deserializes an array of doubles.
eprosima::fastcdr::Cdr::set_encoding_flag
Cdr_DllAPI bool set_encoding_flag(EncodingAlgorithmFlag encoding_flag)
Sets the EncodingAlgorithmFlag for the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
eprosima::fastcdr::Cdr::serialize_member
Cdr & serialize_member(const MemberId &member_id, const _T &member_value, XCdrHeaderSelection header_selection=XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
XCDR extensions.
Definition Cdr.h:2666
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(char *string_t)
This function serializes a string.
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(fixed_string< MAX_CHARS > &value)
Decodes a fixed string.
Definition Cdr.h:1791
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const _T &value)
Encodes the value of a type into the buffer.
Definition Cdr.h:381
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
eprosima::fastcdr::Cdr::allocate_xcdrv2_dheader
Cdr_DllAPI state allocate_xcdrv2_dheader()
Encodes an empty DHEADER if the encoding version is XCDRv2.
eprosima::fastcdr::Cdr::read_encapsulation
Cdr_DllAPI Cdr & read_encapsulation()
This function reads the encapsulation of the CDR stream.
eprosima::fastcdr::Cdr::deserialize_array
TEMPLATE_SPEC Cdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
Definition Cdr.h:2252
eprosima::fastcdr::Cdr::get_cdr_version
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the CdrVersion used by the instance.
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const long double *ldouble_t, size_t num_elements)
This function serializes an array of long doubles.
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(int64_t &longlong_t)
This function deserializes a long long.
eprosima::fastcdr::Cdr::Cdr
Cdr_DllAPI Cdr(FastBuffer &cdr_buffer, const Endianness endianness=DEFAULT_ENDIAN, const CdrVersion cdr_version=XCDRv2)
This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize the assigned...
eprosima::fastcdr::Cdr::deserialize_array
Cdr & deserialize_array(std::vector< _T > &value, Endianness endianness)
Decodes an array of non-primitives on a std::vector with a different endianness.
Definition Cdr.h:2425
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence of non-primitive.
Definition Cdr.h:1844
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(int64_t *longlong_t, size_t num_elements)
This function deserializes an array of long longs.
eprosima::fastcdr::Cdr::set_xcdrv2_dheader
Cdr_DllAPI void set_xcdrv2_dheader(const state &state)
Uses the state to calculate the member's type size and serialize the value in the previous allocated ...
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(external< _T > &value)
Decodes an external from the buffer.
Definition Cdr.h:2873
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const int8_t int8)
This function serializes an int8_t.
eprosima::fastcdr::Cdr::serialize_member
Cdr & serialize_member(const MemberId &member_id, const optional< _T > &member_value, XCdrHeaderSelection header_selection=XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
Encodes an optional member of a type according to the encoding algorithm used.
Definition Cdr.h:2688
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
Definition Cdr.h:1172
eprosima::fastcdr::Cdr::deserialize
TEMPLATE_SPEC Cdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Definition Cdr.h:1775
eprosima::fastcdr::Cdr::alignment
static size_t alignment(size_t current_alignment, size_t data_size)
Returns the number of bytes needed to align a position to certain data size.
Definition Cdr.h:275
eprosima::fastcdr::Cdr::serialize_array
Cdr_DllAPI Cdr & serialize_array(const double *double_t, size_t num_elements)
This function serializes an array of doubles.
eprosima::fastcdr::Cdr::operator<<
Cdr & operator<<(const _T &value)
Encodes the value into the buffer.
Definition Cdr.h:326
eprosima::fastcdr::Cdr::move_alignment_forward
Cdr_DllAPI bool move_alignment_forward(size_t num_bytes)
This function moves the alignment forward.
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(int32_t &long_t)
This function deserializes a long.
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const _T *type_t, size_t num_elements, Endianness endianness)
This function template serializes an array of non-basic objects with a different endianness.
Definition Cdr.h:966
eprosima::fastcdr::Cdr::serialize_array
TEMPLATE_SPEC Cdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
Definition Cdr.h:1038
eprosima::fastcdr::Cdr::serialize_sequence
Cdr & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence of non-primitives.
Definition Cdr.h:1316
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(int16_t &short_t)
This function deserializes a short.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
Definition Cdr.h:737
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const external< _T > &value)
Encodes an external in the buffer.
Definition Cdr.h:2818
eprosima::fastcdr::Cdr::set_state
Cdr_DllAPI void set_state(const state &state)
Sets a previous state of the CDR serialization process;.
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const _T &value, Endianness endianness)
Encodes the value of a type with a different endianness.
Definition Cdr.h:397
eprosima::fastcdr::Cdr::deserialize_array
Cdr_DllAPI Cdr & deserialize_array(bool *bool_t, size_t num_elements)
This function deserializes an array of booleans.
eprosima::fastcdr::Cdr::deserialize_sequence
TEMPLATE_SPEC Cdr & deserialize_sequence(std::wstring *&sequence_t, size_t &num_elements)
This function template deserializes a wide-string sequence.
Definition Cdr.h:2644
eprosima::fastcdr::Cdr::serialize
TEMPLATE_SPEC Cdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
Definition Cdr.h:826
eprosima::fastcdr::Cdr::deserialize
Cdr_DllAPI Cdr & deserialize(float &float_t)
This function deserializes a float.
eprosima::fastcdr::Cdr::serialize
Cdr_DllAPI Cdr & serialize(const bool bool_t)
This function serializes a boolean.
eprosima::fastcdr::FastBuffer
This class represents a stream of bytes that contains (or will contain) serialized data.
Definition FastBuffer.h:244
eprosima::fastcdr::FastBuffer::iterator
_FastBuffer_iterator iterator
Definition FastBuffer.h:247
eprosima::fastcdr::MemberId
Definition MemberId.hpp:28
eprosima::fastcdr::exception::BadParamException
This class is thrown as an exception when an invalid parameter is being serialized.
Definition BadParamException.h:28
eprosima::fastcdr::exception::Exception
This abstract class is used to create exceptions.
Definition Exception.h:29
eprosima::fastcdr::exception::Exception::raise
virtual void raise() const =0
This function throws the object as exception.
eprosima::fastcdr::exception::NotEnoughMemoryException
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
Definition NotEnoughMemoryException.h:28
eprosima::fastcdr::exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
static const char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
Definition NotEnoughMemoryException.h:78
eprosima::fastcdr::external
This class template manages an external member, a member declared to be external to the storage of a ...
Definition external.hpp:30
eprosima::fastcdr::external::is_locked
bool is_locked() const noexcept
Checks if locked.
Definition external.hpp:168
eprosima::fastcdr::external::type
T type
Definition external.hpp:33
eprosima::fastcdr::optional
This class template manages an optional contained value, i.e.
Definition optional.hpp:47
eprosima::fastcdr::optional::reset
void reset(bool initial_engaged=false)
Reset the state of the optional.
Definition optional.hpp:115
eprosima::fastcdr::optional::has_value
bool has_value() const
Checks whether the optional contains a value.
Definition optional.hpp:202
eprosima::fastcdr
Definition Cdr.h:50
eprosima::fastcdr::EncodingAlgorithmFlag
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
Definition CdrEncoding.hpp:38
eprosima::fastcdr::PL_CDR2
@ PL_CDR2
Specifies that the content is PL_CDR2.
Definition CdrEncoding.hpp:48
eprosima::fastcdr::PLAIN_CDR
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
Definition CdrEncoding.hpp:40
eprosima::fastcdr::PLAIN_CDR2
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
Definition CdrEncoding.hpp:44
eprosima::fastcdr::MEMBER_ID_INVALID
static const MemberId MEMBER_ID_INVALID
Definition MemberId.hpp:67
eprosima::fastcdr::is_multi_array_primitive
constexpr bool is_multi_array_primitive(...)
Basis.
Definition container_recursive_inspector.hpp:27
eprosima::fastcdr::deserialize
void deserialize(Cdr &, _T &)
eprosima::fastcdr::CdrVersion
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
Definition CdrEncoding.hpp:25
eprosima::fastcdr::XCDRv2
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Definition CdrEncoding.hpp:33
eprosima::fastcdr::serialize
void serialize(Cdr &, const _T &)
eprosima
Definition Cdr.h:49
eprosima::fastcdr::fixed_string
Template class for non-alloc strings.
Definition fixed_size_string.hpp:45
eprosima::fastcdr::fixed_string::c_str
const char * c_str() const noexcept
Converts to C string.
Definition fixed_size_string.hpp:154
eprosima::fastcdr::fixed_string::assign
fixed_string & assign(const char *c_array, size_t n_chars) noexcept
Assigns from a char array.
Definition fixed_size_string.hpp:78