FastCDR  Version 2.3.6
FastCDR
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 
35 namespace eprosima {
36 namespace fastcdr {
42 class Cdr_DllAPI FastCdr
43 {
44 public:
45 
49  class Cdr_DllAPI state
50  {
51  friend class FastCdr;
52 
53  public:
54 
58  state(
59  const FastCdr& fastcdr);
60 
64  state(
65  const state&);
66 
67  private:
68 
69  state& operator =(
70  const state&) = delete;
71 
73  const FastBuffer::iterator current_position_;
74  };
81  FastCdr(
82  FastBuffer& cdr_buffer);
83 
89  bool jump(
90  size_t num_bytes);
91 
95  void reset();
96 
101  char* get_current_position();
102 
107  inline size_t get_serialized_data_length() const
108  {
109  return current_position_ - cdr_buffer_.begin();
110  }
111 
116  FastCdr::state get_state();
117 
122  void set_state(
123  FastCdr::state& state);
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 
660  }
661 
668  inline
670  const int8_t int8)
671  {
672  return serialize(static_cast<char>(int8));
673  }
674 
681  inline
683  const uint16_t ushort_t)
684  {
685  return serialize(static_cast<int16_t>(ushort_t));
686  }
687 
694  inline
696  const int16_t short_t)
697  {
698  if (((last_position_ - current_position_) >= sizeof(short_t)) || resize(sizeof(short_t)))
699  {
700  current_position_ << short_t;
701  current_position_ += sizeof(short_t);
702 
703  return *this;
704  }
705 
708  }
709 
716  inline
718  const uint32_t ulong_t)
719  {
720  return serialize(static_cast<int32_t>(ulong_t));
721  }
722 
729  inline
731  const int32_t long_t)
732  {
733  if (((last_position_ - current_position_) >= sizeof(long_t)) || resize(sizeof(long_t)))
734  {
735  current_position_ << long_t;
736  current_position_ += sizeof(long_t);
737 
738  return *this;
739  }
740 
743  }
744 
751  inline
753  const wchar_t wchar)
754  {
755  return serialize(static_cast<uint32_t>(wchar));
756  }
757 
764  inline
766  const uint64_t ulonglong_t)
767  {
768  return serialize(static_cast<int64_t>(ulonglong_t));
769  }
770 
777  inline
779  const int64_t longlong_t)
780  {
781  if (((last_position_ - current_position_) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
782  {
783  current_position_ << longlong_t;
784  current_position_ += sizeof(longlong_t);
785 
786  return *this;
787  }
788 
791  }
792 
799  inline
801  const float float_t)
802  {
803  if (((last_position_ - current_position_) >= sizeof(float_t)) || resize(sizeof(float_t)))
804  {
805  current_position_ << float_t;
806  current_position_ += sizeof(float_t);
807 
808  return *this;
809  }
810 
813  }
814 
821  inline
823  const double double_t)
824  {
825  if (((last_position_ - current_position_) >= sizeof(double_t)) || resize(sizeof(double_t)))
826  {
827  current_position_ << double_t;
828  current_position_ += sizeof(double_t);
829 
830  return *this;
831  }
832 
835  }
836 
843  inline
845  const long double ldouble_t)
846  {
847  if (((last_position_ - current_position_) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
848  {
849  current_position_ << ldouble_t;
850 #if defined(_WIN32)
851  current_position_ += sizeof(ldouble_t);
852  current_position_ << static_cast<long double>(0);
853 #endif // if defined(_WIN32)
854  current_position_ += sizeof(ldouble_t);
855 
856  return *this;
857  }
858 
861  }
862 
870  const bool bool_t);
871 
879  const char* string_t);
880 
888  const wchar_t* string_t);
889 
897  inline
899  const std::string& string_t)
900  {
901  // Check there are no null characters in the string.
902  const char* c_str = string_t.c_str();
903  const auto str_len = strlen(c_str);
904  if (string_t.size() > str_len)
905  {
906  throw exception::BadParamException("The string contains null characters");
907  }
908 
909  return serialize(c_str);
910  }
911 
918  inline
920  const std::wstring& string_t)
921  {
922  return serialize(string_t.c_str());
923  }
924 
931  template<class _T, size_t _Size>
933  const std::array<_T, _Size>& array_t)
934  {
935  return serialize_array(array_t.data(), array_t.size());
936  }
937 
944  template<class _T = bool>
946  const std::vector<bool>& vector_t)
947  {
948  return serialize_bool_sequence(vector_t);
949  }
950 
957  template<class _T>
959  const std::vector<_T>& vector_t)
960  {
961  state state_before_error(*this);
962 
963  *this << static_cast<int32_t>(vector_t.size());
964 
965  try
966  {
967  return serialize_array(vector_t.data(), vector_t.size());
968  }
970  {
971  set_state(state_before_error);
972  ex.raise();
973  }
974 
975  return *this;
976  }
977 
978 #ifdef _MSC_VER
979 
985  template<>
986  FastCdr& serialize<bool>(
987  const std::vector<bool>& vector_t)
988  {
989  return serialize_bool_sequence(vector_t);
990  }
991 
992 #endif // ifdef _MSC_VER
993 
1000  template<class _T>
1002  const _T& type_t)
1003  {
1004  type_t.serialize(*this);
1005  return *this;
1006  }
1007 
1015  inline
1017  const uint8_t* octet_t,
1018  size_t num_elements)
1019  {
1020  return serialize_array(reinterpret_cast<const char*>(octet_t), num_elements);
1021  }
1022 
1030  FastCdr& serialize_array(
1031  const char* char_t,
1032  size_t num_elements);
1033 
1041  inline
1043  const int8_t* int8,
1044  size_t num_elements)
1045  {
1046  return serialize_array(reinterpret_cast<const char*>(int8), num_elements);
1047  }
1048 
1056  inline
1058  const uint16_t* ushort_t,
1059  size_t num_elements)
1060  {
1061  return serialize_array(reinterpret_cast<const int16_t*>(ushort_t), num_elements);
1062  }
1063 
1071  FastCdr& serialize_array(
1072  const int16_t* short_t,
1073  size_t num_elements);
1074 
1082  inline
1084  const uint32_t* ulong_t,
1085  size_t num_elements)
1086  {
1087  return serialize_array(reinterpret_cast<const int32_t*>(ulong_t), num_elements);
1088  }
1089 
1097  FastCdr& serialize_array(
1098  const int32_t* long_t,
1099  size_t num_elements);
1100 
1108  FastCdr& serialize_array(
1109  const wchar_t* wchar,
1110  size_t num_elements);
1111 
1119  inline
1121  const uint64_t* ulonglong_t,
1122  size_t num_elements)
1123  {
1124  return serialize_array(reinterpret_cast<const int64_t*>(ulonglong_t), num_elements);
1125  }
1126 
1134  FastCdr& serialize_array(
1135  const int64_t* longlong_t,
1136  size_t num_elements);
1137 
1145  FastCdr& serialize_array(
1146  const float* float_t,
1147  size_t num_elements);
1148 
1156  FastCdr& serialize_array(
1157  const double* double_t,
1158  size_t num_elements);
1159 
1167  FastCdr& serialize_array(
1168  const long double* ldouble_t,
1169  size_t num_elements);
1170 
1178  FastCdr& serialize_array(
1179  const bool* bool_t,
1180  size_t num_elements);
1181 
1189  inline
1191  const std::string* string_t,
1192  size_t num_elements)
1193  {
1194  for (size_t count = 0; count < num_elements; ++count)
1195  {
1196  serialize(string_t[count].c_str());
1197  }
1198  return *this;
1199  }
1200 
1208  inline
1210  const std::wstring* string_t,
1211  size_t num_elements)
1212  {
1213  for (size_t count = 0; count < num_elements; ++count)
1214  {
1215  serialize(string_t[count].c_str());
1216  }
1217  return *this;
1218  }
1219 
1227  template<class _T>
1229  const std::vector<_T>* vector_t,
1230  size_t num_elements)
1231  {
1232  for (size_t count = 0; count < num_elements; ++count)
1233  {
1234  serialize(vector_t[count]);
1235  }
1236  return *this;
1237  }
1238 
1246  template<class _T>
1248  const _T* type_t,
1249  size_t num_elements)
1250  {
1251  for (size_t count = 0; count < num_elements; ++count)
1252  {
1253  type_t[count].serialize(*this);
1254  }
1255  return *this;
1256  }
1257 
1265  template<class _T>
1267  const _T* sequence_t,
1268  size_t num_elements)
1269  {
1270  state state_before_error(*this);
1271 
1272  serialize(static_cast<int32_t>(num_elements));
1273 
1274  try
1275  {
1276  return serialize_array(sequence_t, num_elements);
1277  }
1279  {
1280  set_state(state_before_error);
1281  ex.raise();
1282  }
1283 
1284  return *this;
1285  }
1286 
1293  inline
1295  uint8_t& octet_t)
1296  {
1297  return deserialize(reinterpret_cast<char&>(octet_t));
1298  }
1299 
1306  inline
1308  char& char_t)
1309  {
1310  if ((last_position_ - current_position_) >= sizeof(char_t))
1311  {
1312  current_position_++ >> char_t;
1313  return *this;
1314  }
1315 
1318  }
1319 
1326  inline
1328  int8_t& int8)
1329  {
1330  return deserialize(reinterpret_cast<char&>(int8));
1331  }
1332 
1339  inline
1341  uint16_t& ushort_t)
1342  {
1343  return deserialize(reinterpret_cast<int16_t&>(ushort_t));
1344  }
1345 
1352  inline
1354  int16_t& short_t)
1355  {
1356  if ((last_position_ - current_position_) >= sizeof(short_t))
1357  {
1358  current_position_ >> short_t;
1359  current_position_ += sizeof(short_t);
1360 
1361  return *this;
1362  }
1363 
1366  }
1367 
1374  inline
1376  uint32_t& ulong_t)
1377  {
1378  return deserialize(reinterpret_cast<int32_t&>(ulong_t));
1379  }
1380 
1387  inline
1389  int32_t& long_t)
1390  {
1391  if ((last_position_ - current_position_) >= sizeof(long_t))
1392  {
1393  current_position_ >> long_t;
1394  current_position_ += sizeof(long_t);
1395 
1396  return *this;
1397  }
1398 
1401  }
1402 
1409  inline
1411  wchar_t& wchar)
1412  {
1413  uint32_t ret;
1414  deserialize(ret);
1415  wchar = static_cast<wchar_t>(ret);
1416  return *this;
1417  }
1418 
1425  inline
1427  uint64_t& ulonglong_t)
1428  {
1429  return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
1430  }
1431 
1438  inline
1440  int64_t& longlong_t)
1441  {
1442  if ((last_position_ - current_position_) >= sizeof(longlong_t))
1443  {
1444  current_position_ >> longlong_t;
1445  current_position_ += sizeof(longlong_t);
1446 
1447  return *this;
1448  }
1449 
1452  }
1453 
1460  inline
1462  float& float_t)
1463  {
1464  if ((last_position_ - current_position_) >= sizeof(float_t))
1465  {
1466  current_position_ >> float_t;
1467  current_position_ += sizeof(float_t);
1468 
1469  return *this;
1470  }
1471 
1474  }
1475 
1482  inline
1484  double& double_t)
1485  {
1486  if ((last_position_ - current_position_) >= sizeof(double_t))
1487  {
1488  current_position_ >> double_t;
1489  current_position_ += sizeof(double_t);
1490 
1491  return *this;
1492  }
1493 
1496  }
1497 
1504  inline
1506  long double& ldouble_t)
1507  {
1508  if ((last_position_ - current_position_) >= sizeof(ldouble_t))
1509  {
1510  current_position_ >> ldouble_t;
1511  current_position_ += sizeof(ldouble_t);
1512 #if defined(_WIN32)
1513  current_position_ += sizeof(ldouble_t);
1514 #endif // if defined(_WIN32)
1515 
1516  return *this;
1517  }
1518 
1521  }
1522 
1531  bool& bool_t);
1532 
1543  char*& string_t);
1544 
1555  wchar_t*& string_t);
1556 
1563  inline
1565  std::string& string_t)
1566  {
1567  uint32_t length = 0;
1568  const char* str = read_string(length);
1569  string_t.assign(str, length);
1570  return *this;
1571  }
1572 
1579  inline
1581  std::wstring& string_t)
1582  {
1583  uint32_t length = 0;
1584  string_t = read_wstring(length);
1585  return *this;
1586  }
1587 
1594  template<class _T, size_t _Size>
1596  std::array<_T, _Size>& array_t)
1597  {
1598  return deserialize_array(array_t.data(), array_t.size());
1599  }
1600 
1607  template<class _T = bool>
1609  std::vector<bool>& vector_t)
1610  {
1611  return deserialize_bool_sequence(vector_t);
1612  }
1613 
1620  template<class _T>
1622  std::vector<_T>& vector_t)
1623  {
1624  uint32_t sequence_length = 0;
1625  state state_before_error(*this);
1626 
1627  *this >> sequence_length;
1628 
1629  try
1630  {
1631  vector_t.resize(sequence_length);
1632  return deserialize_array(vector_t.data(), vector_t.size());
1633  }
1635  {
1636  set_state(state_before_error);
1637  ex.raise();
1638  }
1639 
1640  return *this;
1641  }
1642 
1643 #ifdef _MSC_VER
1644 
1650  template<>
1651  FastCdr& deserialize<bool>(
1652  std::vector<bool>& vector_t)
1653  {
1654  return deserialize_bool_sequence(vector_t);
1655  }
1656 
1657 #endif // ifdef _MSC_VER
1658 
1665  template<class _T>
1667  _T& type_t)
1668  {
1669  type_t.deserialize(*this);
1670  return *this;
1671  }
1672 
1680  inline
1682  uint8_t* octet_t,
1683  size_t num_elements)
1684  {
1685  return deserialize_array(reinterpret_cast<char*>(octet_t), num_elements);
1686  }
1687 
1695  FastCdr& deserialize_array(
1696  char* char_t,
1697  size_t num_elements);
1698 
1706  inline
1708  int8_t* int8,
1709  size_t num_elements)
1710  {
1711  return deserialize_array(reinterpret_cast<char*>(int8), num_elements);
1712  }
1713 
1721  inline
1723  uint16_t* ushort_t,
1724  size_t num_elements)
1725  {
1726  return deserialize_array(reinterpret_cast<int16_t*>(ushort_t), num_elements);
1727  }
1728 
1736  FastCdr& deserialize_array(
1737  int16_t* short_t,
1738  size_t num_elements);
1739 
1747  inline
1749  uint32_t* ulong_t,
1750  size_t num_elements)
1751  {
1752  return deserialize_array(reinterpret_cast<int32_t*>(ulong_t), num_elements);
1753  }
1754 
1762  FastCdr& deserialize_array(
1763  int32_t* long_t,
1764  size_t num_elements);
1765 
1773  FastCdr& deserialize_array(
1774  wchar_t* wchar,
1775  size_t num_elements);
1776 
1784  inline
1786  uint64_t* ulonglong_t,
1787  size_t num_elements)
1788  {
1789  return deserialize_array(reinterpret_cast<int64_t*>(ulonglong_t), num_elements);
1790  }
1791 
1799  FastCdr& deserialize_array(
1800  int64_t* longlong_t,
1801  size_t num_elements);
1802 
1810  FastCdr& deserialize_array(
1811  float* float_t,
1812  size_t num_elements);
1813 
1821  FastCdr& deserialize_array(
1822  double* double_t,
1823  size_t num_elements);
1824 
1832  FastCdr& deserialize_array(
1833  long double* ldouble_t,
1834  size_t num_elements);
1835 
1843  FastCdr& deserialize_array(
1844  bool* bool_t,
1845  size_t num_elements);
1846 
1854  inline
1856  std::string* string_t,
1857  size_t num_elements)
1858  {
1859  for (size_t count = 0; count < num_elements; ++count)
1860  {
1861  deserialize(string_t[count]);
1862  }
1863  return *this;
1864  }
1865 
1873  inline
1875  std::wstring* string_t,
1876  size_t num_elements)
1877  {
1878  for (size_t count = 0; count < num_elements; ++count)
1879  {
1880  deserialize(string_t[count]);
1881  }
1882  return *this;
1883  }
1884 
1892  template<class _T>
1894  std::vector<_T>* vector_t,
1895  size_t num_elements)
1896  {
1897  for (size_t count = 0; count < num_elements; ++count)
1898  {
1899  deserialize(vector_t[count]);
1900  }
1901  return *this;
1902  }
1903 
1911  template<class _T>
1913  _T* type_t,
1914  size_t num_elements)
1915  {
1916  for (size_t count = 0; count < num_elements; ++count)
1917  {
1918  type_t[count].deserialize(*this);
1919  }
1920  return *this;
1921  }
1922 
1932  template<class _T = std::string>
1934  std::string*& sequence_t,
1935  size_t& num_elements)
1936  {
1937  return deserialize_string_sequence(sequence_t, num_elements);
1938  }
1939 
1949  template<class _T = std::wstring>
1951  std::wstring*& sequence_t,
1952  size_t& num_elements)
1953  {
1954  return deserialize_wstring_sequence(sequence_t, num_elements);
1955  }
1956 
1966  template<class _T>
1968  _T*& sequence_t,
1969  size_t& num_elements)
1970  {
1971  uint32_t sequence_length = 0;
1972  state state_before_error(*this);
1973 
1974  deserialize(sequence_length);
1975 
1976  try
1977  {
1978  sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
1979  deserialize_array(sequence_t, sequence_length);
1980  }
1982  {
1983  free(sequence_t);
1984  sequence_t = NULL;
1985  set_state(state_before_error);
1986  ex.raise();
1987  }
1988 
1989  num_elements = sequence_length;
1990  return *this;
1991  }
1992 
1993 #ifdef _MSC_VER
1994 
2003  template<>
2004  FastCdr& deserialize_sequence<std::string>(
2005  std::string*& sequence_t,
2006  size_t& num_elements)
2007  {
2008  return deserialize_string_sequence(sequence_t, num_elements);
2009  }
2010 
2020  template<>
2021  FastCdr& deserialize_sequence<std::wstring>(
2022  std::wstring*& sequence_t,
2023  size_t& num_elements)
2024  {
2025  return deserialize_wstring_sequence(sequence_t, num_elements);
2026  }
2027 
2028 #endif // ifdef _MSC_VER
2029 
2030 private:
2031 
2032  FastCdr(
2033  const FastCdr&) = delete;
2034 
2035  FastCdr& operator =(
2036  const FastCdr&) = delete;
2037 
2038  FastCdr& serialize_bool_sequence(
2039  const std::vector<bool>& vector_t);
2040 
2041  FastCdr& deserialize_bool_sequence(
2042  std::vector<bool>& vector_t);
2043 
2044  FastCdr& deserialize_string_sequence(
2045  std::string*& sequence_t,
2046  size_t& num_elements);
2047 
2048  FastCdr& deserialize_wstring_sequence(
2049  std::wstring*& sequence_t,
2050  size_t& num_elements);
2051 
2059  template<class _T, size_t _Size>
2060  FastCdr& serialize_array(
2061  const std::array<_T, _Size>* array_t,
2062  size_t num_elements)
2063  {
2064  if (num_elements == 0 || array_t == nullptr)
2065  {
2066  return *this;
2067  }
2068  return serialize_array(array_t->data(), num_elements * array_t->size());
2069  }
2070 
2078  template<class _T, size_t _Size>
2079  FastCdr& deserialize_array(
2080  std::array<_T, _Size>* array_t,
2081  size_t num_elements)
2082  {
2083  if (num_elements == 0 || array_t == nullptr)
2084  {
2085  return *this;
2086  }
2087  return deserialize_array(array_t->data(), num_elements * array_t->size());
2088  }
2089 
2090  bool resize(
2091  size_t min_size_inc);
2092 
2093  const char* read_string(
2094  uint32_t& length);
2095 
2096  std::wstring read_wstring(
2097  uint32_t& length);
2098 
2100  FastBuffer& cdr_buffer_;
2101 
2103  FastBuffer::iterator current_position_;
2104 
2106  FastBuffer::iterator last_position_;
2107 };
2108 } //namespace fastcdr
2109 } //namespace eprosima
2110 
2111 #endif //_FASTCDR_FASTCDR_H_
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const int8_t int8)
This function serializes an int8_t.
Definition: FastCdr.h:669
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
Definition: FastCdr.h:717
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
Definition: FastCdr.h:1375
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
Definition: FastCdr.h:1707
eprosima::fastcdr::FastCdr::get_serialized_data_length
size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Definition: FastCdr.h:107
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
Definition: FastCdr.h:932
eprosima::fastcdr::FastBuffer::iterator
_FastBuffer_iterator iterator
Definition: FastBuffer.h:247
eprosima::fastcdr::exception::Exception
This abstract class is used to create exceptions.
Definition: Exception.h:28
eprosima::fastcdr::FastBuffer
This class represents a stream of bytes that contains (or will contain) serialized data.
Definition: FastBuffer.h:243
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence.
Definition: FastCdr.h:958
eprosima::fastcdr::FastCdr::serialize_sequence
FastCdr & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence.
Definition: FastCdr.h:1266
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Definition: FastCdr.h:1564
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
Definition: FastCdr.h:945
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition: FastCdr.h:1294
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence.
Definition: FastCdr.h:1621
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const float float_t)
This function serializes a float.
Definition: FastCdr.h:800
eprosima::fastcdr::FastCdr::state
This class stores the current state of a CDR serialization.
Definition: FastCdr.h:49
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(double &double_t)
This function deserializes a double.
Definition: FastCdr.h:1483
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wstrings.
Definition: FastCdr.h:1209
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Definition: FastCdr.h:1722
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Definition: FastCdr.h:1327
eprosima::fastcdr::deserialize
void deserialize(Cdr &, _T &)
eprosima::fastcdr::FastCdr::deserialize_sequence
FastCdr & deserialize_sequence(std::string *&sequence_t, size_t &num_elements)
This function template deserializes a string sequence.
Definition: FastCdr.h:1933
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const char char_t)
This function serializes a character.
Definition: FastCdr.h:649
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const std::vector< _T > *vector_t, size_t num_elements)
This function template serializes an array of sequences.
Definition: FastCdr.h:1228
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(int32_t &long_t)
This function deserializes a long.
Definition: FastCdr.h:1388
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
Definition: FastCdr.h:1748
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
Definition: FastCdr.h:1340
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
Definition: FastCdr.h:919
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const double double_t)
This function serializes a double.
Definition: FastCdr.h:822
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(std::vector< _T > *vector_t, size_t num_elements)
This function template deserializes an array of sequences.
Definition: FastCdr.h:1893
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(_T &type_t)
This function template deserializes a non-basic type object.
Definition: FastCdr.h:1666
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(_T *type_t, size_t num_elements)
This function template deserializes an array of non-basic type objects.
Definition: FastCdr.h:1912
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
Definition: FastCdr.h:1681
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::_FastBuffer_iterator
This class implements the iterator used to go through a FastBuffer.
Definition: FastBuffer.h:42
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
Definition: FastCdr.h:1785
eprosima::fastcdr::FastCdr::deserialize_sequence
FastCdr & deserialize_sequence(std::wstring *&sequence_t, size_t &num_elements)
This function template deserializes a wide-string sequence.
Definition: FastCdr.h:1950
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const int16_t short_t)
This function serializes a short.
Definition: FastCdr.h:695
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const uint8_t octet_t)
This function serializes an octet.
Definition: FastCdr.h:636
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
Definition: FastCdr.h:682
eprosima::fastcdr::exception::NotEnoughMemoryException
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
Definition: NotEnoughMemoryException.h:27
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(long double &ldouble_t)
This function deserializes a long double.
Definition: FastCdr.h:1505
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(int64_t &longlong_t)
This function deserializes a long long.
Definition: FastCdr.h:1439
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(int16_t &short_t)
This function deserializes a short.
Definition: FastCdr.h:1353
eprosima::fastcdr::serialize
void serialize(Cdr &, const _T &)
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
Definition: FastCdr.h:1595
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const std::string &string_t)
This function serializes a std::string.
Definition: FastCdr.h:898
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence of booleans.
Definition: FastCdr.h:1608
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
Definition: FastCdr.h:1190
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const int32_t long_t)
This function serializes a long.
Definition: FastCdr.h:730
eprosima::fastcdr::FastCdr::serialize_array
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:1247
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
Definition: FastCdr.h:765
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const int64_t longlong_t)
This function serializes a long long.
Definition: FastCdr.h:778
eprosima::fastcdr::exception::Exception::raise
virtual void raise() const =0
This function throws the object as exception.
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(std::wstring *string_t, size_t num_elements)
This function deserializes an array of wide-strings.
Definition: FastCdr.h:1874
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Definition: FastCdr.h:1426
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(char &char_t)
This function deserializes a character.
Definition: FastCdr.h:1307
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
Definition: FastCdr.h:752
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Definition: FastCdr.h:1120
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
Definition: FastCdr.h:1042
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
Definition: FastCdr.h:1057
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
Definition: FastCdr.h:1410
eprosima
Definition: fixed_size_string.hpp:32
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(float &float_t)
This function deserializes a float.
Definition: FastCdr.h:1461
eprosima::fastcdr::FastCdr
This class offers an interface to serialize/deserialize some basic types using a modified CDR protoco...
Definition: FastCdr.h:42
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const _T &type_t)
This function template serializes a non-basic type.
Definition: FastCdr.h:1001
eprosima::fastcdr::FastCdr::deserialize_sequence
FastCdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence.
Definition: FastCdr.h:1967
eprosima::fastcdr::FastCdr::deserialize
FastCdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Definition: FastCdr.h:1580
eprosima::fastcdr::exception::BadParamException
This class is thrown as an exception when an invalid parameter is being serialized.
Definition: BadParamException.h:27
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
Definition: FastCdr.h:1016
eprosima::fastcdr::FastCdr::deserialize_array
FastCdr & deserialize_array(std::string *string_t, size_t num_elements)
This function deserializes an array of strings.
Definition: FastCdr.h:1855
eprosima::fastcdr::FastCdr::serialize
FastCdr & serialize(const long double ldouble_t)
This function serializes a long double.
Definition: FastCdr.h:844
eprosima::fastcdr::FastCdr::serialize_array
FastCdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
Definition: FastCdr.h:1083