Fast CDR  Version 1.0.25
Fast CDR
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 "fastcdr_dll.h"
19#include "FastBuffer.h"
20#include "exceptions/NotEnoughMemoryException.h"
21#include <stdint.h>
22#include <string>
23#include <vector>
24
25#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
26#include <malloc.h>
27#else
28#include <stdlib.h>
29#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
30
31#if HAVE_CXX0X
32#include <array>
33#endif // if HAVE_CXX0X
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 m_currentPosition;
74 };
82 FastBuffer& cdrBuffer);
83
89 bool jump(
90 size_t numBytes);
91
95 void reset();
96
102
107 inline size_t getSerializedDataLength() const
108 {
109 return m_currentPosition - m_cdrBuffer.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
341#if HAVE_CXX0X
348 template<class _T, size_t _Size>
349 inline FastCdr& operator <<(
350 const std::array<_T, _Size>& array_t)
351 {
352 return serialize<_T, _Size>(array_t);
353 }
354
355#endif // if HAVE_CXX0X
356
363 template<class _T>
364 inline FastCdr& operator <<(
365 const std::vector<_T>& vector_t)
366 {
367 return serialize<_T>(vector_t);
368 }
369
376 template<class _T>
377 inline FastCdr& operator <<(
378 const _T& type_t)
379 {
380 type_t.serialize(*this);
381 return *this;
382 }
383
390 inline FastCdr& operator >>(
391 uint8_t& octet_t)
392 {
393 return deserialize(octet_t);
394 }
395
402 inline FastCdr& operator >>(
403 char& char_t)
404 {
405 return deserialize(char_t);
406 }
407
414 inline FastCdr& operator >>(
415 int8_t& int8)
416 {
417 return deserialize(int8);
418 }
419
426 inline FastCdr& operator >>(
427 uint16_t& ushort_t)
428 {
429 return deserialize(ushort_t);
430 }
431
438 inline FastCdr& operator >>(
439 int16_t& short_t)
440 {
441 return deserialize(short_t);
442 }
443
450 inline FastCdr& operator >>(
451 uint32_t& ulong_t)
452 {
453 return deserialize(ulong_t);
454 }
455
462 inline FastCdr& operator >>(
463 int32_t& long_t)
464 {
465 return deserialize(long_t);
466 }
467
474 inline FastCdr& operator >>(
475 wchar_t& wchar)
476 {
477 return deserialize(wchar);
478 }
479
486 inline FastCdr& operator >>(
487 uint64_t& ulonglong_t)
488 {
489 return deserialize(ulonglong_t);
490 }
491
498 inline FastCdr& operator >>(
499 int64_t& longlong_t)
500 {
501 return deserialize(longlong_t);
502 }
503
510 inline FastCdr& operator >>(
511 float& float_t)
512 {
513 return deserialize(float_t);
514 }
515
522 inline FastCdr& operator >>(
523 double& double_t)
524 {
525 return deserialize(double_t);
526 }
527
534 inline FastCdr& operator >>(
535 long double& ldouble_t)
536 {
537 return deserialize(ldouble_t);
538 }
539
547 inline FastCdr& operator >>(
548 bool& bool_t)
549 {
550 return deserialize(bool_t);
551 }
552
562 inline FastCdr& operator >>(
563 char*& string_t)
564 {
565 return deserialize(string_t);
566 }
567
574 inline FastCdr& operator >>(
575 std::string& string_t)
576 {
577 return deserialize(string_t);
578 }
579
586 inline FastCdr& operator >>(
587 std::wstring& string_t)
588 {
589 return deserialize(string_t);
590 }
591
592#if HAVE_CXX0X
599 template<class _T, size_t _Size>
600 inline FastCdr& operator >>(
601 std::array<_T, _Size>& array_t)
602 {
603 return deserialize<_T, _Size>(array_t);
604 }
605
606#endif // if HAVE_CXX0X
607
614 template<class _T>
615 inline FastCdr& operator >>(
616 std::vector<_T>& vector_t)
617 {
618 return deserialize<_T>(vector_t);
619 }
620
627 template<class _T>
628 inline FastCdr& operator >>(
629 _T& type_t)
630 {
631 type_t.deserialize(*this);
632 return *this;
633 }
634
641 inline
643 const uint8_t octet_t)
644 {
645 return serialize(static_cast<char>(octet_t));
646 }
647
654 inline
656 const char char_t)
657 {
658 if (((m_lastPosition - m_currentPosition) >= sizeof(char_t)) || resize(sizeof(char_t)))
659 {
660 m_currentPosition++ << char_t;
661 return *this;
662 }
663
665 }
666
673 inline
675 const int8_t int8)
676 {
677 return serialize(static_cast<char>(int8));
678 }
679
686 inline
688 const uint16_t ushort_t)
689 {
690 return serialize(static_cast<int16_t>(ushort_t));
691 }
692
699 inline
701 const int16_t short_t)
702 {
703 if (((m_lastPosition - m_currentPosition) >= sizeof(short_t)) || resize(sizeof(short_t)))
704 {
705 m_currentPosition << short_t;
706 m_currentPosition += sizeof(short_t);
707
708 return *this;
709 }
710
712 }
713
720 inline
722 const uint32_t ulong_t)
723 {
724 return serialize(static_cast<int32_t>(ulong_t));
725 }
726
733 inline
735 const int32_t long_t)
736 {
737 if (((m_lastPosition - m_currentPosition) >= sizeof(long_t)) || resize(sizeof(long_t)))
738 {
739 m_currentPosition << long_t;
740 m_currentPosition += sizeof(long_t);
741
742 return *this;
743 }
744
746 }
747
754 inline
756 const wchar_t wchar)
757 {
758 return serialize(static_cast<uint32_t>(wchar));
759 }
760
767 inline
769 const uint64_t ulonglong_t)
770 {
771 return serialize(static_cast<int64_t>(ulonglong_t));
772 }
773
780 inline
782 const int64_t longlong_t)
783 {
784 if (((m_lastPosition - m_currentPosition) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
785 {
786 m_currentPosition << longlong_t;
787 m_currentPosition += sizeof(longlong_t);
788
789 return *this;
790 }
791
793 }
794
801 inline
803 const float float_t)
804 {
805 if (((m_lastPosition - m_currentPosition) >= sizeof(float_t)) || resize(sizeof(float_t)))
806 {
807 m_currentPosition << float_t;
808 m_currentPosition += sizeof(float_t);
809
810 return *this;
811 }
812
814 }
815
822 inline
824 const double double_t)
825 {
826 if (((m_lastPosition - m_currentPosition) >= sizeof(double_t)) || resize(sizeof(double_t)))
827 {
828 m_currentPosition << double_t;
829 m_currentPosition += sizeof(double_t);
830
831 return *this;
832 }
833
835 }
836
843 inline
845 const long double ldouble_t)
846 {
847 if (((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
848 {
849 m_currentPosition << ldouble_t;
850#if defined(_WIN32)
851 m_currentPosition += sizeof(ldouble_t);
852 m_currentPosition << static_cast<long double>(0);
853#endif // if defined(_WIN32)
854 m_currentPosition += sizeof(ldouble_t);
855
856 return *this;
857 }
858
860 }
861
869 const bool bool_t);
870
878 const char* string_t);
879
887 const wchar_t* string_t);
888
895 inline
897 const std::string& string_t)
898 {
899 return serialize(string_t.c_str());
900 }
901
908 inline
910 const std::wstring& string_t)
911 {
912 return serialize(string_t.c_str());
913 }
914
915#if HAVE_CXX0X
922 template<class _T, size_t _Size>
923 inline FastCdr& serialize(
924 const std::array<_T, _Size>& array_t)
925 {
926 return serializeArray(array_t.data(), array_t.size());
927 }
928
929#endif // if HAVE_CXX0X
930
931#if !defined(_MSC_VER) && HAVE_CXX0X
938 template<class _T = bool>
939 FastCdr& serialize(
940 const std::vector<bool>& vector_t)
941 {
942 return serializeBoolSequence(vector_t);
943 }
944
945#endif // if !defined(_MSC_VER) && HAVE_CXX0X
946
953 template<class _T>
955 const std::vector<_T>& vector_t)
956 {
957 state state_before_error(*this);
958
959 *this << static_cast<int32_t>(vector_t.size());
960
961 try
962 {
963 return serializeArray(vector_t.data(), vector_t.size());
964 }
966 {
967 setState(state_before_error);
968 ex.raise();
969 }
970
971 return *this;
972 }
973
974#ifdef _MSC_VER
981 template<>
982 FastCdr& serialize<bool>(
983 const std::vector<bool>& vector_t)
984 {
985 return serializeBoolSequence(vector_t);
986 }
987
988#endif // ifdef _MSC_VER
989
996 template<class _T>
998 const _T& type_t)
999 {
1000 type_t.serialize(*this);
1001 return *this;
1002 }
1003
1011 inline
1013 const uint8_t* octet_t,
1014 size_t numElements)
1015 {
1016 return serializeArray(reinterpret_cast<const char*>(octet_t), numElements);
1017 }
1018
1027 const char* char_t,
1028 size_t numElements);
1029
1037 inline
1039 const int8_t* int8,
1040 size_t numElements)
1041 {
1042 return serializeArray(reinterpret_cast<const char*>(int8), numElements);
1043 }
1044
1052 inline
1054 const uint16_t* ushort_t,
1055 size_t numElements)
1056 {
1057 return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements);
1058 }
1059
1068 const int16_t* short_t,
1069 size_t numElements);
1070
1078 inline
1080 const uint32_t* ulong_t,
1081 size_t numElements)
1082 {
1083 return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements);
1084 }
1085
1094 const int32_t* long_t,
1095 size_t numElements);
1096
1105 const wchar_t* wchar,
1106 size_t numElements);
1107
1115 inline
1117 const uint64_t* ulonglong_t,
1118 size_t numElements)
1119 {
1120 return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements);
1121 }
1122
1131 const int64_t* longlong_t,
1132 size_t numElements);
1133
1142 const float* float_t,
1143 size_t numElements);
1144
1153 const double* double_t,
1154 size_t numElements);
1155
1164 const long double* ldouble_t,
1165 size_t numElements);
1166
1175 const bool* bool_t,
1176 size_t numElements);
1177
1185 inline
1187 const std::string* string_t,
1188 size_t numElements)
1189 {
1190 for (size_t count = 0; count < numElements; ++count)
1191 {
1192 serialize(string_t[count].c_str());
1193 }
1194 return *this;
1195 }
1196
1204 inline
1206 const std::wstring* string_t,
1207 size_t numElements)
1208 {
1209 for (size_t count = 0; count < numElements; ++count)
1210 {
1211 serialize(string_t[count].c_str());
1212 }
1213 return *this;
1214 }
1215
1223 template<class _T>
1225 const std::vector<_T>* vector_t,
1226 size_t numElements)
1227 {
1228 for (size_t count = 0; count < numElements; ++count)
1229 {
1230 serialize(vector_t[count]);
1231 }
1232 return *this;
1233 }
1234
1242 template<class _T>
1244 const _T* type_t,
1245 size_t numElements)
1246 {
1247 for (size_t count = 0; count < numElements; ++count)
1248 {
1249 type_t[count].serialize(*this);
1250 }
1251 return *this;
1252 }
1253
1261 template<class _T>
1263 const _T* sequence_t,
1264 size_t numElements)
1265 {
1266 state state_before_error(*this);
1267
1268 serialize(static_cast<int32_t>(numElements));
1269
1270 try
1271 {
1272 return serializeArray(sequence_t, numElements);
1273 }
1275 {
1276 setState(state_before_error);
1277 ex.raise();
1278 }
1279
1280 return *this;
1281 }
1282
1289 inline
1291 uint8_t& octet_t)
1292 {
1293 return deserialize(reinterpret_cast<char&>(octet_t));
1294 }
1295
1302 inline
1304 char& char_t)
1305 {
1306 if ((m_lastPosition - m_currentPosition) >= sizeof(char_t))
1307 {
1308 m_currentPosition++ >> char_t;
1309 return *this;
1310 }
1311
1313 }
1314
1321 inline
1323 int8_t& int8)
1324 {
1325 return deserialize(reinterpret_cast<char&>(int8));
1326 }
1327
1334 inline
1336 uint16_t& ushort_t)
1337 {
1338 return deserialize(reinterpret_cast<int16_t&>(ushort_t));
1339 }
1340
1347 inline
1349 int16_t& short_t)
1350 {
1351 if ((m_lastPosition - m_currentPosition) >= sizeof(short_t))
1352 {
1353 m_currentPosition >> short_t;
1354 m_currentPosition += sizeof(short_t);
1355
1356 return *this;
1357 }
1358
1360 }
1361
1368 inline
1370 uint32_t& ulong_t)
1371 {
1372 return deserialize(reinterpret_cast<int32_t&>(ulong_t));
1373 }
1374
1381 inline
1383 int32_t& long_t)
1384 {
1385 if ((m_lastPosition - m_currentPosition) >= sizeof(long_t))
1386 {
1387 m_currentPosition >> long_t;
1388 m_currentPosition += sizeof(long_t);
1389
1390 return *this;
1391 }
1392
1394 }
1395
1402 inline
1404 wchar_t& wchar)
1405 {
1406 uint32_t ret;
1407 deserialize(ret);
1408 wchar = static_cast<wchar_t>(ret);
1409 return *this;
1410 }
1411
1418 inline
1420 uint64_t& ulonglong_t)
1421 {
1422 return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
1423 }
1424
1431 inline
1433 int64_t& longlong_t)
1434 {
1435 if ((m_lastPosition - m_currentPosition) >= sizeof(longlong_t))
1436 {
1437 m_currentPosition >> longlong_t;
1438 m_currentPosition += sizeof(longlong_t);
1439
1440 return *this;
1441 }
1442
1444 }
1445
1452 inline
1454 float& float_t)
1455 {
1456 if ((m_lastPosition - m_currentPosition) >= sizeof(float_t))
1457 {
1458 m_currentPosition >> float_t;
1459 m_currentPosition += sizeof(float_t);
1460
1461 return *this;
1462 }
1463
1465 }
1466
1473 inline
1475 double& double_t)
1476 {
1477 if ((m_lastPosition - m_currentPosition) >= sizeof(double_t))
1478 {
1479 m_currentPosition >> double_t;
1480 m_currentPosition += sizeof(double_t);
1481
1482 return *this;
1483 }
1484
1486 }
1487
1494 inline
1496 long double& ldouble_t)
1497 {
1498 if ((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t))
1499 {
1500 m_currentPosition >> ldouble_t;
1501 m_currentPosition += sizeof(ldouble_t);
1502#if defined(_WIN32)
1503 m_currentPosition += sizeof(ldouble_t);
1504#endif // if defined(_WIN32)
1505
1506 return *this;
1507 }
1508
1510 }
1511
1520 bool& bool_t);
1521
1532 char*& string_t);
1533
1544 wchar_t*& string_t);
1545
1552 inline
1554 std::string& string_t)
1555 {
1556 uint32_t length = 0;
1557 const char* str = readString(length);
1558 string_t = std::string(str, length);
1559 return *this;
1560 }
1561
1568 inline
1570 std::wstring& string_t)
1571 {
1572 uint32_t length = 0;
1573 string_t = readWString(length);
1574 return *this;
1575 }
1576
1577#if HAVE_CXX0X
1584 template<class _T, size_t _Size>
1585 inline FastCdr& deserialize(
1586 std::array<_T, _Size>& array_t)
1587 {
1588 return deserializeArray(array_t.data(), array_t.size());
1589 }
1590
1591#endif // if HAVE_CXX0X
1592
1593#if !defined(_MSC_VER) && HAVE_CXX0X
1600 template<class _T = bool>
1601 FastCdr& deserialize(
1602 std::vector<bool>& vector_t)
1603 {
1604 return deserializeBoolSequence(vector_t);
1605 }
1606
1607#endif // if !defined(_MSC_VER) && HAVE_CXX0X
1608
1615 template<class _T>
1617 std::vector<_T>& vector_t)
1618 {
1619 uint32_t seqLength = 0;
1620 state state_before_error(*this);
1621
1622 *this >> seqLength;
1623
1624 try
1625 {
1626 vector_t.resize(seqLength);
1627 return deserializeArray(vector_t.data(), vector_t.size());
1628 }
1630 {
1631 setState(state_before_error);
1632 ex.raise();
1633 }
1634
1635 return *this;
1636 }
1637
1638#ifdef _MSC_VER
1645 template<>
1646 FastCdr& deserialize<bool>(
1647 std::vector<bool>& vector_t)
1648 {
1649 return deserializeBoolSequence(vector_t);
1650 }
1651
1652#endif // ifdef _MSC_VER
1653
1660 template<class _T>
1662 _T& type_t)
1663 {
1664 type_t.deserialize(*this);
1665 return *this;
1666 }
1667
1675 inline
1677 uint8_t* octet_t,
1678 size_t numElements)
1679 {
1680 return deserializeArray(reinterpret_cast<char*>(octet_t), numElements);
1681 }
1682
1691 char* char_t,
1692 size_t numElements);
1693
1701 inline
1703 int8_t* int8,
1704 size_t numElements)
1705 {
1706 return deserializeArray(reinterpret_cast<char*>(int8), numElements);
1707 }
1708
1716 inline
1718 uint16_t* ushort_t,
1719 size_t numElements)
1720 {
1721 return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements);
1722 }
1723
1732 int16_t* short_t,
1733 size_t numElements);
1734
1742 inline
1744 uint32_t* ulong_t,
1745 size_t numElements)
1746 {
1747 return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements);
1748 }
1749
1758 int32_t* long_t,
1759 size_t numElements);
1760
1769 wchar_t* wchar,
1770 size_t numElements);
1771
1779 inline
1781 uint64_t* ulonglong_t,
1782 size_t numElements)
1783 {
1784 return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements);
1785 }
1786
1795 int64_t* longlong_t,
1796 size_t numElements);
1797
1806 float* float_t,
1807 size_t numElements);
1808
1817 double* double_t,
1818 size_t numElements);
1819
1828 long double* ldouble_t,
1829 size_t numElements);
1830
1839 bool* bool_t,
1840 size_t numElements);
1841
1849 inline
1851 std::string* string_t,
1852 size_t numElements)
1853 {
1854 for (size_t count = 0; count < numElements; ++count)
1855 {
1856 deserialize(string_t[count]);
1857 }
1858 return *this;
1859 }
1860
1868 inline
1870 std::wstring* string_t,
1871 size_t numElements)
1872 {
1873 for (size_t count = 0; count < numElements; ++count)
1874 {
1875 deserialize(string_t[count]);
1876 }
1877 return *this;
1878 }
1879
1887 template<class _T>
1889 std::vector<_T>* vector_t,
1890 size_t numElements)
1891 {
1892 for (size_t count = 0; count < numElements; ++count)
1893 {
1894 deserialize(vector_t[count]);
1895 }
1896 return *this;
1897 }
1898
1906 template<class _T>
1908 _T* type_t,
1909 size_t numElements)
1910 {
1911 for (size_t count = 0; count < numElements; ++count)
1912 {
1913 type_t[count].deserialize(*this);
1914 }
1915 return *this;
1916 }
1917
1918#if !defined(_MSC_VER) && HAVE_CXX0X
1928 template<class _T = std::string>
1929 FastCdr& deserializeSequence(
1930 std::string*& sequence_t,
1931 size_t& numElements)
1932 {
1933 return deserializeStringSequence(sequence_t, numElements);
1934 }
1935
1945 template<class _T = std::wstring>
1946 FastCdr& deserializeSequence(
1947 std::wstring*& sequence_t,
1948 size_t& numElements)
1949 {
1950 return deserializeWStringSequence(sequence_t, numElements);
1951 }
1952
1953#endif // if !defined(_MSC_VER) && HAVE_CXX0X
1954
1964 template<class _T>
1966 _T*& sequence_t,
1967 size_t& numElements)
1968 {
1969 uint32_t seqLength = 0;
1970 state state_before_error(*this);
1971
1972 deserialize(seqLength);
1973
1974 try
1975 {
1976 sequence_t = reinterpret_cast<_T*>(calloc(seqLength, sizeof(_T)));
1977 deserializeArray(sequence_t, seqLength);
1978 }
1980 {
1981 free(sequence_t);
1982 sequence_t = NULL;
1983 setState(state_before_error);
1984 ex.raise();
1985 }
1986
1987 numElements = seqLength;
1988 return *this;
1989 }
1990
1991#ifdef _MSC_VER
2001 template<>
2002 FastCdr& deserializeSequence<std::string>(
2003 std::string*& sequence_t,
2004 size_t& numElements)
2005 {
2006 return deserializeStringSequence(sequence_t, numElements);
2007 }
2008
2018 template<>
2019 FastCdr& deserializeSequence<std::wstring>(
2020 std::wstring*& sequence_t,
2021 size_t& numElements)
2022 {
2023 return deserializeWStringSequence(sequence_t, numElements);
2024 }
2025
2026#endif // ifdef _MSC_VER
2027
2028private:
2029
2030 FastCdr(
2031 const FastCdr&) = delete;
2032
2033 FastCdr& operator =(
2034 const FastCdr&) = delete;
2035
2036 FastCdr& serializeBoolSequence(
2037 const std::vector<bool>& vector_t);
2038
2039 FastCdr& deserializeBoolSequence(
2040 std::vector<bool>& vector_t);
2041
2042 FastCdr& deserializeStringSequence(
2043 std::string*& sequence_t,
2044 size_t& numElements);
2045
2046 FastCdr& deserializeWStringSequence(
2047 std::wstring*& sequence_t,
2048 size_t& numElements);
2049
2050#if HAVE_CXX0X
2058 template<class _T, size_t _Size>
2059 FastCdr& serializeArray(
2060 const std::array<_T, _Size>* array_t,
2061 size_t numElements)
2062 {
2063 return serializeArray(array_t->data(), numElements * array_t->size());
2064 }
2065
2073 template<class _T, size_t _Size>
2074 FastCdr& deserializeArray(
2075 std::array<_T, _Size>* array_t,
2076 size_t numElements)
2077 {
2078 return deserializeArray(array_t->data(), numElements * array_t->size());
2079 }
2080
2081#endif // if HAVE_CXX0X
2082
2083 bool resize(
2084 size_t minSizeInc);
2085
2086 const char* readString(
2087 uint32_t& length);
2088
2089 std::wstring readWString(
2090 uint32_t& length);
2091
2093 FastBuffer& m_cdrBuffer;
2094
2096 FastBuffer::iterator m_currentPosition;
2097
2099 FastBuffer::iterator m_lastPosition;
2100};
2101} //namespace fastcdr
2102} //namespace eprosima
2103
2104#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:229
_FastBuffer_iterator iterator
Definition: FastBuffer.h:232
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::state getState()
This function returns the current state of the CDR stream.
FastCdr & deserializeArray(std::vector< _T > *vector_t, size_t numElements)
This function template deserializes an array of sequences.
Definition: FastCdr.h:1888
FastCdr & deserializeArray(int8_t *int8, size_t numElements)
This function deserializes an array of int8_t.
Definition: FastCdr.h:1702
FastCdr & serialize(const wchar_t *string_t)
This function serializes a wstring.
FastCdr & serializeArray(const int32_t *long_t, size_t numElements)
This function serializes an array of longs.
FastCdr & deserialize(char *&string_t)
This function deserializes a string.
FastCdr & deserializeArray(uint16_t *ushort_t, size_t numElements)
This function deserializes an array of unsigned shorts.
Definition: FastCdr.h:1717
FastCdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Definition: FastCdr.h:1322
FastCdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
Definition: FastCdr.h:755
FastCdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence.
Definition: FastCdr.h:954
FastCdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
Definition: FastCdr.h:1403
FastCdr & deserializeArray(_T *type_t, size_t numElements)
This function template deserializes an array of non-basic type objects.
Definition: FastCdr.h:1907
FastCdr & serializeArray(const int64_t *longlong_t, size_t numElements)
This function serializes an array of long longs.
FastCdr & serializeArray(const std::wstring *string_t, size_t numElements)
This function serializes an array of wstrings.
Definition: FastCdr.h:1205
FastCdr & serializeArray(const uint32_t *ulong_t, size_t numElements)
This function serializes an array of unsigned longs.
Definition: FastCdr.h:1079
FastCdr & deserializeSequence(_T *&sequence_t, size_t &numElements)
This function template deserializes a raw sequence.
Definition: FastCdr.h:1965
FastCdr & deserializeArray(uint8_t *octet_t, size_t numElements)
This function deserializes an array of octets.
Definition: FastCdr.h:1676
FastCdr & serializeArray(const std::string *string_t, size_t numElements)
This function serializes an array of strings.
Definition: FastCdr.h:1186
FastCdr & deserializeArray(int64_t *longlong_t, size_t numElements)
This function deserializes an array of long longs.
FastCdr & serialize(const uint8_t octet_t)
This function serializes an octet.
Definition: FastCdr.h:642
FastCdr & deserializeArray(wchar_t *wchar, size_t numElements)
This function deserializes an array of wide-chars.
FastCdr & deserializeArray(uint32_t *ulong_t, size_t numElements)
This function deserializes an array of unsigned longs.
Definition: FastCdr.h:1743
FastCdr & deserialize(double &double_t)
This function deserializes a double.
Definition: FastCdr.h:1474
FastCdr & serializeArray(const std::vector< _T > *vector_t, size_t numElements)
This function template serializes an array of sequences.
Definition: FastCdr.h:1224
FastCdr & serialize(const int16_t short_t)
This function serializes a short.
Definition: FastCdr.h:700
FastCdr & deserialize(float &float_t)
This function deserializes a float.
Definition: FastCdr.h:1453
FastCdr & deserializeArray(int32_t *long_t, size_t numElements)
This function deserializes an array of longs.
FastCdr(FastBuffer &cdrBuffer)
This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize the assig...
FastCdr & deserializeArray(std::string *string_t, size_t numElements)
This function deserializes an array of strings.
Definition: FastCdr.h:1850
size_t getSerializedDataLength() const
This function returns the length of the serialized data inside the stream.
Definition: FastCdr.h:107
FastCdr & deserialize(bool &bool_t)
This function deserializes a boolean.
FastCdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Definition: FastCdr.h:1419
FastCdr & deserializeArray(char *char_t, size_t numElements)
This function deserializes an array of characters.
FastCdr & serializeArray(const float *float_t, size_t numElements)
This function serializes an array of floats.
FastCdr & serializeArray(const int8_t *int8, size_t numElements)
This function serializes an array of int8_t.
Definition: FastCdr.h:1038
FastCdr & deserializeArray(double *double_t, size_t numElements)
This function deserializes an array of doubles.
FastCdr & deserializeArray(uint64_t *ulonglong_t, size_t numElements)
This function deserializes an array of unsigned long longs.
Definition: FastCdr.h:1780
FastCdr & deserialize(int64_t &longlong_t)
This function deserializes a long long.
Definition: FastCdr.h:1432
FastCdr & deserialize(_T &type_t)
This function template deserializes a non-basic type object.
Definition: FastCdr.h:1661
FastCdr & deserialize(int16_t &short_t)
This function deserializes a short.
Definition: FastCdr.h:1348
FastCdr & serialize(const float float_t)
This function serializes a float.
Definition: FastCdr.h:802
FastCdr & serializeArray(const int16_t *short_t, size_t numElements)
This function serializes an array of shorts.
FastCdr & serialize(const int8_t int8)
This function serializes an int8_t.
Definition: FastCdr.h:674
FastCdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Definition: FastCdr.h:1569
FastCdr & deserialize(char &char_t)
This function deserializes a character.
Definition: FastCdr.h:1303
FastCdr & serialize(const double double_t)
This function serializes a double.
Definition: FastCdr.h:823
FastCdr & deserializeArray(int16_t *short_t, size_t numElements)
This function deserializes an array of shorts.
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:1616
FastCdr & deserialize(long double &ldouble_t)
This function deserializes a long double.
Definition: FastCdr.h:1495
FastCdr & deserialize(wchar_t *&string_t)
This function deserializes a wide string.
FastCdr & serializeArray(const uint16_t *ushort_t, size_t numElements)
This function serializes an array of unsigned shorts.
Definition: FastCdr.h:1053
FastCdr & serializeArray(const uint64_t *ulonglong_t, size_t numElements)
This function serializes an array of unsigned long longs.
Definition: FastCdr.h:1116
FastCdr & serializeArray(const double *double_t, size_t numElements)
This function serializes an array of doubles.
FastCdr & serializeArray(const bool *bool_t, size_t numElements)
This function serializes an array of booleans.
FastCdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
Definition: FastCdr.h:721
FastCdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
Definition: FastCdr.h:909
FastCdr & serializeArray(const long double *ldouble_t, size_t numElements)
This function serializes an array of long doubles.
FastCdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
Definition: FastCdr.h:687
FastCdr & serializeArray(const _T *type_t, size_t numElements)
This function template serializes an array of non-basic type objects.
Definition: FastCdr.h:1243
FastCdr & serializeArray(const char *char_t, size_t numElements)
This function serializes an array of characters.
FastCdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
Definition: FastCdr.h:768
FastCdr & deserializeArray(std::wstring *string_t, size_t numElements)
This function deserializes an array of wide-strings.
Definition: FastCdr.h:1869
FastCdr & deserialize(int32_t &long_t)
This function deserializes a long.
Definition: FastCdr.h:1382
void setState(FastCdr::state &state)
This function sets a previous state of the CDR stream;.
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:1335
FastCdr & serializeArray(const uint8_t *octet_t, size_t numElements)
This function serializes an array of octets.
Definition: FastCdr.h:1012
FastCdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
Definition: FastCdr.h:1369
FastCdr & serialize(const int32_t long_t)
This function serializes a long.
Definition: FastCdr.h:734
FastCdr & deserializeArray(bool *bool_t, size_t numElements)
This function deserializes an array of booleans.
void reset()
This function resets the current position in the buffer to the begining.
FastCdr & deserializeArray(float *float_t, size_t numElements)
This function deserializes an array of floats.
FastCdr & deserializeArray(long double *ldouble_t, size_t numElements)
This function deserializes an array of long doubles.
FastCdr & serialize(const char char_t)
This function serializes a character.
Definition: FastCdr.h:655
bool jump(size_t numBytes)
This function skips a number of bytes in the CDR stream buffer.
FastCdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition: FastCdr.h:1290
FastCdr & serializeArray(const wchar_t *wchar, size_t numElements)
This function serializes an array of wide-chars.
FastCdr & serialize(const std::string &string_t)
This function serializes a std::string.
Definition: FastCdr.h:896
FastCdr & serialize(const long double ldouble_t)
This function serializes a long double.
Definition: FastCdr.h:844
FastCdr & serializeSequence(const _T *sequence_t, size_t numElements)
This function template serializes a raw sequence.
Definition: FastCdr.h:1262
FastCdr & serialize(const int64_t longlong_t)
This function serializes a long long.
Definition: FastCdr.h:781
char * getCurrentPosition()
This function returns the current position in the CDR stream.
FastCdr & serialize(const _T &type_t)
This function template serializes a non-basic type.
Definition: FastCdr.h:997
FastCdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Definition: FastCdr.h:1553
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
static const char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
Definition: NotEnoughMemoryException.h:82
Definition: Cdr.h:37