Cdr.cpp
Go to the documentation of this file.
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 #include <fastcdr/Cdr.h>
17 
18 using namespace eprosima::fastcdr;
19 using namespace ::exception;
20 
21 #if FASTCDR_IS_BIG_ENDIAN_TARGET
22 const Cdr::Endianness Cdr::DEFAULT_ENDIAN = BIG_ENDIANNESS;
23 #else
24 const Cdr::Endianness Cdr::DEFAULT_ENDIAN = LITTLE_ENDIANNESS;
25 #endif // if FASTCDR_IS_BIG_ENDIAN_TARGET
26 
27 CONSTEXPR size_t ALIGNMENT_LONG_DOUBLE = 8;
28 
30  const Cdr& cdr)
31  : m_currentPosition(cdr.m_currentPosition)
32  , m_alignPosition(cdr.m_alignPosition)
33  , m_swapBytes(cdr.m_swapBytes)
34  , m_lastDataSize(cdr.m_lastDataSize)
35 {
36 }
37 
39  const state& current_state)
40  : m_currentPosition(current_state.m_currentPosition)
41  , m_alignPosition(current_state.m_alignPosition)
42  , m_swapBytes(current_state.m_swapBytes)
43  , m_lastDataSize(current_state.m_lastDataSize)
44 {
45 }
46 
48  FastBuffer& cdrBuffer,
49  const Endianness endianness,
50  const CdrType cdrType)
51  : m_cdrBuffer(cdrBuffer)
52  , m_cdrType(cdrType)
54  , m_options(0)
55  , m_endianness(static_cast<uint8_t>(endianness))
56  , m_swapBytes(endianness == DEFAULT_ENDIAN ? false : true)
57  , m_lastDataSize(0)
58  , m_currentPosition(cdrBuffer.begin())
59  , m_alignPosition(cdrBuffer.begin())
60  , m_lastPosition(cdrBuffer.end())
61 {
62 }
63 
65 {
66  uint8_t dummy = 0, encapsulationKind = 0;
67  state state_before_error(*this);
68 
69  try
70  {
71  // If it is DDS_CDR, the first step is to get the dummy byte.
72  if (m_cdrType == DDS_CDR)
73  {
74  (*this) >> dummy;
75  if (0 != dummy)
76  {
77  throw BadParamException("Unexpected non-zero initial byte received in Cdr::read_encapsulation");
78  }
79  }
80 
81  // Get the ecampsulation byte.
82  (*this) >> encapsulationKind;
83 
84 
85  // If it is a different endianness, make changes.
86  if (m_endianness != (encapsulationKind & 0x1))
87  {
89  m_endianness = (encapsulationKind & 0x1);
90  }
91 
92  // Check encapsulationKind correctness
93  uint8_t allowed_kind_mask = LITTLE_ENDIANNESS;
94  if (m_cdrType == DDS_CDR)
95  {
96  allowed_kind_mask |= DDS_CDR_WITH_PL;
97  }
98 
99  if (0 != (encapsulationKind & ~allowed_kind_mask))
100  {
101  throw BadParamException("Unexpected CDR type received in Cdr::read_encapsulation");
102  }
103 
104  // If it is DDS_CDR type, view if contains a parameter list.
105  if ((encapsulationKind & DDS_CDR_WITH_PL) && ((m_cdrType == DDS_CDR)))
106  {
108  }
109 
110  if (m_cdrType == DDS_CDR)
111  {
112  (*this) >> m_options;
113  }
114  }
115  catch (Exception& ex)
116  {
117  setState(state_before_error);
118  ex.raise();
119  }
120 
121  resetAlignment();
122  return *this;
123 }
124 
126 {
127  uint8_t dummy = 0, encapsulationKind = 0;
128  state state_before_error(*this);
129 
130  try
131  {
132  // If it is DDS_CDR, the first step is to serialize the dummy byte.
133  if (m_cdrType == DDS_CDR)
134  {
135  (*this) << dummy;
136  }
137 
138  // Construct encapsulation byte.
139  encapsulationKind = (static_cast<uint8_t>(m_plFlag) | m_endianness);
140 
141  // Serialize the encapsulation byte.
142  (*this) << encapsulationKind;
143  }
144  catch (Exception& ex)
145  {
146  setState(state_before_error);
147  ex.raise();
148  }
149 
150  try
151  {
152  if (m_cdrType == DDS_CDR)
153  {
154  (*this) << m_options;
155  }
156  }
157  catch (Exception& ex)
158  {
159  setState(state_before_error);
160  ex.raise();
161  }
162 
163  resetAlignment();
164  return *this;
165 }
166 
168 {
169  return m_plFlag;
170 }
171 
173  DDSCdrPlFlag plFlag)
174 {
175  m_plFlag = plFlag;
176 }
177 
178 uint16_t Cdr::getDDSCdrOptions() const
179 {
180  return m_options;
181 }
182 
184  uint16_t options)
185 {
186  m_options = options;
187 }
188 
191 {
192  if (m_endianness != endianness)
193  {
196  }
197 }
198 
200  size_t numBytes)
201 {
202  bool returnedValue = false;
203 
204  if (((m_lastPosition - m_currentPosition) >= numBytes) || resize(numBytes))
205  {
206  m_currentPosition += numBytes;
207  returnedValue = true;
208  }
209 
210  return returnedValue;
211 }
212 
214 {
215  return m_cdrBuffer.getBuffer();
216 }
217 
219 {
220  return &m_currentPosition;
221 }
222 
224 {
225  return Cdr::state(*this);
226 }
227 
229  state& current_state)
230 {
231  m_currentPosition >> current_state.m_currentPosition;
232  m_alignPosition >> current_state.m_alignPosition;
233  m_swapBytes = current_state.m_swapBytes;
234  m_lastDataSize = current_state.m_lastDataSize;
235 }
236 
238 {
241  m_swapBytes = m_endianness == DEFAULT_ENDIAN ? false : true;
242  m_lastDataSize = 0;
243 }
244 
246  size_t numBytes)
247 {
248  bool returnedValue = false;
249 
250  if (((m_lastPosition - m_alignPosition) >= numBytes) || resize(numBytes))
251  {
252  m_alignPosition += numBytes;
253  returnedValue = true;
254  }
255 
256  return returnedValue;
257 }
258 
260  size_t minSizeInc)
261 {
262  if (m_cdrBuffer.resize(minSizeInc))
263  {
267  return true;
268  }
269 
270  return false;
271 }
272 
274  const char char_t)
275 {
276  if (((m_lastPosition - m_currentPosition) >= sizeof(char_t)) || resize(sizeof(char_t)))
277  {
278  // Save last datasize.
279  m_lastDataSize = sizeof(char_t);
280 
282  return *this;
283  }
284 
285  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
286 }
287 
289  const int16_t short_t)
290 {
291  size_t align = alignment(sizeof(short_t));
292  size_t sizeAligned = sizeof(short_t) + align;
293 
294  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
295  {
296  // Save last datasize.
297  m_lastDataSize = sizeof(short_t);
298 
299  // Align.
300  makeAlign(align);
301 
302  if (m_swapBytes)
303  {
304  const char* dst = reinterpret_cast<const char*>(&short_t);
305 
306  m_currentPosition++ << dst[1];
307  m_currentPosition++ << dst[0];
308  }
309  else
310  {
311  m_currentPosition << short_t;
312  m_currentPosition += sizeof(short_t);
313  }
314 
315  return *this;
316  }
317 
318  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
319 }
320 
322  const int16_t short_t,
324 {
325  bool auxSwap = m_swapBytes;
326  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
327 
328  try
329  {
330  serialize(short_t);
331  m_swapBytes = auxSwap;
332  }
333  catch (Exception& ex)
334  {
335  m_swapBytes = auxSwap;
336  ex.raise();
337  }
338 
339  return *this;
340 }
341 
343  const int32_t long_t)
344 {
345  size_t align = alignment(sizeof(long_t));
346  size_t sizeAligned = sizeof(long_t) + align;
347 
348  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
349  {
350  // Save last datasize.
351  m_lastDataSize = sizeof(long_t);
352 
353  // Align.
354  makeAlign(align);
355 
356  if (m_swapBytes)
357  {
358  const char* dst = reinterpret_cast<const char*>(&long_t);
359 
360  m_currentPosition++ << dst[3];
361  m_currentPosition++ << dst[2];
362  m_currentPosition++ << dst[1];
363  m_currentPosition++ << dst[0];
364  }
365  else
366  {
367  m_currentPosition << long_t;
368  m_currentPosition += sizeof(long_t);
369  }
370 
371  return *this;
372  }
373 
374  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
375 }
376 
378  const int32_t long_t,
380 {
381  bool auxSwap = m_swapBytes;
382  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
383 
384  try
385  {
386  serialize(long_t);
387  m_swapBytes = auxSwap;
388  }
389  catch (Exception& ex)
390  {
391  m_swapBytes = auxSwap;
392  ex.raise();
393  }
394 
395  return *this;
396 }
397 
399  const int64_t longlong_t)
400 {
401  size_t align = alignment(sizeof(longlong_t));
402  size_t sizeAligned = sizeof(longlong_t) + align;
403 
404  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
405  {
406  // Save last datasize.
407  m_lastDataSize = sizeof(longlong_t);
408 
409  // Align.
410  makeAlign(align);
411 
412  if (m_swapBytes)
413  {
414  const char* dst = reinterpret_cast<const char*>(&longlong_t);
415 
416  m_currentPosition++ << dst[7];
417  m_currentPosition++ << dst[6];
418  m_currentPosition++ << dst[5];
419  m_currentPosition++ << dst[4];
420  m_currentPosition++ << dst[3];
421  m_currentPosition++ << dst[2];
422  m_currentPosition++ << dst[1];
423  m_currentPosition++ << dst[0];
424  }
425  else
426  {
427  m_currentPosition << longlong_t;
428  m_currentPosition += sizeof(longlong_t);
429  }
430 
431  return *this;
432  }
433 
434  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
435 }
436 
438  const int64_t longlong_t,
440 {
441  bool auxSwap = m_swapBytes;
442  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
443 
444  try
445  {
446  serialize(longlong_t);
447  m_swapBytes = auxSwap;
448  }
449  catch (Exception& ex)
450  {
451  m_swapBytes = auxSwap;
452  ex.raise();
453  }
454 
455  return *this;
456 }
457 
459  const float float_t)
460 {
461  size_t align = alignment(sizeof(float_t));
462  size_t sizeAligned = sizeof(float_t) + align;
463 
464  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
465  {
466  // Save last datasize.
467  m_lastDataSize = sizeof(float_t);
468 
469  // Align.
470  makeAlign(align);
471 
472  if (m_swapBytes)
473  {
474  const char* dst = reinterpret_cast<const char*>(&float_t);
475 
476  m_currentPosition++ << dst[3];
477  m_currentPosition++ << dst[2];
478  m_currentPosition++ << dst[1];
479  m_currentPosition++ << dst[0];
480  }
481  else
482  {
483  m_currentPosition << float_t;
484  m_currentPosition += sizeof(float_t);
485  }
486 
487  return *this;
488  }
489 
490  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
491 }
492 
494  const float float_t,
496 {
497  bool auxSwap = m_swapBytes;
498  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
499 
500  try
501  {
502  serialize(float_t);
503  m_swapBytes = auxSwap;
504  }
505  catch (Exception& ex)
506  {
507  m_swapBytes = auxSwap;
508  ex.raise();
509  }
510 
511  return *this;
512 }
513 
515  const double double_t)
516 {
517  size_t align = alignment(sizeof(double_t));
518  size_t sizeAligned = sizeof(double_t) + align;
519 
520  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
521  {
522  // Save last datasize.
523  m_lastDataSize = sizeof(double_t);
524 
525  // Align.
526  makeAlign(align);
527 
528  if (m_swapBytes)
529  {
530  const char* dst = reinterpret_cast<const char*>(&double_t);
531 
532  m_currentPosition++ << dst[7];
533  m_currentPosition++ << dst[6];
534  m_currentPosition++ << dst[5];
535  m_currentPosition++ << dst[4];
536  m_currentPosition++ << dst[3];
537  m_currentPosition++ << dst[2];
538  m_currentPosition++ << dst[1];
539  m_currentPosition++ << dst[0];
540  }
541  else
542  {
543  m_currentPosition << double_t;
544  m_currentPosition += sizeof(double_t);
545  }
546 
547  return *this;
548  }
549 
550  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
551 }
552 
554  const double double_t,
556 {
557  bool auxSwap = m_swapBytes;
558  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
559 
560  try
561  {
562  serialize(double_t);
563  m_swapBytes = auxSwap;
564  }
565  catch (Exception& ex)
566  {
567  m_swapBytes = auxSwap;
568  ex.raise();
569  }
570 
571  return *this;
572 }
573 
575  const long double ldouble_t)
576 {
578  size_t sizeAligned = sizeof(ldouble_t) + align;
579 
580  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
581  {
582  // Save last datasize.
583  m_lastDataSize = 16; // sizeof(ldouble_t);
584 
585  // Align.
586  makeAlign(align);
587 
588  if (m_swapBytes)
589  {
590 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
591  __float128 tmp = ldouble_t;
592  const char* dst = reinterpret_cast<const char*>(&tmp);
593 #else
594  const char* dst = reinterpret_cast<const char*>(&ldouble_t);
595 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
596 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
597  m_currentPosition++ << dst[15];
598  m_currentPosition++ << dst[14];
599  m_currentPosition++ << dst[13];
600  m_currentPosition++ << dst[12];
601  m_currentPosition++ << dst[11];
602  m_currentPosition++ << dst[10];
603  m_currentPosition++ << dst[9];
604  m_currentPosition++ << dst[8];
605  m_currentPosition++ << dst[7];
606  m_currentPosition++ << dst[6];
607  m_currentPosition++ << dst[5];
608  m_currentPosition++ << dst[4];
609  m_currentPosition++ << dst[3];
610  m_currentPosition++ << dst[2];
611  m_currentPosition++ << dst[1];
612  m_currentPosition++ << dst[0];
613 #else
614 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
615  // Filled with 0's.
616  m_currentPosition++ << static_cast<char>(0);
617  m_currentPosition++ << static_cast<char>(0);
618  m_currentPosition++ << static_cast<char>(0);
619  m_currentPosition++ << static_cast<char>(0);
620  m_currentPosition++ << static_cast<char>(0);
621  m_currentPosition++ << static_cast<char>(0);
622  m_currentPosition++ << static_cast<char>(0);
623  m_currentPosition++ << static_cast<char>(0);
624  m_currentPosition++ << dst[7];
625  m_currentPosition++ << dst[6];
626  m_currentPosition++ << dst[5];
627  m_currentPosition++ << dst[4];
628  m_currentPosition++ << dst[3];
629  m_currentPosition++ << dst[2];
630  m_currentPosition++ << dst[1];
631  m_currentPosition++ << dst[0];
632 #else
633 #error unsupported long double type and no __float128 available
634 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
635 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
636  }
637  else
638  {
639 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
640  __float128 tmp = ldouble_t;
641  m_currentPosition << tmp;
642  m_currentPosition += 16;
643 #else
644 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
645  m_currentPosition << static_cast<long double>(0);
646  m_currentPosition += sizeof(ldouble_t);
647 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
648 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
649  m_currentPosition << ldouble_t;
650  m_currentPosition += sizeof(ldouble_t);
651 #else
652 #error unsupported long double type and no __float128 available
653 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
654 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
655  }
656 
657  return *this;
658  }
659 
660  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
661 }
662 
664  const long double ldouble_t,
666 {
667  bool auxSwap = m_swapBytes;
668  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
669 
670  try
671  {
672  serialize(ldouble_t);
673  m_swapBytes = auxSwap;
674  }
675  catch (Exception& ex)
676  {
677  m_swapBytes = auxSwap;
678  ex.raise();
679  }
680 
681  return *this;
682 }
683 
685  const bool bool_t)
686 {
687  uint8_t value = 0;
688 
689  if (((m_lastPosition - m_currentPosition) >= sizeof(uint8_t)) || resize(sizeof(uint8_t)))
690  {
691  // Save last datasize.
692  m_lastDataSize = sizeof(uint8_t);
693 
694  if (bool_t)
695  {
696  value = 1;
697  }
698  m_currentPosition++ << value;
699 
700  return *this;
701  }
702 
703  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
704 }
705 
707  const char* string_t)
708 {
709  uint32_t length = 0;
710 
711  if (string_t != nullptr)
712  {
713  length = size_to_uint32(strlen(string_t)) + 1;
714  }
715 
716  if (length > 0)
717  {
718  Cdr::state state_before_error(*this);
719  serialize(length);
720 
721  if (((m_lastPosition - m_currentPosition) >= length) || resize(length))
722  {
723  // Save last datasize.
724  m_lastDataSize = sizeof(uint8_t);
725 
726  m_currentPosition.memcopy(string_t, length);
727  m_currentPosition += length;
728  }
729  else
730  {
731  setState(state_before_error);
732  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
733  }
734  }
735  else
736  {
737  serialize(length);
738  }
739 
740  return *this;
741 }
742 
744  const wchar_t* string_t)
745 {
746  uint32_t bytesLength = 0;
747  size_t wstrlen = 0;
748 
749  if (string_t != nullptr)
750  {
751  wstrlen = wcslen(string_t);
752  bytesLength = size_to_uint32(wstrlen * 4);
753  }
754 
755  if (bytesLength > 0)
756  {
757  Cdr::state state_(*this);
758  serialize(size_to_uint32(wstrlen));
759 
760  if (((m_lastPosition - m_currentPosition) >= bytesLength) || resize(bytesLength))
761  {
762  // Save last datasize.
763  m_lastDataSize = sizeof(uint32_t);
764 
765 #if defined(_WIN32)
766  serializeArray(string_t, wstrlen);
767 #else
768  m_currentPosition.memcopy(string_t, bytesLength);
769  m_currentPosition += bytesLength; // size on bytes
770 #endif // if defined(_WIN32)
771  }
772  else
773  {
774  setState(state_);
775  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
776  }
777  }
778  else
779  {
780  serialize(bytesLength);
781  }
782 
783  return *this;
784 }
785 
787  const char* string_t,
789 {
790  bool auxSwap = m_swapBytes;
791  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
792 
793  try
794  {
795  serialize(string_t);
796  m_swapBytes = auxSwap;
797  }
798  catch (Exception& ex)
799  {
800  m_swapBytes = auxSwap;
801  ex.raise();
802  }
803 
804  return *this;
805 }
806 
808  const wchar_t* string_t,
810 {
811  bool auxSwap = m_swapBytes;
812  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
813 
814  try
815  {
816  serialize(string_t);
817  m_swapBytes = auxSwap;
818  }
819  catch (Exception& ex)
820  {
821  m_swapBytes = auxSwap;
822  ex.raise();
823  }
824 
825  return *this;
826 }
827 
829  const bool* bool_t,
830  size_t numElements)
831 {
832  size_t totalSize = sizeof(*bool_t) * numElements;
833 
834  if (((m_lastPosition - m_currentPosition) >= totalSize) || resize(totalSize))
835  {
836  // Save last datasize.
837  m_lastDataSize = sizeof(*bool_t);
838 
839  for (size_t count = 0; count < numElements; ++count)
840  {
841  uint8_t value = 0;
842 
843  if (bool_t[count])
844  {
845  value = 1;
846  }
847  m_currentPosition++ << value;
848  }
849 
850  return *this;
851  }
852 
853  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
854 }
855 
857  const char* char_t,
858  size_t numElements)
859 {
860  size_t totalSize = sizeof(*char_t) * numElements;
861 
862  if (((m_lastPosition - m_currentPosition) >= totalSize) || resize(totalSize))
863  {
864  // Save last datasize.
865  m_lastDataSize = sizeof(*char_t);
866 
867  m_currentPosition.memcopy(char_t, totalSize);
868  m_currentPosition += totalSize;
869  return *this;
870  }
871 
872  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
873 }
874 
876  const int16_t* short_t,
877  size_t numElements)
878 {
879  if (numElements == 0)
880  {
881  return *this;
882  }
883 
884  size_t align = alignment(sizeof(*short_t));
885  size_t totalSize = sizeof(*short_t) * numElements;
886  size_t sizeAligned = totalSize + align;
887 
888  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
889  {
890  // Save last datasize.
891  m_lastDataSize = sizeof(*short_t);
892 
893  // Align if there are any elements
894  if (numElements)
895  {
896  makeAlign(align);
897  }
898 
899  if (m_swapBytes)
900  {
901  const char* dst = reinterpret_cast<const char*>(&short_t);
902  const char* end = dst + totalSize;
903 
904  for (; dst < end; dst += sizeof(*short_t))
905  {
906  m_currentPosition++ << dst[1];
907  m_currentPosition++ << dst[0];
908  }
909  }
910  else
911  {
912  m_currentPosition.memcopy(short_t, totalSize);
913  m_currentPosition += totalSize;
914  }
915 
916  return *this;
917  }
918 
919  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
920 }
921 
923  const int16_t* short_t,
924  size_t numElements,
926 {
927  bool auxSwap = m_swapBytes;
928  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
929 
930  try
931  {
932  serializeArray(short_t, numElements);
933  m_swapBytes = auxSwap;
934  }
935  catch (Exception& ex)
936  {
937  m_swapBytes = auxSwap;
938  ex.raise();
939  }
940 
941  return *this;
942 }
943 
945  const int32_t* long_t,
946  size_t numElements)
947 {
948  if (numElements == 0)
949  {
950  return *this;
951  }
952 
953  size_t align = alignment(sizeof(*long_t));
954  size_t totalSize = sizeof(*long_t) * numElements;
955  size_t sizeAligned = totalSize + align;
956 
957  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
958  {
959  // Save last datasize.
960  m_lastDataSize = sizeof(*long_t);
961 
962  // Align if there are any elements
963  if (numElements)
964  {
965  makeAlign(align);
966  }
967 
968  if (m_swapBytes)
969  {
970  const char* dst = reinterpret_cast<const char*>(&long_t);
971  const char* end = dst + totalSize;
972 
973  for (; dst < end; dst += sizeof(*long_t))
974  {
975  m_currentPosition++ << dst[3];
976  m_currentPosition++ << dst[2];
977  m_currentPosition++ << dst[1];
978  m_currentPosition++ << dst[0];
979  }
980  }
981  else
982  {
983  m_currentPosition.memcopy(long_t, totalSize);
984  m_currentPosition += totalSize;
985  }
986 
987  return *this;
988  }
989 
990  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
991 }
992 
994  const int32_t* long_t,
995  size_t numElements,
997 {
998  bool auxSwap = m_swapBytes;
999  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1000 
1001  try
1002  {
1003  serializeArray(long_t, numElements);
1004  m_swapBytes = auxSwap;
1005  }
1006  catch (Exception& ex)
1007  {
1008  m_swapBytes = auxSwap;
1009  ex.raise();
1010  }
1011 
1012  return *this;
1013 }
1014 
1016  const wchar_t* wchar,
1017  size_t numElements)
1018 {
1019  if (numElements == 0)
1020  {
1021  return *this;
1022  }
1023 
1024  for (size_t count = 0; count < numElements; ++count)
1025  {
1026  serialize(wchar[count]);
1027  }
1028  return *this;
1029 }
1030 
1032  const wchar_t* wchar,
1033  size_t numElements,
1035 {
1036  bool auxSwap = m_swapBytes;
1037  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1038 
1039  try
1040  {
1041  serializeArray(wchar, numElements);
1042  m_swapBytes = auxSwap;
1043  }
1044  catch (Exception& ex)
1045  {
1046  m_swapBytes = auxSwap;
1047  ex.raise();
1048  }
1049 
1050  return *this;
1051 }
1052 
1054  const int64_t* longlong_t,
1055  size_t numElements)
1056 {
1057  if (numElements == 0)
1058  {
1059  return *this;
1060  }
1061 
1062  size_t align = alignment(sizeof(*longlong_t));
1063  size_t totalSize = sizeof(*longlong_t) * numElements;
1064  size_t sizeAligned = totalSize + align;
1065 
1066  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
1067  {
1068  // Save last datasize.
1069  m_lastDataSize = sizeof(*longlong_t);
1070 
1071  // Align if there are any elements
1072  if (numElements)
1073  {
1074  makeAlign(align);
1075  }
1076 
1077  if (m_swapBytes)
1078  {
1079  const char* dst = reinterpret_cast<const char*>(&longlong_t);
1080  const char* end = dst + totalSize;
1081 
1082  for (; dst < end; dst += sizeof(*longlong_t))
1083  {
1084  m_currentPosition++ << dst[7];
1085  m_currentPosition++ << dst[6];
1086  m_currentPosition++ << dst[5];
1087  m_currentPosition++ << dst[4];
1088  m_currentPosition++ << dst[3];
1089  m_currentPosition++ << dst[2];
1090  m_currentPosition++ << dst[1];
1091  m_currentPosition++ << dst[0];
1092  }
1093  }
1094  else
1095  {
1096  m_currentPosition.memcopy(longlong_t, totalSize);
1097  m_currentPosition += totalSize;
1098  }
1099 
1100  return *this;
1101  }
1102 
1103  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1104 }
1105 
1107  const int64_t* longlong_t,
1108  size_t numElements,
1110 {
1111  bool auxSwap = m_swapBytes;
1112  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1113 
1114  try
1115  {
1116  serializeArray(longlong_t, numElements);
1117  m_swapBytes = auxSwap;
1118  }
1119  catch (Exception& ex)
1120  {
1121  m_swapBytes = auxSwap;
1122  ex.raise();
1123  }
1124 
1125  return *this;
1126 }
1127 
1129  const float* float_t,
1130  size_t numElements)
1131 {
1132  if (numElements == 0)
1133  {
1134  return *this;
1135  }
1136 
1137  size_t align = alignment(sizeof(*float_t));
1138  size_t totalSize = sizeof(*float_t) * numElements;
1139  size_t sizeAligned = totalSize + align;
1140 
1141  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
1142  {
1143  // Save last datasize.
1144  m_lastDataSize = sizeof(*float_t);
1145 
1146  // Align if there are any elements
1147  if (numElements)
1148  {
1149  makeAlign(align);
1150  }
1151 
1152  if (m_swapBytes)
1153  {
1154  const char* dst = reinterpret_cast<const char*>(&float_t);
1155  const char* end = dst + totalSize;
1156 
1157  for (; dst < end; dst += sizeof(*float_t))
1158  {
1159  m_currentPosition++ << dst[3];
1160  m_currentPosition++ << dst[2];
1161  m_currentPosition++ << dst[1];
1162  m_currentPosition++ << dst[0];
1163  }
1164  }
1165  else
1166  {
1167  m_currentPosition.memcopy(float_t, totalSize);
1168  m_currentPosition += totalSize;
1169  }
1170 
1171  return *this;
1172  }
1173 
1174  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1175 }
1176 
1178  const float* float_t,
1179  size_t numElements,
1181 {
1182  bool auxSwap = m_swapBytes;
1183  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1184 
1185  try
1186  {
1187  serializeArray(float_t, numElements);
1188  m_swapBytes = auxSwap;
1189  }
1190  catch (Exception& ex)
1191  {
1192  m_swapBytes = auxSwap;
1193  ex.raise();
1194  }
1195 
1196  return *this;
1197 }
1198 
1200  const double* double_t,
1201  size_t numElements)
1202 {
1203  if (numElements == 0)
1204  {
1205  return *this;
1206  }
1207 
1208  size_t align = alignment(sizeof(*double_t));
1209  size_t totalSize = sizeof(*double_t) * numElements;
1210  size_t sizeAligned = totalSize + align;
1211 
1212  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
1213  {
1214  // Save last datasize.
1215  m_lastDataSize = sizeof(*double_t);
1216 
1217  // Align if there are any elements
1218  if (numElements)
1219  {
1220  makeAlign(align);
1221  }
1222 
1223  if (m_swapBytes)
1224  {
1225  const char* dst = reinterpret_cast<const char*>(&double_t);
1226  const char* end = dst + totalSize;
1227 
1228  for (; dst < end; dst += sizeof(*double_t))
1229  {
1230  m_currentPosition++ << dst[7];
1231  m_currentPosition++ << dst[6];
1232  m_currentPosition++ << dst[5];
1233  m_currentPosition++ << dst[4];
1234  m_currentPosition++ << dst[3];
1235  m_currentPosition++ << dst[2];
1236  m_currentPosition++ << dst[1];
1237  m_currentPosition++ << dst[0];
1238  }
1239  }
1240  else
1241  {
1242  m_currentPosition.memcopy(double_t, totalSize);
1243  m_currentPosition += totalSize;
1244  }
1245 
1246  return *this;
1247  }
1248 
1249  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1250 }
1251 
1253  const double* double_t,
1254  size_t numElements,
1256 {
1257  bool auxSwap = m_swapBytes;
1258  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1259 
1260  try
1261  {
1262  serializeArray(double_t, numElements);
1263  m_swapBytes = auxSwap;
1264  }
1265  catch (Exception& ex)
1266  {
1267  m_swapBytes = auxSwap;
1268  ex.raise();
1269  }
1270 
1271  return *this;
1272 }
1273 
1275  const long double* ldouble_t,
1276  size_t numElements)
1277 {
1278  if (numElements == 0)
1279  {
1280  return *this;
1281  }
1282 
1284  // Fix for Windows ( long doubles only store 8 bytes )
1285  size_t totalSize = 16 * numElements; // sizeof(*ldouble_t)
1286  size_t sizeAligned = totalSize + align;
1287 
1288  if (((m_lastPosition - m_currentPosition) >= sizeAligned) || resize(sizeAligned))
1289  {
1290  // Save last datasize.
1291  m_lastDataSize = 16;
1292 
1293  // Align if there are any elements
1294  if (numElements)
1295  {
1296  makeAlign(align);
1297  }
1298 
1299 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1300  if (m_swapBytes)
1301  {
1302  for (size_t i = 0; i < numElements; ++i, ++ldouble_t)
1303  {
1304  __float128 tmp = *ldouble_t;
1305  const char* dst = reinterpret_cast<const char*>(&tmp);
1306  m_currentPosition++ << dst[15];
1307  m_currentPosition++ << dst[14];
1308  m_currentPosition++ << dst[13];
1309  m_currentPosition++ << dst[12];
1310  m_currentPosition++ << dst[11];
1311  m_currentPosition++ << dst[10];
1312  m_currentPosition++ << dst[9];
1313  m_currentPosition++ << dst[8];
1314  m_currentPosition++ << dst[7];
1315  m_currentPosition++ << dst[6];
1316  m_currentPosition++ << dst[5];
1317  m_currentPosition++ << dst[4];
1318  m_currentPosition++ << dst[3];
1319  m_currentPosition++ << dst[2];
1320  m_currentPosition++ << dst[1];
1321  m_currentPosition++ << dst[0];
1322  }
1323  }
1324  else
1325  {
1326  for (size_t i = 0; i < numElements; ++i, ++ldouble_t)
1327  {
1328  __float128 tmp = *ldouble_t;
1329  m_currentPosition << tmp;
1330  m_currentPosition += 16;
1331  }
1332  }
1333 #else
1334 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1335  if (m_swapBytes)
1336  {
1337  const char* dst = reinterpret_cast<const char*>(&ldouble_t);
1338  const char* end = dst + totalSize;
1339 
1340  for (; dst < end; dst += sizeof(*ldouble_t))
1341  {
1342 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1343  m_currentPosition++ << dst[15];
1344  m_currentPosition++ << dst[14];
1345  m_currentPosition++ << dst[13];
1346  m_currentPosition++ << dst[12];
1347  m_currentPosition++ << dst[11];
1348  m_currentPosition++ << dst[10];
1349  m_currentPosition++ << dst[9];
1350  m_currentPosition++ << dst[8];
1351 #else
1352  m_currentPosition++ << static_cast<char>(0);
1353  m_currentPosition++ << static_cast<char>(0);
1354  m_currentPosition++ << static_cast<char>(0);
1355  m_currentPosition++ << static_cast<char>(0);
1356  m_currentPosition++ << static_cast<char>(0);
1357  m_currentPosition++ << static_cast<char>(0);
1358  m_currentPosition++ << static_cast<char>(0);
1359  m_currentPosition++ << static_cast<char>(0);
1360 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1361  m_currentPosition++ << dst[7];
1362  m_currentPosition++ << dst[6];
1363  m_currentPosition++ << dst[5];
1364  m_currentPosition++ << dst[4];
1365  m_currentPosition++ << dst[3];
1366  m_currentPosition++ << dst[2];
1367  m_currentPosition++ << dst[1];
1368  m_currentPosition++ << dst[0];
1369  }
1370  }
1371  else
1372  {
1373 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1374  m_currentPosition.memcopy(ldouble_t, totalSize);
1375  m_currentPosition += totalSize;
1376 #else
1377  for (size_t i = 0; i < numElements; ++i)
1378  {
1379  m_currentPosition << static_cast<long double>(0);
1380  m_currentPosition += 8;
1381  m_currentPosition << ldouble_t[i];
1382  m_currentPosition += 8;
1383  }
1384 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1385  }
1386 #else
1387 #error unsupported long double type and no __float128 available
1388 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1389 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1390 
1391  return *this;
1392  }
1393 
1394  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1395 }
1396 
1398  const long double* ldouble_t,
1399  size_t numElements,
1401 {
1402  bool auxSwap = m_swapBytes;
1403  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1404 
1405  try
1406  {
1407  serializeArray(ldouble_t, numElements);
1408  m_swapBytes = auxSwap;
1409  }
1410  catch (Exception& ex)
1411  {
1412  m_swapBytes = auxSwap;
1413  ex.raise();
1414  }
1415 
1416  return *this;
1417 }
1418 
1420  char& char_t)
1421 {
1422  if ((m_lastPosition - m_currentPosition) >= sizeof(char_t))
1423  {
1424  // Save last datasize.
1425  m_lastDataSize = sizeof(char_t);
1426 
1428  return *this;
1429  }
1430 
1431  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1432 }
1433 
1435  int16_t& short_t)
1436 {
1437  size_t align = alignment(sizeof(short_t));
1438  size_t sizeAligned = sizeof(short_t) + align;
1439 
1440  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1441  {
1442  // Save last datasize.
1443  m_lastDataSize = sizeof(short_t);
1444 
1445  // Align
1446  makeAlign(align);
1447 
1448  if (m_swapBytes)
1449  {
1450  char* dst = reinterpret_cast<char*>(&short_t);
1451 
1452  m_currentPosition++ >> dst[1];
1453  m_currentPosition++ >> dst[0];
1454  }
1455  else
1456  {
1457  m_currentPosition >> short_t;
1458  m_currentPosition += sizeof(short_t);
1459  }
1460 
1461  return *this;
1462  }
1463 
1464  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1465 }
1466 
1468  int16_t& short_t,
1470 {
1471  bool auxSwap = m_swapBytes;
1472  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1473 
1474  try
1475  {
1476  deserialize(short_t);
1477  m_swapBytes = auxSwap;
1478  }
1479  catch (Exception& ex)
1480  {
1481  m_swapBytes = auxSwap;
1482  ex.raise();
1483  }
1484 
1485  return *this;
1486 }
1487 
1489  int32_t& long_t)
1490 {
1491  size_t align = alignment(sizeof(long_t));
1492  size_t sizeAligned = sizeof(long_t) + align;
1493 
1494  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1495  {
1496  // Save last datasize.
1497  m_lastDataSize = sizeof(long_t);
1498 
1499  // Align
1500  makeAlign(align);
1501 
1502  if (m_swapBytes)
1503  {
1504  char* dst = reinterpret_cast<char*>(&long_t);
1505 
1506  m_currentPosition++ >> dst[3];
1507  m_currentPosition++ >> dst[2];
1508  m_currentPosition++ >> dst[1];
1509  m_currentPosition++ >> dst[0];
1510  }
1511  else
1512  {
1513  m_currentPosition >> long_t;
1514  m_currentPosition += sizeof(long_t);
1515  }
1516 
1517  return *this;
1518  }
1519 
1520  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1521 }
1522 
1524  int32_t& long_t,
1526 {
1527  bool auxSwap = m_swapBytes;
1528  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1529 
1530  try
1531  {
1532  deserialize(long_t);
1533  m_swapBytes = auxSwap;
1534  }
1535  catch (Exception& ex)
1536  {
1537  m_swapBytes = auxSwap;
1538  ex.raise();
1539  }
1540 
1541  return *this;
1542 }
1543 
1545  int64_t& longlong_t)
1546 {
1547  size_t align = alignment(sizeof(longlong_t));
1548  size_t sizeAligned = sizeof(longlong_t) + align;
1549 
1550  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1551  {
1552  // Save last datasize.
1553  m_lastDataSize = sizeof(longlong_t);
1554 
1555  // Align.
1556  makeAlign(align);
1557 
1558  if (m_swapBytes)
1559  {
1560  char* dst = reinterpret_cast<char*>(&longlong_t);
1561 
1562  m_currentPosition++ >> dst[7];
1563  m_currentPosition++ >> dst[6];
1564  m_currentPosition++ >> dst[5];
1565  m_currentPosition++ >> dst[4];
1566  m_currentPosition++ >> dst[3];
1567  m_currentPosition++ >> dst[2];
1568  m_currentPosition++ >> dst[1];
1569  m_currentPosition++ >> dst[0];
1570  }
1571  else
1572  {
1573  m_currentPosition >> longlong_t;
1574  m_currentPosition += sizeof(longlong_t);
1575  }
1576 
1577  return *this;
1578  }
1579 
1580  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1581 }
1582 
1584  int64_t& longlong_t,
1586 {
1587  bool auxSwap = m_swapBytes;
1588  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1589 
1590  try
1591  {
1592  deserialize(longlong_t);
1593  m_swapBytes = auxSwap;
1594  }
1595  catch (Exception& ex)
1596  {
1597  m_swapBytes = auxSwap;
1598  ex.raise();
1599  }
1600 
1601  return *this;
1602 }
1603 
1605  float& float_t)
1606 {
1607  size_t align = alignment(sizeof(float_t));
1608  size_t sizeAligned = sizeof(float_t) + align;
1609 
1610  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1611  {
1612  // Save last datasize.
1613  m_lastDataSize = sizeof(float_t);
1614 
1615  // Align.
1616  makeAlign(align);
1617 
1618  if (m_swapBytes)
1619  {
1620  char* dst = reinterpret_cast<char*>(&float_t);
1621 
1622  m_currentPosition++ >> dst[3];
1623  m_currentPosition++ >> dst[2];
1624  m_currentPosition++ >> dst[1];
1625  m_currentPosition++ >> dst[0];
1626  }
1627  else
1628  {
1629  m_currentPosition >> float_t;
1630  m_currentPosition += sizeof(float_t);
1631  }
1632 
1633  return *this;
1634  }
1635 
1636  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1637 }
1638 
1640  float& float_t,
1642 {
1643  bool auxSwap = m_swapBytes;
1644  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1645 
1646  try
1647  {
1648  deserialize(float_t);
1649  m_swapBytes = auxSwap;
1650  }
1651  catch (Exception& ex)
1652  {
1653  m_swapBytes = auxSwap;
1654  ex.raise();
1655  }
1656 
1657  return *this;
1658 }
1659 
1661  double& double_t)
1662 {
1663  size_t align = alignment(sizeof(double_t));
1664  size_t sizeAligned = sizeof(double_t) + align;
1665 
1666  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1667  {
1668  // Save last datasize.
1669  m_lastDataSize = sizeof(double_t);
1670 
1671  // Align.
1672  makeAlign(align);
1673 
1674  if (m_swapBytes)
1675  {
1676  char* dst = reinterpret_cast<char*>(&double_t);
1677 
1678  m_currentPosition++ >> dst[7];
1679  m_currentPosition++ >> dst[6];
1680  m_currentPosition++ >> dst[5];
1681  m_currentPosition++ >> dst[4];
1682  m_currentPosition++ >> dst[3];
1683  m_currentPosition++ >> dst[2];
1684  m_currentPosition++ >> dst[1];
1685  m_currentPosition++ >> dst[0];
1686  }
1687  else
1688  {
1689  m_currentPosition >> double_t;
1690  m_currentPosition += sizeof(double_t);
1691  }
1692 
1693  return *this;
1694  }
1695 
1696  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1697 }
1698 
1700  double& double_t,
1702 {
1703  bool auxSwap = m_swapBytes;
1704  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1705 
1706  try
1707  {
1708  deserialize(double_t);
1709  m_swapBytes = auxSwap;
1710  }
1711  catch (Exception& ex)
1712  {
1713  m_swapBytes = auxSwap;
1714  ex.raise();
1715  }
1716 
1717  return *this;
1718 }
1719 
1721  long double& ldouble_t)
1722 {
1724  size_t sizeAligned = sizeof(ldouble_t) + align;
1725 
1726  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
1727  {
1728  // Save last datasize.
1729  m_lastDataSize = 16; // sizeof(ldouble_t);
1730 
1731  // Align.
1732  makeAlign(align);
1733 
1734  if (m_swapBytes)
1735  {
1736 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1737  __float128 tmp = ldouble_t;
1738  char* dst = reinterpret_cast<char*>(&tmp);
1739 #else
1740  char* dst = reinterpret_cast<char*>(&ldouble_t);
1741 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1742 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1743  m_currentPosition++ >> dst[15];
1744  m_currentPosition++ >> dst[14];
1745  m_currentPosition++ >> dst[13];
1746  m_currentPosition++ >> dst[12];
1747  m_currentPosition++ >> dst[11];
1748  m_currentPosition++ >> dst[10];
1749  m_currentPosition++ >> dst[9];
1750  m_currentPosition++ >> dst[8];
1751  m_currentPosition++ >> dst[7];
1752  m_currentPosition++ >> dst[6];
1753  m_currentPosition++ >> dst[5];
1754  m_currentPosition++ >> dst[4];
1755  m_currentPosition++ >> dst[3];
1756  m_currentPosition++ >> dst[2];
1757  m_currentPosition++ >> dst[1];
1758  m_currentPosition++ >> dst[0];
1759 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1760  ldouble_t = static_cast<long double>(tmp);
1761 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1762 #else
1763 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1764  m_currentPosition += 8;
1765  m_currentPosition++ >> dst[7];
1766  m_currentPosition++ >> dst[6];
1767  m_currentPosition++ >> dst[5];
1768  m_currentPosition++ >> dst[4];
1769  m_currentPosition++ >> dst[3];
1770  m_currentPosition++ >> dst[2];
1771  m_currentPosition++ >> dst[1];
1772  m_currentPosition++ >> dst[0];
1773 #else
1774 #error unsupported long double type and no __float128 available
1775 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1776 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1777  }
1778  else
1779  {
1780 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1781  __float128 tmp;
1782  m_currentPosition >> tmp;
1783  m_currentPosition += 16;
1784  ldouble_t = static_cast<long double>(tmp);
1785 #else
1786 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1787 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1788  m_currentPosition += 8;
1789 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1790  m_currentPosition >> ldouble_t;
1791  m_currentPosition += sizeof(ldouble_t);
1792 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1793 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1794  }
1795 
1796  return *this;
1797  }
1798 
1799  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1800 }
1801 
1803  long double& ldouble_t,
1805 {
1806  bool auxSwap = m_swapBytes;
1807  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1808 
1809  try
1810  {
1811  deserialize(ldouble_t);
1812  m_swapBytes = auxSwap;
1813  }
1814  catch (Exception& ex)
1815  {
1816  m_swapBytes = auxSwap;
1817  ex.raise();
1818  }
1819 
1820  return *this;
1821 }
1822 
1824  bool& bool_t)
1825 {
1826  uint8_t value = 0;
1827 
1828  if ((m_lastPosition - m_currentPosition) >= sizeof(uint8_t))
1829  {
1830  // Save last datasize.
1831  m_lastDataSize = sizeof(uint8_t);
1832 
1833  m_currentPosition++ >> value;
1834 
1835  if (value == 1)
1836  {
1837  bool_t = true;
1838  return *this;
1839  }
1840  else if (value == 0)
1841  {
1842  bool_t = false;
1843  return *this;
1844  }
1845 
1846  throw BadParamException("Unexpected byte value in Cdr::deserialize(bool), expected 0 or 1");
1847  }
1848 
1849  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1850 }
1851 
1853  char*& string_t)
1854 {
1855  uint32_t length = 0;
1856  Cdr::state state_before_error(*this);
1857 
1858  deserialize(length);
1859 
1860  if (length == 0)
1861  {
1862  string_t = NULL;
1863  return *this;
1864  }
1865  else if ((m_lastPosition - m_currentPosition) >= length)
1866  {
1867  // Save last datasize.
1868  m_lastDataSize = sizeof(uint8_t);
1869 
1870  // Allocate memory.
1871  string_t =
1872  reinterpret_cast<char*>(calloc(length + ((&m_currentPosition)[length - 1] == '\0' ? 0 : 1),
1873  sizeof(char)));
1874  memcpy(string_t, &m_currentPosition, length);
1875  m_currentPosition += length;
1876  return *this;
1877  }
1878 
1879  setState(state_before_error);
1880  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1881 }
1882 
1884  wchar_t*& string_t)
1885 {
1886  uint32_t length = 0;
1887  Cdr::state state_before_error(*this);
1888 
1889  deserialize(length);
1890 
1891  if (length == 0)
1892  {
1893  string_t = NULL;
1894  return *this;
1895  }
1896  else if ((m_lastPosition - m_currentPosition) >= length)
1897  {
1898  // Save last datasize.
1899  m_lastDataSize = 4;
1900  // Allocate memory.
1901  string_t = reinterpret_cast<wchar_t*>(calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero
1902 
1903 #if defined(_WIN32)
1904  for (size_t idx = 0; idx < length; ++idx)
1905  {
1906  uint32_t temp;
1907  m_currentPosition >> temp;
1908  string_t[idx] = static_cast<wchar_t>(temp);
1909  m_currentPosition += 4;
1910  }
1911 #else
1912  memcpy(string_t, &m_currentPosition, length * sizeof(wchar_t));
1913  m_currentPosition += length * sizeof(wchar_t);
1914 #endif // if defined(_WIN32)
1915  return *this;
1916  }
1917 
1918  setState(state_before_error);
1919  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1920 }
1921 
1923  char*& string_t,
1925 {
1926  bool auxSwap = m_swapBytes;
1927  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1928 
1929  try
1930  {
1931  deserialize(string_t);
1932  m_swapBytes = auxSwap;
1933  }
1934  catch (Exception& ex)
1935  {
1936  m_swapBytes = auxSwap;
1937  ex.raise();
1938  }
1939 
1940  return *this;
1941 }
1942 
1944  wchar_t*& string_t,
1946 {
1947  bool auxSwap = m_swapBytes;
1948  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
1949 
1950  try
1951  {
1952  deserialize(string_t);
1953  m_swapBytes = auxSwap;
1954  }
1955  catch (Exception& ex)
1956  {
1957  m_swapBytes = auxSwap;
1958  ex.raise();
1959  }
1960 
1961  return *this;
1962 }
1963 
1964 const char* Cdr::readString(
1965  uint32_t& length)
1966 {
1967  const char* returnedValue = "";
1968  state state_before_error(*this);
1969 
1970  *this >> length;
1971 
1972  if (length == 0)
1973  {
1974  return returnedValue;
1975  }
1976  else if ((m_lastPosition - m_currentPosition) >= length)
1977  {
1978  // Save last datasize.
1979  m_lastDataSize = sizeof(uint8_t);
1980 
1981  returnedValue = &m_currentPosition;
1982  m_currentPosition += length;
1983  if (returnedValue[length - 1] == '\0')
1984  {
1985  --length;
1986  }
1987  return returnedValue;
1988  }
1989 
1990  setState(state_before_error);
1993 }
1994 
1995 const std::wstring Cdr::readWString(
1996  uint32_t& length)
1997 {
1998  std::wstring returnedValue = L"";
1999  state state_(*this);
2000 
2001  *this >> length;
2002  uint32_t bytesLength = length * 4;
2003 
2004  if (bytesLength == 0)
2005  {
2006  return returnedValue;
2007  }
2008  else if ((m_lastPosition - m_currentPosition) >= bytesLength)
2009  {
2010  // Save last datasize.
2011  m_lastDataSize = sizeof(uint32_t);
2012 
2013  returnedValue.resize(length);
2014  deserializeArray(const_cast<wchar_t*>(returnedValue.c_str()), length);
2015  if (returnedValue[length - 1] == L'\0')
2016  {
2017  --length;
2018  returnedValue.erase(length);
2019  }
2020  return returnedValue;
2021  }
2022 
2023  setState(state_);
2026 }
2027 
2029  bool* bool_t,
2030  size_t numElements)
2031 {
2032  size_t totalSize = sizeof(*bool_t) * numElements;
2033 
2034  if ((m_lastPosition - m_currentPosition) >= totalSize)
2035  {
2036  // Save last datasize.
2037  m_lastDataSize = sizeof(*bool_t);
2038 
2039  for (size_t count = 0; count < numElements; ++count)
2040  {
2041  uint8_t value = 0;
2042  m_currentPosition++ >> value;
2043 
2044  if (value == 1)
2045  {
2046  bool_t[count] = true;
2047  }
2048  else if (value == 0)
2049  {
2050  bool_t[count] = false;
2051  }
2052  }
2053 
2054  return *this;
2055  }
2056 
2057  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2058 }
2059 
2061  char* char_t,
2062  size_t numElements)
2063 {
2064  size_t totalSize = sizeof(*char_t) * numElements;
2065 
2066  if ((m_lastPosition - m_currentPosition) >= totalSize)
2067  {
2068  // Save last datasize.
2069  m_lastDataSize = sizeof(*char_t);
2070 
2071  m_currentPosition.rmemcopy(char_t, totalSize);
2072  m_currentPosition += totalSize;
2073  return *this;
2074  }
2075 
2076  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2077 }
2078 
2080  int16_t* short_t,
2081  size_t numElements)
2082 {
2083  if (numElements == 0)
2084  {
2085  return *this;
2086  }
2087 
2088  size_t align = alignment(sizeof(*short_t));
2089  size_t totalSize = sizeof(*short_t) * numElements;
2090  size_t sizeAligned = totalSize + align;
2091 
2092  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2093  {
2094  // Save last datasize.
2095  m_lastDataSize = sizeof(*short_t);
2096 
2097  // Align if there are any elements
2098  if (numElements)
2099  {
2100  makeAlign(align);
2101  }
2102 
2103  if (m_swapBytes)
2104  {
2105  char* dst = reinterpret_cast<char*>(short_t);
2106  char* end = dst + totalSize;
2107 
2108  for (; dst < end; dst += sizeof(*short_t))
2109  {
2110  m_currentPosition++ >> dst[1];
2111  m_currentPosition++ >> dst[0];
2112  }
2113  }
2114  else
2115  {
2116  m_currentPosition.rmemcopy(short_t, totalSize);
2117  m_currentPosition += totalSize;
2118  }
2119 
2120  return *this;
2121  }
2122 
2123  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2124 }
2125 
2127  int16_t* short_t,
2128  size_t numElements,
2130 {
2131  bool auxSwap = m_swapBytes;
2132  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2133 
2134  try
2135  {
2136  deserializeArray(short_t, numElements);
2137  m_swapBytes = auxSwap;
2138  }
2139  catch (Exception& ex)
2140  {
2141  m_swapBytes = auxSwap;
2142  ex.raise();
2143  }
2144 
2145  return *this;
2146 }
2147 
2149  int32_t* long_t,
2150  size_t numElements)
2151 {
2152  if (numElements == 0)
2153  {
2154  return *this;
2155  }
2156 
2157  size_t align = alignment(sizeof(*long_t));
2158  size_t totalSize = sizeof(*long_t) * numElements;
2159  size_t sizeAligned = totalSize + align;
2160 
2161  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2162  {
2163  // Save last datasize.
2164  m_lastDataSize = sizeof(*long_t);
2165 
2166  // Align if there are any elements
2167  if (numElements)
2168  {
2169  makeAlign(align);
2170  }
2171 
2172  if (m_swapBytes)
2173  {
2174  char* dst = reinterpret_cast<char*>(long_t);
2175  char* end = dst + totalSize;
2176 
2177  for (; dst < end; dst += sizeof(*long_t))
2178  {
2179  m_currentPosition++ >> dst[3];
2180  m_currentPosition++ >> dst[2];
2181  m_currentPosition++ >> dst[1];
2182  m_currentPosition++ >> dst[0];
2183  }
2184  }
2185  else
2186  {
2187  m_currentPosition.rmemcopy(long_t, totalSize);
2188  m_currentPosition += totalSize;
2189  }
2190 
2191  return *this;
2192  }
2193 
2194  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2195 }
2196 
2198  int32_t* long_t,
2199  size_t numElements,
2201 {
2202  bool auxSwap = m_swapBytes;
2203  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2204 
2205  try
2206  {
2207  deserializeArray(long_t, numElements);
2208  m_swapBytes = auxSwap;
2209  }
2210  catch (Exception& ex)
2211  {
2212  m_swapBytes = auxSwap;
2213  ex.raise();
2214  }
2215 
2216  return *this;
2217 }
2218 
2220  wchar_t* wchar,
2221  size_t numElements)
2222 {
2223  if (numElements == 0)
2224  {
2225  return *this;
2226  }
2227 
2228  uint32_t value;
2229  for (size_t count = 0; count < numElements; ++count)
2230  {
2231  deserialize(value);
2232  wchar[count] = static_cast<wchar_t>(value);
2233  }
2234  return *this;
2235 }
2236 
2238  wchar_t* wchar,
2239  size_t numElements,
2241 {
2242  bool auxSwap = m_swapBytes;
2243  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2244 
2245  try
2246  {
2247  deserializeArray(wchar, numElements);
2248  m_swapBytes = auxSwap;
2249  }
2250  catch (Exception& ex)
2251  {
2252  m_swapBytes = auxSwap;
2253  ex.raise();
2254  }
2255 
2256  return *this;
2257 }
2258 
2260  int64_t* longlong_t,
2261  size_t numElements)
2262 {
2263  if (numElements == 0)
2264  {
2265  return *this;
2266  }
2267 
2268  size_t align = alignment(sizeof(*longlong_t));
2269  size_t totalSize = sizeof(*longlong_t) * numElements;
2270  size_t sizeAligned = totalSize + align;
2271 
2272  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2273  {
2274  // Save last datasize.
2275  m_lastDataSize = sizeof(*longlong_t);
2276 
2277  // Align if there are any elements
2278  if (numElements)
2279  {
2280  makeAlign(align);
2281  }
2282 
2283  if (m_swapBytes)
2284  {
2285  char* dst = reinterpret_cast<char*>(longlong_t);
2286  char* end = dst + totalSize;
2287 
2288  for (; dst < end; dst += sizeof(*longlong_t))
2289  {
2290  m_currentPosition++ >> dst[7];
2291  m_currentPosition++ >> dst[6];
2292  m_currentPosition++ >> dst[5];
2293  m_currentPosition++ >> dst[4];
2294  m_currentPosition++ >> dst[3];
2295  m_currentPosition++ >> dst[2];
2296  m_currentPosition++ >> dst[1];
2297  m_currentPosition++ >> dst[0];
2298  }
2299  }
2300  else
2301  {
2302  m_currentPosition.rmemcopy(longlong_t, totalSize);
2303  m_currentPosition += totalSize;
2304  }
2305 
2306  return *this;
2307  }
2308 
2309  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2310 }
2311 
2313  int64_t* longlong_t,
2314  size_t numElements,
2316 {
2317  bool auxSwap = m_swapBytes;
2318  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2319 
2320  try
2321  {
2322  deserializeArray(longlong_t, numElements);
2323  m_swapBytes = auxSwap;
2324  }
2325  catch (Exception& ex)
2326  {
2327  m_swapBytes = auxSwap;
2328  ex.raise();
2329  }
2330 
2331  return *this;
2332 }
2333 
2335  float* float_t,
2336  size_t numElements)
2337 {
2338  if (numElements == 0)
2339  {
2340  return *this;
2341  }
2342 
2343  size_t align = alignment(sizeof(*float_t));
2344  size_t totalSize = sizeof(*float_t) * numElements;
2345  size_t sizeAligned = totalSize + align;
2346 
2347  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2348  {
2349  // Save last datasize.
2350  m_lastDataSize = sizeof(*float_t);
2351 
2352  // Align if there are any elements
2353  if (numElements)
2354  {
2355  makeAlign(align);
2356  }
2357 
2358  if (m_swapBytes)
2359  {
2360  char* dst = reinterpret_cast<char*>(float_t);
2361  char* end = dst + totalSize;
2362 
2363  for (; dst < end; dst += sizeof(*float_t))
2364  {
2365  m_currentPosition++ >> dst[3];
2366  m_currentPosition++ >> dst[2];
2367  m_currentPosition++ >> dst[1];
2368  m_currentPosition++ >> dst[0];
2369  }
2370  }
2371  else
2372  {
2373  m_currentPosition.rmemcopy(float_t, totalSize);
2374  m_currentPosition += totalSize;
2375  }
2376 
2377  return *this;
2378  }
2379 
2380  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2381 }
2382 
2384  float* float_t,
2385  size_t numElements,
2387 {
2388  bool auxSwap = m_swapBytes;
2389  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2390 
2391  try
2392  {
2393  deserializeArray(float_t, numElements);
2394  m_swapBytes = auxSwap;
2395  }
2396  catch (Exception& ex)
2397  {
2398  m_swapBytes = auxSwap;
2399  ex.raise();
2400  }
2401 
2402  return *this;
2403 }
2404 
2406  double* double_t,
2407  size_t numElements)
2408 {
2409  if (numElements == 0)
2410  {
2411  return *this;
2412  }
2413 
2414  size_t align = alignment(sizeof(*double_t));
2415  size_t totalSize = sizeof(*double_t) * numElements;
2416  size_t sizeAligned = totalSize + align;
2417 
2418  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2419  {
2420  // Save last datasize.
2421  m_lastDataSize = sizeof(*double_t);
2422 
2423  // Align if there are any elements
2424  if (numElements)
2425  {
2426  makeAlign(align);
2427  }
2428 
2429  if (m_swapBytes)
2430  {
2431  char* dst = reinterpret_cast<char*>(double_t);
2432  char* end = dst + totalSize;
2433 
2434  for (; dst < end; dst += sizeof(*double_t))
2435  {
2436  m_currentPosition++ >> dst[7];
2437  m_currentPosition++ >> dst[6];
2438  m_currentPosition++ >> dst[5];
2439  m_currentPosition++ >> dst[4];
2440  m_currentPosition++ >> dst[3];
2441  m_currentPosition++ >> dst[2];
2442  m_currentPosition++ >> dst[1];
2443  m_currentPosition++ >> dst[0];
2444  }
2445  }
2446  else
2447  {
2448  m_currentPosition.rmemcopy(double_t, totalSize);
2449  m_currentPosition += totalSize;
2450  }
2451 
2452  return *this;
2453  }
2454 
2455  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2456 }
2457 
2459  double* double_t,
2460  size_t numElements,
2462 {
2463  bool auxSwap = m_swapBytes;
2464  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2465 
2466  try
2467  {
2468  deserializeArray(double_t, numElements);
2469  m_swapBytes = auxSwap;
2470  }
2471  catch (Exception& ex)
2472  {
2473  m_swapBytes = auxSwap;
2474  ex.raise();
2475  }
2476 
2477  return *this;
2478 }
2479 
2481  long double* ldouble_t,
2482  size_t numElements)
2483 {
2484  if (numElements == 0)
2485  {
2486  return *this;
2487  }
2488 
2490  // Fix for Windows ( long doubles only store 8 bytes )
2491  size_t totalSize = 16 * numElements;
2492  size_t sizeAligned = totalSize + align;
2493 
2494  if ((m_lastPosition - m_currentPosition) >= sizeAligned)
2495  {
2496  // Save last datasize.
2497  m_lastDataSize = 16;
2498 
2499  // Align if there are any elements
2500  if (numElements)
2501  {
2502  makeAlign(align);
2503  }
2504 
2505 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2506  if (m_swapBytes)
2507  {
2508  for (size_t i = 0; i < numElements; ++i)
2509  {
2510  __float128 tmp;
2511  char* dst = reinterpret_cast<char*>(&tmp);
2512  m_currentPosition++ >> dst[15];
2513  m_currentPosition++ >> dst[14];
2514  m_currentPosition++ >> dst[13];
2515  m_currentPosition++ >> dst[12];
2516  m_currentPosition++ >> dst[11];
2517  m_currentPosition++ >> dst[10];
2518  m_currentPosition++ >> dst[9];
2519  m_currentPosition++ >> dst[8];
2520  m_currentPosition++ >> dst[7];
2521  m_currentPosition++ >> dst[6];
2522  m_currentPosition++ >> dst[5];
2523  m_currentPosition++ >> dst[4];
2524  m_currentPosition++ >> dst[3];
2525  m_currentPosition++ >> dst[2];
2526  m_currentPosition++ >> dst[1];
2527  m_currentPosition++ >> dst[0];
2528  ldouble_t[i] = static_cast<long double>(tmp);
2529  }
2530  }
2531  else
2532  {
2533  for (size_t i = 0; i < numElements; ++i)
2534  {
2535  __float128 tmp;
2536  m_currentPosition >> tmp;
2537  m_currentPosition += 16;
2538  ldouble_t[i] = static_cast<long double>(tmp);
2539  }
2540  }
2541 #else
2542 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2543  if (m_swapBytes)
2544  {
2545  char* dst = reinterpret_cast<char*>(ldouble_t);
2546  char* end = dst + numElements * sizeof(*ldouble_t);
2547 
2548  for (; dst < end; dst += sizeof(*ldouble_t))
2549  {
2550 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2551  m_currentPosition++ >> dst[15];
2552  m_currentPosition++ >> dst[14];
2553  m_currentPosition++ >> dst[13];
2554  m_currentPosition++ >> dst[12];
2555  m_currentPosition++ >> dst[11];
2556  m_currentPosition++ >> dst[10];
2557  m_currentPosition++ >> dst[9];
2558  m_currentPosition++ >> dst[8];
2559 #else
2560  m_currentPosition += 8;
2561 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2562  m_currentPosition++ >> dst[7];
2563  m_currentPosition++ >> dst[6];
2564  m_currentPosition++ >> dst[5];
2565  m_currentPosition++ >> dst[4];
2566  m_currentPosition++ >> dst[3];
2567  m_currentPosition++ >> dst[2];
2568  m_currentPosition++ >> dst[1];
2569  m_currentPosition++ >> dst[0];
2570  }
2571  }
2572  else
2573  {
2574 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2575  m_currentPosition.rmemcopy(ldouble_t, totalSize);
2576  m_currentPosition += totalSize;
2577 #else
2578  for (size_t i = 0; i < numElements; ++i)
2579  {
2580  m_currentPosition += 8; // ignore first 8 bytes
2581  m_currentPosition >> ldouble_t[i];
2582  m_currentPosition += 8;
2583  }
2584 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2585  }
2586 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2587 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2588 
2589  return *this;
2590  }
2591 
2592  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2593 }
2594 
2596  long double* ldouble_t,
2597  size_t numElements,
2599 {
2600  bool auxSwap = m_swapBytes;
2601  m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
2602 
2603  try
2604  {
2605  deserializeArray(ldouble_t, numElements);
2606  m_swapBytes = auxSwap;
2607  }
2608  catch (Exception& ex)
2609  {
2610  m_swapBytes = auxSwap;
2611  ex.raise();
2612  }
2613 
2614  return *this;
2615 }
2616 
2618  const std::vector<bool>& vector_t)
2619 {
2620  state state_before_error(*this);
2621 
2622  *this << static_cast<int32_t>(vector_t.size());
2623 
2624  size_t totalSize = vector_t.size() * sizeof(bool);
2625 
2626  if (((m_lastPosition - m_currentPosition) >= totalSize) || resize(totalSize))
2627  {
2628  // Save last datasize.
2629  m_lastDataSize = sizeof(bool);
2630 
2631  for (size_t count = 0; count < vector_t.size(); ++count)
2632  {
2633  uint8_t value = 0;
2634  std::vector<bool>::const_reference ref = vector_t[count];
2635 
2636  if (ref)
2637  {
2638  value = 1;
2639  }
2640  m_currentPosition++ << value;
2641  }
2642  }
2643  else
2644  {
2645  setState(state_before_error);
2646  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2647  }
2648 
2649  return *this;
2650 }
2651 
2653  std::vector<bool>& vector_t)
2654 {
2655  uint32_t seqLength = 0;
2656  state state_before_error(*this);
2657 
2658  *this >> seqLength;
2659 
2660  size_t totalSize = seqLength * sizeof(bool);
2661 
2662  if ((m_lastPosition - m_currentPosition) >= totalSize)
2663  {
2664  vector_t.resize(seqLength);
2665  // Save last datasize.
2666  m_lastDataSize = sizeof(bool);
2667 
2668  for (uint32_t count = 0; count < seqLength; ++count)
2669  {
2670  uint8_t value = 0;
2671  m_currentPosition++ >> value;
2672 
2673  if (value == 1)
2674  {
2675  vector_t[count] = true;
2676  }
2677  else if (value == 0)
2678  {
2679  vector_t[count] = false;
2680  }
2681  else
2682  {
2683  throw BadParamException("Unexpected byte value in Cdr::deserializeBoolSequence, expected 0 or 1");
2684  }
2685  }
2686  }
2687  else
2688  {
2689  setState(state_before_error);
2690  throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
2691  }
2692 
2693  return *this;
2694 }
2695 
2697  std::string*& sequence_t,
2698  size_t& numElements)
2699 {
2700  uint32_t seqLength = 0;
2701  state state_before_error(*this);
2702 
2703  deserialize(seqLength);
2704 
2705  try
2706  {
2707  sequence_t = new std::string[seqLength];
2708  deserializeArray(sequence_t, seqLength);
2709  }
2711  {
2712  delete [] sequence_t;
2713  sequence_t = NULL;
2714  setState(state_before_error);
2715  ex.raise();
2716  }
2717 
2718  numElements = seqLength;
2719  return *this;
2720 }
2721 
2723  std::wstring*& sequence_t,
2724  size_t& numElements)
2725 {
2726  uint32_t seqLength = 0;
2727  state state_before_error(*this);
2728 
2729  deserialize(seqLength);
2730 
2731  try
2732  {
2733  sequence_t = new std::wstring[seqLength];
2734  deserializeArray(sequence_t, seqLength);
2735  }
2737  {
2738  delete [] sequence_t;
2739  sequence_t = NULL;
2740  setState(state_before_error);
2741  ex.raise();
2742  }
2743 
2744  numElements = seqLength;
2745  return *this;
2746 }
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
static size_t alignment(size_t current_alignment, size_t dataSize)
Get the number of bytes needed to align a position to certain data size.
Definition: Cdr.h:239
void setState(state &state)
This function sets a previous state of the CDR serialization process;.
Definition: Cdr.cpp:228
void reset()
This function resets the current position in the buffer to the beginning.
Definition: Cdr.cpp:237
bool moveAlignmentForward(size_t numBytes)
This function moves the alignment forward.
Definition: Cdr.cpp:245
Definition: core.h:1869
FastBuffer::iterator m_lastPosition
The last position in the buffer;.
Definition: Cdr.h:3552
bool resize(size_t minSizeInc)
This function resizes the internal buffer. It only applies if the FastBuffer object was created with ...
Definition: Cdr.cpp:259
This abstract class is used to create exceptions.
Definition: Exception.h:29
CdrType
This enumeration represents the two kinds of CDR serialization supported by eprosima::fastcdr::CDR.
Definition: Cdr.h:48
typename detail::char_t_impl< S >::type char_t
Definition: core.h:621
Cdr & serializeBoolSequence(const std::vector< bool > &vector_t)
Definition: Cdr.cpp:2617
This class is thrown as an exception when the buffer&#39;s internal memory reachs its size limit...
Cdr & read_encapsulation()
This function reads the encapsulation of the CDR stream. If the CDR stream contains an encapsulation...
Definition: Cdr.cpp:64
Cdr & deserializeArray(uint8_t *octet_t, size_t numElements)
This function deserializes an array of octets.
Definition: Cdr.h:2708
const char * readString(uint32_t &length)
Definition: Cdr.cpp:1964
constexpr std::uintptr_t align(std::size_t alignment, std::uintptr_t ptr, std::size_t &space)
Definition: sol.hpp:10963
Specifies that the content is not a parameter list.
Definition: Cdr.h:65
uint8_t m_endianness
The endianness that will be applied over the buffer.
Definition: Cdr.h:3537
DDSCdrPlFlag getDDSCdrPlFlag() const
This function returns the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:167
static Cdr_DllAPI const char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
uint16_t m_options
This attribute stores the option flags when the CDR type is DDS_CDR;.
Definition: Cdr.h:3534
Cdr & deserializeWStringSequence(std::wstring *&sequence_t, size_t &numElements)
Definition: Cdr.cpp:2722
DDS CDR serialization.
Definition: Cdr.h:53
char * dst
Definition: lz4.h:724
void changeEndianness(Endianness endianness)
This function sets the current endianness used by the CDR type.
Definition: Cdr.cpp:189
void setDDSCdrOptions(uint16_t options)
This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:183
FastBuffer::iterator m_currentPosition
The current position in the serialization/deserialization process.
Definition: Cdr.h:3546
const FastBuffer::iterator m_currentPosition
The position in the buffer when the state was created.
Definition: Cdr.h:115
uint16_t getDDSCdrOptions() const
This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:178
Endianness endianness() const
This function returns the current endianness used by the CDR type.
Definition: Cdr.h:194
iterator begin()
This function returns a iterator that points to the begining of the stream.
Definition: FastBuffer.h:302
FastBuffer::iterator m_alignPosition
The position from where the aligment is calculated.
Definition: Cdr.h:3549
char * getCurrentPosition()
This function returns the current position in the CDR stream.
Definition: Cdr.cpp:218
uint32_t size_to_uint32(size_t val)
Definition: FastBuffer.h:25
void rmemcopy(void *dst, const size_t size)
This function copies from the raw buffer to a external buffer.
Definition: FastBuffer.h:146
const FastBuffer::iterator m_alignPosition
The position from the aligment is calculated, when the state was created..
Definition: Cdr.h:118
static const Endianness DEFAULT_ENDIAN
Default endiness in the system.
Definition: Cdr.h:86
This class stores the current state of a CDR serialization.
Definition: Cdr.h:91
Cdr & serializeArray(const uint8_t *octet_t, size_t numElements)
This function serializes an array of octets.
Definition: Cdr.h:1419
Cdr & deserializeStringSequence(std::string *&sequence_t, size_t &numElements)
Definition: Cdr.cpp:2696
state(const Cdr &cdr)
Default constructor.
Definition: Cdr.cpp:29
constexpr auto count() -> size_t
Definition: core.h:1050
Cdr & serialize_encapsulation()
This function writes the encapsulation of the CDR stream. If the CDR stream should contain an encapsu...
Definition: Cdr.cpp:125
char * getBufferPointer()
This function returns the pointer to the current used buffer.
Definition: Cdr.cpp:213
This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an...
Definition: Cdr.h:43
int dummy
Definition: lstrlib.c:1350
bool jump(size_t numBytes)
This function skips a number of bytes in the CDR stream buffer.
Definition: Cdr.cpp:199
bool m_swapBytes
This attribute specified if it is needed to swap the bytes when the state was created..
Definition: Cdr.h:121
Cdr & deserializeBoolSequence(std::vector< bool > &vector_t)
Definition: Cdr.cpp:2652
DDSCdrPlFlag
This enumeration represents the two posible values of the flag that points if the content is a parame...
Definition: Cdr.h:61
Endianness
This enumeration represents endianness types.
Definition: Cdr.h:76
This class represents a stream of bytes that contains (or will contain) serialized data...
Definition: FastBuffer.h:228
Cdr(FastBuffer &cdrBuffer, const Endianness endianness=DEFAULT_ENDIAN, const CdrType cdrType=CORBA_CDR)
This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize the assigned...
Definition: Cdr.cpp:47
DDSCdrPlFlag m_plFlag
Using DDS_CDR type, this attribute stores if the stream buffer contains a parameter list or not...
Definition: Cdr.h:3531
bool resize(size_t minSizeInc)
This function resizes the raw buffer. It will call the user&#39;s defined function for this purpose...
Definition: FastBuffer.cpp:66
void makeAlign(size_t align)
This function jumps the number of bytes of the alignment. These bytes should be calculated with the f...
Definition: Cdr.h:3504
const std::wstring readWString(uint32_t &length)
Definition: Cdr.cpp:1995
void memcopy(const void *src, const size_t size)
This function copies a buffer into the raw buffer.
Definition: FastBuffer.h:130
FastBuffer & m_cdrBuffer
Reference to the buffer that will be serialized/deserialized.
Definition: Cdr.h:3525
char * getBuffer() const
This function returns the stream that the eprosima::fastcdr::FastBuffers uses to serialize data...
Definition: FastBuffer.h:283
Definition: core.h:1131
void resetAlignment()
This function resets the alignment to the current position in the buffer.
Definition: Cdr.h:270
state getState()
This function returns the current state of the CDR serialization process.
Definition: Cdr.cpp:223
size_t m_lastDataSize
Stores the last datasize serialized/deserialized. It&#39;s used to optimize.
Definition: Cdr.h:3543
iterator end()
This function returns a iterator that points to the end of the stream.
Definition: FastBuffer.h:312
Cdr & serialize(const uint8_t octet_t)
This function serializes an octet.
Definition: Cdr.h:819
size_t m_lastDataSize
Stores the last datasize serialized/deserialized when the state was created.
Definition: Cdr.h:124
void setDDSCdrPlFlag(DDSCdrPlFlag plFlag)
This function sets the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:172
Specifies that the content is a parameter list.
Definition: Cdr.h:67
CONSTEXPR size_t ALIGNMENT_LONG_DOUBLE
Definition: Cdr.cpp:27
CdrType m_cdrType
The type of CDR that will be use in serialization/deserialization.
Definition: Cdr.h:3528
Cdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition: Cdr.h:2035
bool m_swapBytes
This attribute specifies if it is needed to swap the bytes.
Definition: Cdr.h:3540


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:01