Fast CDR  Version 2.2.6
Fast CDR
Loading...
Searching...
No Matches
FastCdr.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_FASTCDR_H_
16#define _FASTCDR_FASTCDR_H_
17
18#include <array>
19#include <cstdint>
20#include <cstring>
21#include <string>
22#include <vector>
23
24#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
25#include <malloc.h>
26#else
27#include <stdlib.h>
28#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
29
30#include "fastcdr_dll.h"
31#include "FastBuffer.h"
32#include "exceptions/NotEnoughMemoryException.h"
33#include "exceptions/BadParamException.h"
34
35namespace eprosima {
36namespace fastcdr {
42class Cdr_DllAPI FastCdr
43{
44public:
45
49 class Cdr_DllAPI state
50 {
51 friend class FastCdr;
52
53 public:
54
59 const FastCdr& fastcdr);
60
65 const state&);
66
67 private:
68
69 state& operator =(
70 const state&) = delete;
71
73 const FastBuffer::iterator current_position_;
74 };
82 FastBuffer& cdr_buffer);
83
89 bool jump(
90 size_t num_bytes);
91
95 void reset();
96
102
107 inline size_t get_serialized_data_length() const
108 {
109 return current_position_ - cdr_buffer_.begin();
110 }
111
117
124
131 inline FastCdr& operator <<(
132 const uint8_t octet_t)
133 {
134 return serialize(octet_t);
135 }
136
143 inline FastCdr& operator <<(
144 const char char_t)
145 {
146 return serialize(char_t);
147 }
148
155 inline FastCdr& operator <<(
156 const int8_t int8)
157 {
158 return serialize(int8);
159 }
160
167 inline FastCdr& operator <<(
168 const uint16_t ushort_t)
169 {
170 return serialize(ushort_t);
171 }
172
179 inline FastCdr& operator <<(
180 const int16_t short_t)
181 {
182 return serialize(short_t);
183 }
184
191 inline FastCdr& operator <<(
192 const uint32_t ulong_t)
193 {
194 return serialize(ulong_t);
195 }
196
203 inline FastCdr& operator <<(
204 const int32_t long_t)
205 {
206 return serialize(long_t);
207 }
208
215 inline FastCdr& operator <<(
216 const wchar_t wchar)
217 {
218 return serialize(wchar);
219 }
220
227 inline FastCdr& operator <<(
228 const uint64_t ulonglong_t)
229 {
230 return serialize(ulonglong_t);
231 }
232
239 inline FastCdr& operator <<(
240 const int64_t longlong_t)
241 {
242 return serialize(longlong_t);
243 }
244
251 inline FastCdr& operator <<(
252 const float float_t)
253 {
254 return serialize(float_t);
255 }
256
263 inline FastCdr& operator <<(
264 const double double_t)
265 {
266 return serialize(double_t);
267 }
268
275 inline FastCdr& operator <<(
276 const long double ldouble_t)
277 {
278 return serialize(ldouble_t);
279 }
280
287 inline FastCdr& operator <<(
288 const bool bool_t)
289 {
290 return serialize(bool_t);
291 }
292
299 inline FastCdr& operator <<(
300 const char* string_t)
301 {
302 return serialize(string_t);
303 }
304
311 inline FastCdr& operator <<(
312 const wchar_t* string_t)
313 {
314 return serialize(string_t);
315 }
316
323 inline FastCdr& operator <<(
324 const std::string& string_t)
325 {
326 return serialize(string_t);
327 }
328
335 inline FastCdr& operator <<(
336 const std::wstring& string_t)
337 {
338 return serialize(string_t);
339 }
340
347 template<class _T, size_t _Size>
348 inline FastCdr& operator <<(
349 const std::array<_T, _Size>& array_t)
350 {
351 return serialize<_T, _Size>(array_t);
352 }
353
360 template<class _T>
361 inline FastCdr& operator <<(
362 const std::vector<_T>& vector_t)
363 {
364 return serialize<_T>(vector_t);
365 }
366
373 template<class _T>
374 inline FastCdr& operator <<(
375 const _T& type_t)
376 {
377 type_t.serialize(*this);
378 return *this;
379 }
380
387 inline FastCdr& operator >>(
388 uint8_t& octet_t)
389 {
390 return deserialize(octet_t);
391 }
392
399 inline FastCdr& operator >>(
400 char& char_t)
401 {
402 return deserialize(char_t);
403 }
404
411 inline FastCdr& operator >>(
412 int8_t& int8)
413 {
414 return deserialize(int8);
415 }
416
423 inline FastCdr& operator >>(
424 uint16_t& ushort_t)
425 {
426 return deserialize(ushort_t);
427 }
428
435 inline FastCdr& operator >>(
436 int16_t& short_t)
437 {
438 return deserialize(short_t);
439 }
440
447 inline FastCdr& operator >>(
448 uint32_t& ulong_t)
449 {
450 return deserialize(ulong_t);
451 }
452
459 inline FastCdr& operator >>(
460 int32_t& long_t)
461 {
462 return deserialize(long_t);
463 }
464
471 inline FastCdr& operator >>(
472 wchar_t& wchar)
473 {
474 return deserialize(wchar);
475 }
476
483 inline FastCdr& operator >>(
484 uint64_t& ulonglong_t)
485 {
486 return deserialize(ulonglong_t);
487 }
488
495 inline FastCdr& operator >>(
496 int64_t& longlong_t)
497 {
498 return deserialize(longlong_t);
499 }
500
507 inline FastCdr& operator >>(
508 float& float_t)
509 {
510 return deserialize(float_t);
511 }
512
519 inline FastCdr& operator >>(
520 double& double_t)
521 {
522 return deserialize(double_t);
523 }
524
531 inline FastCdr& operator >>(
532 long double& ldouble_t)
533 {
534 return deserialize(ldouble_t);
535 }
536
544 inline FastCdr& operator >>(
545 bool& bool_t)
546 {
547 return deserialize(bool_t);
548 }
549
559 inline FastCdr& operator >>(
560 char*& string_t)
561 {
562 return deserialize(string_t);
563 }
564
571 inline FastCdr& operator >>(
572 std::string& string_t)
573 {
574 return deserialize(string_t);
575 }
576
583 inline FastCdr& operator >>(
584 std::wstring& string_t)
585 {
586 return deserialize(string_t);
587 }
588
595 template<class _T, size_t _Size>
596 inline FastCdr& operator >>(
597 std::array<_T, _Size>& array_t)
598 {
599 return deserialize<_T, _Size>(array_t);
600 }
601
608 template<class _T>
609 inline FastCdr& operator >>(
610 std::vector<_T>& vector_t)
611 {
612 return deserialize<_T>(vector_t);
613 }
614
621 template<class _T>
622 inline FastCdr& operator >>(
623 _T& type_t)
624 {
625 type_t.deserialize(*this);
626 return *this;
627 }
628
635 inline
637 const uint8_t octet_t)
638 {
639 return serialize(static_cast<char>(octet_t));
640 }
641
648 inline
650 const char char_t)
651 {
652 if (((last_position_ - current_position_) >= sizeof(char_t)) || resize(sizeof(char_t)))
653 {
654 current_position_++ << char_t;
655 return *this;
656 }
657
658 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
659 }
660
667 inline
669 const int8_t int8)
670 {
671 return serialize(static_cast<char>(int8));
672 }
673
680 inline
682 const uint16_t ushort_t)
683 {
684 return serialize(static_cast<int16_t>(ushort_t));
685 }
686
693 inline
695 const int16_t short_t)
696 {
697 if (((last_position_ - current_position_) >= sizeof(short_t)) || resize(sizeof(short_t)))
698 {
699 current_position_ << short_t;
700 current_position_ += sizeof(short_t);
701
702 return *this;
703 }
704
705 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
706 }
707
714 inline
716 const uint32_t ulong_t)
717 {
718 return serialize(static_cast<int32_t>(ulong_t));
719 }
720
727 inline
729 const int32_t long_t)
730 {
731 if (((last_position_ - current_position_) >= sizeof(long_t)) || resize(sizeof(long_t)))
732 {
733 current_position_ << long_t;
734 current_position_ += sizeof(long_t);
735
736 return *this;
737 }
738
739 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
740 }
741
748 inline
750 const wchar_t wchar)
751 {
752 return serialize(static_cast<uint32_t>(wchar));
753 }
754
761 inline
763 const uint64_t ulonglong_t)
764 {
765 return serialize(static_cast<int64_t>(ulonglong_t));
766 }
767
774 inline
776 const int64_t longlong_t)
777 {
778 if (((last_position_ - current_position_) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
779 {
780 current_position_ << longlong_t;
781 current_position_ += sizeof(longlong_t);
782
783 return *this;
784 }
785
786 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
787 }
788
795 inline
797 const float float_t)
798 {
799 if (((last_position_ - current_position_) >= sizeof(float_t)) || resize(sizeof(float_t)))
800 {
801 current_position_ << float_t;
802 current_position_ += sizeof(float_t);
803
804 return *this;
805 }
806
807 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
808 }
809
816 inline
818 const double double_t)
819 {
820 if (((last_position_ - current_position_) >= sizeof(double_t)) || resize(sizeof(double_t)))
821 {
822 current_position_ << double_t;
823 current_position_ += sizeof(double_t);
824
825 return *this;
826 }
827
828 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
829 }
830
837 inline
839 const long double ldouble_t)
840 {
841 if (((last_position_ - current_position_) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
842 {
843 current_position_ << ldouble_t;
844#if defined(_WIN32)
845 current_position_ += sizeof(ldouble_t);
846 current_position_ << static_cast<long double>(0);
847#endif // if defined(_WIN32)
848 current_position_ += sizeof(ldouble_t);
849
850 return *this;
851 }
852
853 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
854 }
855
863 const bool bool_t);
864
872 const char* string_t);
873
881 const wchar_t* string_t);
882
890 inline
892 const std::string& string_t)
893 {
894 // Check there are no null characters in the string.
895 const char* c_str = string_t.c_str();
896 const auto str_len = strlen(c_str);
897 if (string_t.size() > str_len)
898 {
899 throw exception::BadParamException("The string contains null characters");
900 }
901
902 return serialize(c_str);
903 }
904
911 inline
913 const std::wstring& string_t)
914 {
915 return serialize(string_t.c_str());
916 }
917
924 template<class _T, size_t _Size>
926 const std::array<_T, _Size>& array_t)
927 {
928 return serialize_array(array_t.data(), array_t.size());
929 }
930
937 template<class _T = bool>
939 const std::vector<bool>& vector_t)
940 {
941 return serialize_bool_sequence(vector_t);
942 }
943
950 template<class _T>
952 const std::vector<_T>& vector_t)
953 {
954 state state_before_error(*this);
955
956 *this << static_cast<int32_t>(vector_t.size());
957
958 try
959 {
960 return serialize_array(vector_t.data(), vector_t.size());
961 }
963 {
964 set_state(state_before_error);
965 ex.raise();
966 }
967
968 return *this;
969 }
970
971#ifdef _MSC_VER
978 template<>
979 FastCdr& serialize<bool>(
980 const std::vector<bool>& vector_t)
981 {
982 return serialize_bool_sequence(vector_t);
983 }
984
985#endif // ifdef _MSC_VER
986
993 template<class _T>
995 const _T& type_t)
996 {
997 type_t.serialize(*this);
998 return *this;
999 }
1000
1008 inline
1010 const uint8_t* octet_t,
1011 size_t num_elements)
1012 {
1013 return serialize_array(reinterpret_cast<const char*>(octet_t), num_elements);
1014 }
1015
1024 const char* char_t,
1025 size_t num_elements);
1026
1034 inline
1036 const int8_t* int8,
1037 size_t num_elements)
1038 {
1039 return serialize_array(reinterpret_cast<const char*>(int8), num_elements);
1040 }
1041
1049 inline
1051 const uint16_t* ushort_t,
1052 size_t num_elements)
1053 {
1054 return serialize_array(reinterpret_cast<const int16_t*>(ushort_t), num_elements);
1055 }
1056
1065 const int16_t* short_t,
1066 size_t num_elements);
1067
1075 inline
1077 const uint32_t* ulong_t,
1078 size_t num_elements)
1079 {
1080 return serialize_array(reinterpret_cast<const int32_t*>(ulong_t), num_elements);
1081 }
1082
1091 const int32_t* long_t,
1092 size_t num_elements);
1093
1102 const wchar_t* wchar,
1103 size_t num_elements);
1104
1112 inline
1114 const uint64_t* ulonglong_t,
1115 size_t num_elements)
1116 {
1117 return serialize_array(reinterpret_cast<const int64_t*>(ulonglong_t), num_elements);
1118 }
1119
1128 const int64_t* longlong_t,
1129 size_t num_elements);
1130
1139 const float* float_t,
1140 size_t num_elements);
1141
1150 const double* double_t,
1151 size_t num_elements);
1152
1161 const long double* ldouble_t,
1162 size_t num_elements);
1163
1172 const bool* bool_t,
1173 size_t num_elements);
1174
1182 inline
1184 const std::string* string_t,
1185 size_t num_elements)
1186 {
1187 for (size_t count = 0; count < num_elements; ++count)
1188 {
1189 serialize(string_t[count].c_str());
1190 }
1191 return *this;
1192 }
1193
1201 inline
1203 const std::wstring* string_t,
1204 size_t num_elements)
1205 {
1206 for (size_t count = 0; count < num_elements; ++count)
1207 {
1208 serialize(string_t[count].c_str());
1209 }
1210 return *this;
1211 }
1212
1220 template<class _T>
1222 const std::vector<_T>* vector_t,
1223 size_t num_elements)
1224 {
1225 for (size_t count = 0; count < num_elements; ++count)
1226 {
1227 serialize(vector_t[count]);
1228 }
1229 return *this;
1230 }
1231
1239 template<class _T>
1241 const _T* type_t,
1242 size_t num_elements)
1243 {
1244 for (size_t count = 0; count < num_elements; ++count)
1245 {
1246 type_t[count].serialize(*this);
1247 }
1248 return *this;
1249 }
1250
1258 template<class _T>
1260 const _T* sequence_t,
1261 size_t num_elements)
1262 {
1263 state state_before_error(*this);
1264
1265 serialize(static_cast<int32_t>(num_elements));
1266
1267 try
1268 {
1269 return serialize_array(sequence_t, num_elements);
1270 }
1272 {
1273 set_state(state_before_error);
1274 ex.raise();
1275 }
1276
1277 return *this;
1278 }
1279
1286 inline
1288 uint8_t& octet_t)
1289 {
1290 return deserialize(reinterpret_cast<char&>(octet_t));
1291 }
1292
1299 inline
1301 char& char_t)
1302 {
1303 if ((last_position_ - current_position_) >= sizeof(char_t))
1304 {
1305 current_position_++ >> char_t;
1306 return *this;
1307 }
1308
1309 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1310 }
1311
1318 inline
1320 int8_t& int8)
1321 {
1322 return deserialize(reinterpret_cast<char&>(int8));
1323 }
1324
1331 inline
1333 uint16_t& ushort_t)
1334 {
1335 return deserialize(reinterpret_cast<int16_t&>(ushort_t));
1336 }
1337
1344 inline
1346 int16_t& short_t)
1347 {
1348 if ((last_position_ - current_position_) >= sizeof(short_t))
1349 {
1350 current_position_ >> short_t;
1351 current_position_ += sizeof(short_t);
1352
1353 return *this;
1354 }
1355
1356 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1357 }
1358
1365 inline
1367 uint32_t& ulong_t)
1368 {
1369 return deserialize(reinterpret_cast<int32_t&>(ulong_t));
1370 }
1371
1378 inline
1380 int32_t& long_t)
1381 {
1382 if ((last_position_ - current_position_) >= sizeof(long_t))
1383 {
1384 current_position_ >> long_t;
1385 current_position_ += sizeof(long_t);
1386
1387 return *this;
1388 }
1389
1390 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1391 }
1392
1399 inline
1401 wchar_t& wchar)
1402 {
1403 uint32_t ret;
1404 deserialize(ret);
1405 wchar = static_cast<wchar_t>(ret);
1406 return *this;
1407 }
1408
1415 inline
1417 uint64_t& ulonglong_t)
1418 {
1419 return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
1420 }
1421
1428 inline
1430 int64_t& longlong_t)
1431 {
1432 if ((last_position_ - current_position_) >= sizeof(longlong_t))
1433 {
1434 current_position_ >> longlong_t;
1435 current_position_ += sizeof(longlong_t);
1436
1437 return *this;
1438 }
1439
1440 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1441 }
1442
1449 inline
1451 float& float_t)
1452 {
1453 if ((last_position_ - current_position_) >= sizeof(float_t))
1454 {
1455 current_position_ >> float_t;
1456 current_position_ += sizeof(float_t);
1457
1458 return *this;
1459 }
1460
1461 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1462 }
1463
1470 inline
1472 double& double_t)
1473 {
1474 if ((last_position_ - current_position_) >= sizeof(double_t))
1475 {
1476 current_position_ >> double_t;
1477 current_position_ += sizeof(double_t);
1478
1479 return *this;
1480 }
1481
1482 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1483 }
1484
1491 inline
1493 long double& ldouble_t)
1494 {
1495 if ((last_position_ - current_position_) >= sizeof(ldouble_t))
1496 {
1497 current_position_ >> ldouble_t;
1498 current_position_ += sizeof(ldouble_t);
1499#if defined(_WIN32)
1500 current_position_ += sizeof(ldouble_t);
1501#endif // if defined(_WIN32)
1502
1503 return *this;
1504 }
1505
1506 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1507 }
1508
1517 bool& bool_t);
1518
1529 char*& string_t);
1530
1541 wchar_t*& string_t);
1542
1549 inline
1551 std::string& string_t)
1552 {
1553 uint32_t length = 0;
1554 const char* str = read_string(length);
1555 string_t.assign(str, length);
1556 return *this;
1557 }
1558
1565 inline
1567 std::wstring& string_t)
1568 {
1569 uint32_t length = 0;
1570 string_t = read_wstring(length);
1571 return *this;
1572 }
1573
1580 template<class _T, size_t _Size>
1582 std::array<_T, _Size>& array_t)
1583 {
1584 return deserialize_array(array_t.data(), array_t.size());
1585 }
1586
1593 template<class _T = bool>
1595 std::vector<bool>& vector_t)
1596 {
1597 return deserialize_bool_sequence(vector_t);
1598 }
1599
1606 template<class _T>
1608 std::vector<_T>& vector_t)
1609 {
1610 uint32_t sequence_length = 0;
1611 state state_before_error(*this);
1612
1613 *this >> sequence_length;
1614
1615 try
1616 {
1617 vector_t.resize(sequence_length);
1618 return deserialize_array(vector_t.data(), vector_t.size());
1619 }
1621 {
1622 set_state(state_before_error);
1623 ex.raise();
1624 }
1625
1626 return *this;
1627 }
1628
1629#ifdef _MSC_VER
1636 template<>
1637 FastCdr& deserialize<bool>(
1638 std::vector<bool>& vector_t)
1639 {
1640 return deserialize_bool_sequence(vector_t);
1641 }
1642
1643#endif // ifdef _MSC_VER
1644
1651 template<class _T>
1653 _T& type_t)
1654 {
1655 type_t.deserialize(*this);
1656 return *this;
1657 }
1658
1666 inline
1668 uint8_t* octet_t,
1669 size_t num_elements)
1670 {
1671 return deserialize_array(reinterpret_cast<char*>(octet_t), num_elements);
1672 }
1673
1682 char* char_t,
1683 size_t num_elements);
1684
1692 inline
1694 int8_t* int8,
1695 size_t num_elements)
1696 {
1697 return deserialize_array(reinterpret_cast<char*>(int8), num_elements);
1698 }
1699
1707 inline
1709 uint16_t* ushort_t,
1710 size_t num_elements)
1711 {
1712 return deserialize_array(reinterpret_cast<int16_t*>(ushort_t), num_elements);
1713 }
1714
1723 int16_t* short_t,
1724 size_t num_elements);
1725
1733 inline
1735 uint32_t* ulong_t,
1736 size_t num_elements)
1737 {
1738 return deserialize_array(reinterpret_cast<int32_t*>(ulong_t), num_elements);
1739 }
1740
1749 int32_t* long_t,
1750 size_t num_elements);
1751
1760 wchar_t* wchar,
1761 size_t num_elements);
1762
1770 inline
1772 uint64_t* ulonglong_t,
1773 size_t num_elements)
1774 {
1775 return deserialize_array(reinterpret_cast<int64_t*>(ulonglong_t), num_elements);
1776 }
1777
1786 int64_t* longlong_t,
1787 size_t num_elements);
1788
1797 float* float_t,
1798 size_t num_elements);
1799
1808 double* double_t,
1809 size_t num_elements);
1810
1819 long double* ldouble_t,
1820 size_t num_elements);
1821
1830 bool* bool_t,
1831 size_t num_elements);
1832
1840 inline
1842 std::string* string_t,
1843 size_t num_elements)
1844 {
1845 for (size_t count = 0; count < num_elements; ++count)
1846 {
1847 deserialize(string_t[count]);
1848 }
1849 return *this;
1850 }
1851
1859 inline
1861 std::wstring* string_t,
1862 size_t num_elements)
1863 {
1864 for (size_t count = 0; count < num_elements; ++count)
1865 {
1866 deserialize(string_t[count]);
1867 }
1868 return *this;
1869 }
1870
1878 template<class _T>
1880 std::vector<_T>* vector_t,
1881 size_t num_elements)
1882 {
1883 for (size_t count = 0; count < num_elements; ++count)
1884 {
1885 deserialize(vector_t[count]);
1886 }
1887 return *this;
1888 }
1889
1897 template<class _T>
1899 _T* type_t,
1900 size_t num_elements)
1901 {
1902 for (size_t count = 0; count < num_elements; ++count)
1903 {
1904 type_t[count].deserialize(*this);
1905 }
1906 return *this;
1907 }
1908
1918 template<class _T = std::string>
1920 std::string*& sequence_t,
1921 size_t& num_elements)
1922 {
1923 return deserialize_string_sequence(sequence_t, num_elements);
1924 }
1925
1935 template<class _T = std::wstring>
1937 std::wstring*& sequence_t,
1938 size_t& num_elements)
1939 {
1940 return deserialize_wstring_sequence(sequence_t, num_elements);
1941 }
1942
1952 template<class _T>
1954 _T*& sequence_t,
1955 size_t& num_elements)
1956 {
1957 uint32_t sequence_length = 0;
1958 state state_before_error(*this);
1959
1960 deserialize(sequence_length);
1961
1962 try
1963 {
1964 sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
1965 deserialize_array(sequence_t, sequence_length);
1966 }
1968 {
1969 free(sequence_t);
1970 sequence_t = NULL;
1971 set_state(state_before_error);
1972 ex.raise();
1973 }
1974
1975 num_elements = sequence_length;
1976 return *this;
1977 }
1978
1979#ifdef _MSC_VER
1989 template<>
1990 FastCdr& deserialize_sequence<std::string>(
1991 std::string*& sequence_t,
1992 size_t& num_elements)
1993 {
1994 return deserialize_string_sequence(sequence_t, num_elements);
1995 }
1996
2006 template<>
2007 FastCdr& deserialize_sequence<std::wstring>(
2008 std::wstring*& sequence_t,
2009 size_t& num_elements)
2010 {
2011 return deserialize_wstring_sequence(sequence_t, num_elements);
2012 }
2013
2014#endif // ifdef _MSC_VER
2015
2016private:
2017
2018 FastCdr(
2019 const FastCdr&) = delete;
2020
2021 FastCdr& operator =(
2022 const FastCdr&) = delete;
2023
2024 FastCdr& serialize_bool_sequence(
2025 const std::vector<bool>& vector_t);
2026
2027 FastCdr& deserialize_bool_sequence(
2028 std::vector<bool>& vector_t);
2029
2030 FastCdr& deserialize_string_sequence(
2031 std::string*& sequence_t,
2032 size_t& num_elements);
2033
2034 FastCdr& deserialize_wstring_sequence(
2035 std::wstring*& sequence_t,
2036 size_t& num_elements);
2037
2045 template<class _T, size_t _Size>
2046 FastCdr& serialize_array(
2047 const std::array<_T, _Size>* array_t,
2048 size_t num_elements)
2049 {
2050 return serialize_array(array_t->data(), num_elements * array_t->size());
2051 }
2052
2060 template<class _T, size_t _Size>
2061 FastCdr& deserialize_array(
2062 std::array<_T, _Size>* array_t,
2063 size_t num_elements)
2064 {
2065 return deserialize_array(array_t->data(), num_elements * array_t->size());
2066 }
2067
2068 bool resize(
2069 size_t min_size_inc);
2070
2071 const char* read_string(
2072 uint32_t& length);
2073
2074 std::wstring read_wstring(
2075 uint32_t& length);
2076
2078 FastBuffer& cdr_buffer_;
2079
2081 FastBuffer::iterator current_position_;
2082
2084 FastBuffer::iterator last_position_;
2085};
2086} //namespace fastcdr
2087} //namespace eprosima
2088
2089#endif //_FASTCDR_FASTCDR_H_
This class implements the iterator used to go through a FastBuffer.
Definition FastBuffer.h:43
This class represents a stream of bytes that contains (or will contain) serialized data.
Definition FastBuffer.h:244
This class stores the current state of a CDR serialization.
Definition FastCdr.h:50
state(const FastCdr &fastcdr)
Default constructor.
state(const state &)
Copy constructor.
This class offers an interface to serialize/deserialize some basic types using a modified CDR protoco...
Definition FastCdr.h:43
FastCdr & deserialize_array(float *float_t, size_t num_elements)
This function deserializes an array of floats.
FastCdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
Definition FastCdr.h:1035
FastCdr & serialize(const wchar_t *string_t)
This function serializes a wstring.
FastCdr & deserialize_array(std::vector< _T > *vector_t, size_t num_elements)
This function template deserializes an array of sequences.
Definition FastCdr.h:1879
FastCdr & deserialize(char *&string_t)
This function deserializes a string.
FastCdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Definition FastCdr.h:1319
FastCdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
Definition FastCdr.h:749
FastCdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
Definition FastCdr.h:1667
FastCdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence.
Definition FastCdr.h:951
FastCdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
Definition FastCdr.h:1076
bool jump(size_t num_bytes)
This function skips a number of bytes in the CDR stream buffer.
FastCdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
Definition FastCdr.h:1400
FastCdr & deserialize_array(std::wstring *string_t, size_t num_elements)
This function deserializes an array of wide-strings.
Definition FastCdr.h:1860
FastCdr & serialize_array(const int32_t *long_t, size_t num_elements)
This function serializes an array of longs.
FastCdr & serialize_array(const _T *type_t, size_t num_elements)
This function template serializes an array of non-basic type objects.
Definition FastCdr.h:1240
FastCdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence.
Definition FastCdr.h:1953
FastCdr & serialize(const uint8_t octet_t)
This function serializes an octet.
Definition FastCdr.h:636
FastCdr & deserialize_array(int16_t *short_t, size_t num_elements)
This function deserializes an array of shorts.
FastCdr & deserialize_array(_T *type_t, size_t num_elements)
This function template deserializes an array of non-basic type objects.
Definition FastCdr.h:1898
FastCdr & deserialize(double &double_t)
This function deserializes a double.
Definition FastCdr.h:1471
FastCdr & serialize(const int16_t short_t)
This function serializes a short.
Definition FastCdr.h:694
FastCdr & deserialize(float &float_t)
This function deserializes a float.
Definition FastCdr.h:1450
FastCdr & serialize_array(const int16_t *short_t, size_t num_elements)
This function serializes an array of shorts.
FastCdr & serialize_array(const wchar_t *wchar, size_t num_elements)
This function serializes an array of wide-chars.
FastCdr & deserialize(bool &bool_t)
This function deserializes a boolean.
FastCdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
Definition FastCdr.h:1050
FastCdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Definition FastCdr.h:1416
FastCdr & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
Definition FastCdr.h:1581
FastCdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
Definition FastCdr.h:1183
FastCdr & deserialize(int64_t &longlong_t)
This function deserializes a long long.
Definition FastCdr.h:1429
FastCdr & deserialize(_T &type_t)
This function template deserializes a non-basic type object.
Definition FastCdr.h:1652
FastCdr & deserialize(int16_t &short_t)
This function deserializes a short.
Definition FastCdr.h:1345
FastCdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
Definition FastCdr.h:1009
FastCdr & serialize(const float float_t)
This function serializes a float.
Definition FastCdr.h:796
FastCdr & deserialize_sequence(std::string *&sequence_t, size_t &num_elements)
This function template deserializes a string sequence.
Definition FastCdr.h:1919
FastCdr & serialize(const int8_t int8)
This function serializes an int8_t.
Definition FastCdr.h:668
FastCdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Definition FastCdr.h:1566
FastCdr & serialize_array(const char *char_t, size_t num_elements)
This function serializes an array of characters.
FastCdr & deserialize(char &char_t)
This function deserializes a character.
Definition FastCdr.h:1300
FastCdr & serialize(const double double_t)
This function serializes a double.
Definition FastCdr.h:817
FastCdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wstrings.
Definition FastCdr.h:1202
FastCdr & deserialize_sequence(std::wstring *&sequence_t, size_t &num_elements)
This function template deserializes a wide-string sequence.
Definition FastCdr.h:1936
FastCdr & serialize(const bool bool_t)
This function serializes a boolean.
FastCdr & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence.
Definition FastCdr.h:1607
FastCdr & serialize_array(const bool *bool_t, size_t num_elements)
This function serializes an array of booleans.
FastCdr & deserialize(long double &ldouble_t)
This function deserializes a long double.
Definition FastCdr.h:1492
FastCdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Definition FastCdr.h:1113
FastCdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
Definition FastCdr.h:1734
FastCdr & deserialize(wchar_t *&string_t)
This function deserializes a wide string.
FastCdr & deserialize_array(long double *ldouble_t, size_t num_elements)
This function deserializes an array of long doubles.
FastCdr & deserialize_array(int64_t *longlong_t, size_t num_elements)
This function deserializes an array of long longs.
FastCdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
Definition FastCdr.h:715
FastCdr(FastBuffer &cdr_buffer)
This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize the assig...
FastCdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
Definition FastCdr.h:912
FastCdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
Definition FastCdr.h:681
FastCdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
Definition FastCdr.h:925
FastCdr & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence.
Definition FastCdr.h:1259
FastCdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
Definition FastCdr.h:762
FastCdr & deserialize(int32_t &long_t)
This function deserializes a long.
Definition FastCdr.h:1379
FastCdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
Definition FastCdr.h:1771
FastCdr & serialize_array(const long double *ldouble_t, size_t num_elements)
This function serializes an array of long doubles.
void set_state(FastCdr::state &state)
This function sets a previous state of the CDR stream;.
FastCdr & serialize_array(const double *double_t, size_t num_elements)
This function serializes an array of doubles.
FastCdr & serialize(const char *string_t)
This function serializes a string.
FastCdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
Definition FastCdr.h:1332
FastCdr & deserialize_array(char *char_t, size_t num_elements)
This function deserializes an array of characters.
FastCdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
Definition FastCdr.h:1366
FastCdr & serialize(const int32_t long_t)
This function serializes a long.
Definition FastCdr.h:728
FastCdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
Definition FastCdr.h:938
FastCdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
Definition FastCdr.h:1693
FastCdr & serialize_array(const int64_t *longlong_t, size_t num_elements)
This function serializes an array of long longs.
FastCdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence of booleans.
Definition FastCdr.h:1594
size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Definition FastCdr.h:107
void reset()
This function resets the current position in the buffer to the begining.
FastCdr & serialize(const char char_t)
This function serializes a character.
Definition FastCdr.h:649
FastCdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Definition FastCdr.h:1708
FastCdr::state get_state()
This function returns the current state of the CDR stream.
FastCdr & serialize_array(const std::vector< _T > *vector_t, size_t num_elements)
This function template serializes an array of sequences.
Definition FastCdr.h:1221
FastCdr & serialize_array(const float *float_t, size_t num_elements)
This function serializes an array of floats.
FastCdr & deserialize_array(bool *bool_t, size_t num_elements)
This function deserializes an array of booleans.
FastCdr & deserialize_array(std::string *string_t, size_t num_elements)
This function deserializes an array of strings.
Definition FastCdr.h:1841
FastCdr & deserialize_array(double *double_t, size_t num_elements)
This function deserializes an array of doubles.
FastCdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition FastCdr.h:1287
FastCdr & deserialize_array(wchar_t *wchar, size_t num_elements)
This function deserializes an array of wide-chars.
FastCdr & serialize(const std::string &string_t)
This function serializes a std::string.
Definition FastCdr.h:891
char * get_current_position()
This function returns the current position in the CDR stream.
FastCdr & serialize(const long double ldouble_t)
This function serializes a long double.
Definition FastCdr.h:838
FastCdr & serialize(const int64_t longlong_t)
This function serializes a long long.
Definition FastCdr.h:775
FastCdr & serialize(const _T &type_t)
This function template serializes a non-basic type.
Definition FastCdr.h:994
FastCdr & deserialize_array(int32_t *long_t, size_t num_elements)
This function deserializes an array of longs.
FastCdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Definition FastCdr.h:1550
This class is thrown as an exception when an invalid parameter is being serialized.
Definition BadParamException.h:28
This abstract class is used to create exceptions.
Definition Exception.h:30
virtual void raise() const =0
This function throws the object as exception.
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
Definition NotEnoughMemoryException.h:28
void deserialize(Cdr &, _T &)
void serialize(Cdr &, const _T &)
Definition Cdr.h:49