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 <cstring>
16 #include <limits>
17 
18 #include <fastcdr/Cdr.h>
19 
20 namespace eprosima {
21 namespace fastcdr {
22 
23 using namespace exception;
24 
25 #if FASTCDR_IS_BIG_ENDIAN_TARGET
26 const Cdr::Endianness Cdr::DEFAULT_ENDIAN = BIG_ENDIANNESS;
27 #else
28 const Cdr::Endianness Cdr::DEFAULT_ENDIAN = LITTLE_ENDIANNESS;
29 #endif // if FASTCDR_IS_BIG_ENDIAN_TARGET
30 
31 constexpr uint16_t PID_EXTENDED = 0x3F01;
32 constexpr uint16_t PID_EXTENDED_LENGTH = 0x8;
33 constexpr uint16_t PID_SENTINEL = 0x3F02;
34 constexpr uint16_t PID_SENTINEL_LENGTH = 0x0;
35 
36 constexpr uint8_t operator ""_8u(
37  unsigned long long int value)
38 {
39  return static_cast<uint8_t>(value);
40 }
41 
42 inline size_t alignment_on_state(
43  const FastBuffer::iterator& origin,
44  const FastBuffer::iterator& offset,
45  size_t data_size)
46 {
47  return (data_size - ((offset - origin) % data_size)) & (data_size - 1);
48 }
49 
50 inline uint32_t Cdr::get_long_lc(
51  SerializedMemberSizeForNextInt serialized_member_size)
52 {
53  uint32_t lc = 0x40000000;
54 
55  switch (serialized_member_size)
56  {
57  case SERIALIZED_MEMBER_SIZE_8:
58  lc = 0x70000000;
59  break;
60  case SERIALIZED_MEMBER_SIZE_4:
61  lc = 0x60000000;
62  break;
63  case SERIALIZED_MEMBER_SIZE:
64  lc = 0x50000000;
65  break;
66  default:
67  break;
68  }
69 
70  return lc;
71 }
72 
73 inline uint32_t Cdr::get_short_lc(
74  size_t member_serialized_size)
75 {
76  uint32_t lc = 0x0;
77  switch (member_serialized_size)
78  {
79  case 2:
80  lc = 0x10000000;
81  break;
82  case 4:
83  lc = 0x20000000;
84  break;
85  case 8:
86  lc = 0x30000000;
87  break;
88  default:
89  break;
90  }
91 
92  return lc;
93 }
94 
96  const Cdr& cdr)
97  : offset_(cdr.offset_)
98  , origin_(cdr.origin_)
99  , swap_bytes_(cdr.swap_bytes_)
100  , last_data_size_(cdr.last_data_size_)
101  , next_member_id_(cdr.next_member_id_)
102  , previous_encoding_(cdr.current_encoding_)
103 {
104 }
105 
107  const state& current_state)
108  : offset_(current_state.offset_)
109  , origin_(current_state.origin_)
110  , swap_bytes_(current_state.swap_bytes_)
111  , last_data_size_(current_state.last_data_size_)
112  , next_member_id_(current_state.next_member_id_)
113  , previous_encoding_(current_state.previous_encoding_)
114 {
115 }
116 
118  const Cdr::state& other_state) const
119 {
120  return
121  other_state.offset_ == offset_ &&
122  other_state.origin_ == origin_ &&
123  other_state.swap_bytes_ == swap_bytes_ &&
124  (0 == other_state.last_data_size_ ||
125  0 == last_data_size_ ||
126  other_state.last_data_size_ == last_data_size_
127  );
128 }
129 
131  FastBuffer& cdr_buffer,
132  const Endianness endianness,
133  const CdrVersion cdr_version)
134  : cdr_buffer_(cdr_buffer)
135  , cdr_version_(cdr_version)
137  , swap_bytes_(endianness == DEFAULT_ENDIAN ? false : true)
138  , offset_(cdr_buffer.begin())
139  , origin_(cdr_buffer.begin())
140  , end_(cdr_buffer.end())
141 {
142  switch (cdr_version_)
143  {
144  case CdrVersion::XCDRv2:
145  break;
146  case CdrVersion::XCDRv1:
147  align64_ = 8;
150  break;
151  default:
152  align64_ = 8;
155  break;
156  }
157  reset_callbacks();
158 }
159 
161 {
162  switch (cdr_version_)
163  {
164  case CdrVersion::XCDRv2:
172  break;
173  case CdrVersion::XCDRv1:
181  break;
182  default:
190  break;
191  }
192 }
193 
195 {
196  uint8_t dummy {0};
197  uint8_t encapsulation {0};
198  state state_before_error(*this);
199 
200  try
201  {
202  // If it is DDS_CDR, the first step is to get the dummy byte.
204  {
205  (*this) >> dummy;
206  if (0 != dummy)
207  {
208  throw BadParamException("Unexpected non-zero initial byte received in Cdr::read_encapsulation");
209  }
210  }
211 
212  // Get the ecampsulation byte.
213  (*this) >> encapsulation;
214 
215 
216  // If it is a different endianness, make changes.
217  const uint8_t endianness = encapsulation & 0x1_8u;
218  if (endianness_ != endianness)
219  {
222  }
223 
224  // Check encapsulationKind correctness
225  const uint8_t encoding_flag = encapsulation & static_cast<uint8_t>(~0x1);
226  switch (encoding_flag)
227  {
232  {
234  align64_ = 4;
235  }
236  else
237  {
238  throw BadParamException(
239  "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv2 should be selected.");
240  }
241  break;
244  {
246  align64_ = 8;
247  }
248  else
249  {
250  throw BadParamException(
251  "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv1 should be selected");
252  }
253  break;
256  {
258  align64_ = 8;
259  }
260  break;
261  default:
262  throw BadParamException("Unexpected encoding algorithm received in Cdr::read_encapsulation for DDS CDR");
263  }
264  reset_callbacks();
265 
266  encoding_flag_ = static_cast<EncodingAlgorithmFlag>(encoding_flag);
268 
270  {
272  }
273  }
274  catch (Exception& ex)
275  {
276  set_state(state_before_error);
277  ex.raise();
278  }
279 
280  reset_alignment();
281  return *this;
282 }
283 
285 {
286  uint8_t dummy = 0;
287  uint8_t encapsulation = 0;
288  state state_before_error(*this);
289 
290  try
291  {
292  // If it is DDS_CDR, the first step is to serialize the dummy byte.
294  {
295  (*this) << dummy;
296  }
297 
298  // Construct encapsulation byte.
299  encapsulation = (encoding_flag_ | endianness_);
300 
301  // Serialize the encapsulation byte.
302  (*this) << encapsulation;
303 
305  }
306  catch (Exception& ex)
307  {
308  set_state(state_before_error);
309  ex.raise();
310  }
311 
312  try
313  {
315  {
317  }
318  }
319  catch (Exception& ex)
320  {
321  set_state(state_before_error);
322  ex.raise();
323  }
324 
325  reset_alignment();
326  return *this;
327 }
328 
330 {
331  return cdr_version_;
332 }
333 
335 {
336  return encoding_flag_;
337 }
338 
340  EncodingAlgorithmFlag encoding_flag)
341 {
342  bool ret_value = false;
343 
345  {
346  if (offset_ == cdr_buffer_.begin())
347  {
348  encoding_flag_ = encoding_flag;
349  ret_value = true;
350  }
351  }
352 
353  return ret_value;
354 }
355 
356 std::array<uint8_t, 2> Cdr::get_dds_cdr_options() const
357 {
358  return options_;
359 }
360 
362  const std::array<uint8_t, 2>& options)
363 {
364  options_ = options;
365 }
366 
368  Endianness endianness)
369 {
370  if (endianness_ != endianness)
371  {
374  }
375 }
376 
378 {
379  return static_cast<Endianness>(endianness_);
380 }
381 
383  size_t num_bytes)
384 {
385  bool ret_value = false;
386 
387  if (((end_ - offset_) >= num_bytes) || resize(num_bytes))
388  {
389  offset_ += num_bytes;
390  last_data_size_ = 0;
391  ret_value = true;
392  }
393 
394  return ret_value;
395 }
396 
398 {
399  return cdr_buffer_.getBuffer();
400 }
401 
403 {
404  return &offset_;
405 }
406 
408 {
409  return offset_ - cdr_buffer_.begin();
410 }
411 
413 {
414  return Cdr::state(*this);
415 }
416 
418  const state& current_state)
419 {
420  offset_ >> current_state.offset_;
421  origin_ >> current_state.origin_;
422  swap_bytes_ = current_state.swap_bytes_;
423  last_data_size_ = current_state.last_data_size_;
424  next_member_id_ = current_state.next_member_id_;
425 }
426 
428 {
431  swap_bytes_ = endianness_ == DEFAULT_ENDIAN ? false : true;
432  last_data_size_ = 0;
437  options_ = {0, 0};
438 }
439 
441  size_t num_bytes)
442 {
443  bool ret_value = false;
444 
445  if (((end_ - origin_) >= num_bytes) || resize(num_bytes))
446  {
447  origin_ += num_bytes;
448  last_data_size_ = 0;
449  ret_value = true;
450  }
451 
452  return ret_value;
453 }
454 
456  size_t min_size_inc)
457 {
458  if (cdr_buffer_.resize(min_size_inc))
459  {
462  end_ = cdr_buffer_.end();
463  return true;
464  }
465 
466  return false;
467 }
468 
470  const char char_t)
471 {
472  if (((end_ - offset_) >= sizeof(char_t)) || resize(sizeof(char_t)))
473  {
474  // Save last datasize.
475  last_data_size_ = sizeof(char_t);
476 
477  offset_++ << char_t;
478  return *this;
479  }
480 
482 }
483 
485  const int16_t short_t)
486 {
487  size_t align = alignment(sizeof(short_t));
488  size_t size_aligned = sizeof(short_t) + align;
489 
490  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
491  {
492  // Save last datasize.
493  last_data_size_ = sizeof(short_t);
494 
495  // Align.
497 
498  if (swap_bytes_)
499  {
500  const char* dst = reinterpret_cast<const char*>(&short_t);
501 
502  offset_++ << dst[1];
503  offset_++ << dst[0];
504  }
505  else
506  {
507  offset_ << short_t;
508  offset_ += sizeof(short_t);
509  }
510 
511  return *this;
512  }
513 
515 }
516 
518  const int32_t long_t)
519 {
520  size_t align = alignment(sizeof(long_t));
521  size_t size_aligned = sizeof(long_t) + align;
522 
523  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
524  {
525  // Save last datasize.
526  last_data_size_ = sizeof(long_t);
527 
528  // Align.
530 
531  if (swap_bytes_)
532  {
533  const char* dst = reinterpret_cast<const char*>(&long_t);
534 
535  offset_++ << dst[3];
536  offset_++ << dst[2];
537  offset_++ << dst[1];
538  offset_++ << dst[0];
539  }
540  else
541  {
542  offset_ << long_t;
543  offset_ += sizeof(long_t);
544  }
545 
546  return *this;
547  }
548 
550 }
551 
553  const int64_t longlong_t)
554 {
555  size_t align = alignment(align64_);
556  size_t size_aligned = sizeof(longlong_t) + align;
557 
558  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
559  {
560  // Save last datasize.
562 
563  // Align.
565 
566  if (swap_bytes_)
567  {
568  const char* dst = reinterpret_cast<const char*>(&longlong_t);
569 
570  offset_++ << dst[7];
571  offset_++ << dst[6];
572  offset_++ << dst[5];
573  offset_++ << dst[4];
574  offset_++ << dst[3];
575  offset_++ << dst[2];
576  offset_++ << dst[1];
577  offset_++ << dst[0];
578  }
579  else
580  {
581  offset_ << longlong_t;
582  offset_ += sizeof(longlong_t);
583  }
584 
585  return *this;
586  }
587 
589 }
590 
592  const float float_t)
593 {
594  size_t align = alignment(sizeof(float_t));
595  size_t size_aligned = sizeof(float_t) + align;
596 
597  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
598  {
599  // Save last datasize.
600  last_data_size_ = sizeof(float_t);
601 
602  // Align.
604 
605  if (swap_bytes_)
606  {
607  const char* dst = reinterpret_cast<const char*>(&float_t);
608 
609  offset_++ << dst[3];
610  offset_++ << dst[2];
611  offset_++ << dst[1];
612  offset_++ << dst[0];
613  }
614  else
615  {
616  offset_ << float_t;
617  offset_ += sizeof(float_t);
618  }
619 
620  return *this;
621  }
622 
624 }
625 
627  const double double_t)
628 {
629  size_t align = alignment(align64_);
630  size_t size_aligned = sizeof(double_t) + align;
631 
632  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
633  {
634  // Save last datasize.
636 
637  // Align.
639 
640  if (swap_bytes_)
641  {
642  const char* dst = reinterpret_cast<const char*>(&double_t);
643 
644  offset_++ << dst[7];
645  offset_++ << dst[6];
646  offset_++ << dst[5];
647  offset_++ << dst[4];
648  offset_++ << dst[3];
649  offset_++ << dst[2];
650  offset_++ << dst[1];
651  offset_++ << dst[0];
652  }
653  else
654  {
655  offset_ << double_t;
656  offset_ += sizeof(double_t);
657  }
658 
659  return *this;
660  }
661 
663 }
664 
666  const long double ldouble_t)
667 {
668  size_t align = alignment(align64_);
669  size_t size_aligned = sizeof(ldouble_t) + align;
670 
671  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
672  {
673  // Save last datasize.
675 
676  // Align.
678 
679  if (swap_bytes_)
680  {
681 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
682  __float128 tmp = ldouble_t;
683  const char* dst = reinterpret_cast<const char*>(&tmp);
684 #else
685  const char* dst = reinterpret_cast<const char*>(&ldouble_t);
686 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
687 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
688  offset_++ << dst[15];
689  offset_++ << dst[14];
690  offset_++ << dst[13];
691  offset_++ << dst[12];
692  offset_++ << dst[11];
693  offset_++ << dst[10];
694  offset_++ << dst[9];
695  offset_++ << dst[8];
696  offset_++ << dst[7];
697  offset_++ << dst[6];
698  offset_++ << dst[5];
699  offset_++ << dst[4];
700  offset_++ << dst[3];
701  offset_++ << dst[2];
702  offset_++ << dst[1];
703  offset_++ << dst[0];
704 #else
705 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
706  // Filled with 0's.
707  offset_++ << static_cast<char>(0);
708  offset_++ << static_cast<char>(0);
709  offset_++ << static_cast<char>(0);
710  offset_++ << static_cast<char>(0);
711  offset_++ << static_cast<char>(0);
712  offset_++ << static_cast<char>(0);
713  offset_++ << static_cast<char>(0);
714  offset_++ << static_cast<char>(0);
715  offset_++ << dst[7];
716  offset_++ << dst[6];
717  offset_++ << dst[5];
718  offset_++ << dst[4];
719  offset_++ << dst[3];
720  offset_++ << dst[2];
721  offset_++ << dst[1];
722  offset_++ << dst[0];
723 #else
724 #error unsupported long double type and no __float128 available
725 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
726 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
727  }
728  else
729  {
730 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
731  __float128 tmp = ldouble_t;
732  offset_ << tmp;
733  offset_ += 16;
734 #else
735 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
736  offset_ << static_cast<long double>(0);
737  offset_ += sizeof(ldouble_t);
738 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
739 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
740  offset_ << ldouble_t;
741  offset_ += sizeof(ldouble_t);
742 #else
743 #error unsupported long double type and no __float128 available
744 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
745 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
746  }
747 
748  return *this;
749  }
750 
752 }
753 
755  const bool bool_t)
756 {
757  if (((end_ - offset_) >= sizeof(uint8_t)) || resize(sizeof(uint8_t)))
758  {
759  // Save last datasize.
760  last_data_size_ = sizeof(uint8_t);
761 
762  if (bool_t)
763  {
764  offset_++ << static_cast<uint8_t>(1);
765  }
766  else
767  {
768  offset_++ << static_cast<uint8_t>(0);
769  }
770 
771  return *this;
772  }
773 
775 }
776 
778  const char* string_t)
779 {
780  uint32_t length = 0;
781 
782  if (string_t != nullptr)
783  {
784  length = size_to_uint32(strlen(string_t)) + 1;
785  }
786 
787  if (length > 0)
788  {
789  Cdr::state state_before_error(*this);
790  serialize(length);
791 
792  if (((end_ - offset_) >= length) || resize(length))
793  {
794  // Save last datasize.
795  last_data_size_ = sizeof(uint8_t);
796 
797  offset_.memcopy(string_t, length);
798  offset_ += length;
799  }
800  else
801  {
802  set_state(state_before_error);
804  }
805  }
806  else
807  {
808  serialize(length);
809  }
810 
811  serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
812 
813  return *this;
814 }
815 
817  const wchar_t* string_t)
818 {
819  uint32_t bytes_length = 0;
820  size_t wstrlen = 0;
821 
822  if (string_t != nullptr)
823  {
824  wstrlen = wcslen(string_t);
825  bytes_length = size_to_uint32(wstrlen * 2);
826  }
827 
828  if (bytes_length > 0)
829  {
830  Cdr::state state_(*this);
831  serialize(size_to_uint32(wstrlen));
832 
833  if (((end_ - offset_) >= bytes_length) || resize(bytes_length))
834  {
835  serialize_array(string_t, wstrlen);
836  }
837  else
838  {
839  set_state(state_);
841  }
842  }
843  else
844  {
845  serialize(bytes_length);
846  }
847 
848  return *this;
849 }
850 
852  const bool* bool_t,
853  size_t num_elements)
854 {
855  size_t total_size = sizeof(*bool_t) * num_elements;
856 
857  if (((end_ - offset_) >= total_size) || resize(total_size))
858  {
859  // Save last datasize.
860  last_data_size_ = sizeof(*bool_t);
861 
862  for (size_t count = 0; count < num_elements; ++count)
863  {
864  uint8_t value = 0;
865 
866  if (bool_t[count])
867  {
868  value = 1;
869  }
870  offset_++ << value;
871  }
872 
873  return *this;
874  }
875 
877 }
878 
880  const char* char_t,
881  size_t num_elements)
882 {
883  size_t total_size = sizeof(*char_t) * num_elements;
884 
885  if (((end_ - offset_) >= total_size) || resize(total_size))
886  {
887  // Save last datasize.
888  last_data_size_ = sizeof(*char_t);
889 
890  offset_.memcopy(char_t, total_size);
891  offset_ += total_size;
892  return *this;
893  }
894 
896 }
897 
899  const int16_t* short_t,
900  size_t num_elements)
901 {
902  if (num_elements == 0)
903  {
904  return *this;
905  }
906 
907  size_t align = alignment(sizeof(*short_t));
908  size_t total_size = sizeof(*short_t) * num_elements;
909  size_t size_aligned = total_size + align;
910 
911  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
912  {
913  // Save last datasize.
914  last_data_size_ = sizeof(*short_t);
915 
916  // Align if there are any elements
917  if (num_elements)
918  {
920  }
921 
922  if (swap_bytes_)
923  {
924  const char* dst = reinterpret_cast<const char*>(short_t);
925  const char* end = dst + total_size;
926 
927  for (; dst < end; dst += sizeof(*short_t))
928  {
929  offset_++ << dst[1];
930  offset_++ << dst[0];
931  }
932  }
933  else
934  {
935  offset_.memcopy(short_t, total_size);
936  offset_ += total_size;
937  }
938 
939  return *this;
940  }
941 
943 }
944 
946  const int32_t* long_t,
947  size_t num_elements)
948 {
949  if (num_elements == 0)
950  {
951  return *this;
952  }
953 
954  size_t align = alignment(sizeof(*long_t));
955  size_t total_size = sizeof(*long_t) * num_elements;
956  size_t size_aligned = total_size + align;
957 
958  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
959  {
960  // Save last datasize.
961  last_data_size_ = sizeof(*long_t);
962 
963  // Align if there are any elements
964  if (num_elements)
965  {
967  }
968 
969  if (swap_bytes_)
970  {
971  const char* dst = reinterpret_cast<const char*>(long_t);
972  const char* end = dst + total_size;
973 
974  for (; dst < end; dst += sizeof(*long_t))
975  {
976  offset_++ << dst[3];
977  offset_++ << dst[2];
978  offset_++ << dst[1];
979  offset_++ << dst[0];
980  }
981  }
982  else
983  {
984  offset_.memcopy(long_t, total_size);
985  offset_ += total_size;
986  }
987 
988  return *this;
989  }
990 
992 }
993 
995  const wchar_t* wchar,
996  size_t num_elements)
997 {
998  if (num_elements == 0)
999  {
1000  return *this;
1001  }
1002 
1003  for (size_t count = 0; count < num_elements; ++count)
1004  {
1005  serialize(wchar[count]);
1006  }
1007  return *this;
1008 }
1009 
1011  const int64_t* longlong_t,
1012  size_t num_elements)
1013 {
1014  if (num_elements == 0)
1015  {
1016  return *this;
1017  }
1018 
1019  size_t align = alignment(align64_);
1020  size_t total_size = sizeof(*longlong_t) * num_elements;
1021  size_t size_aligned = total_size + align;
1022 
1023  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
1024  {
1025  // Save last datasize.
1027 
1028  // Align if there are any elements
1029  if (num_elements)
1030  {
1032  }
1033 
1034  if (swap_bytes_)
1035  {
1036  const char* dst = reinterpret_cast<const char*>(longlong_t);
1037  const char* end = dst + total_size;
1038 
1039  for (; dst < end; dst += sizeof(*longlong_t))
1040  {
1041  offset_++ << dst[7];
1042  offset_++ << dst[6];
1043  offset_++ << dst[5];
1044  offset_++ << dst[4];
1045  offset_++ << dst[3];
1046  offset_++ << dst[2];
1047  offset_++ << dst[1];
1048  offset_++ << dst[0];
1049  }
1050  }
1051  else
1052  {
1053  offset_.memcopy(longlong_t, total_size);
1054  offset_ += total_size;
1055  }
1056 
1057  return *this;
1058  }
1059 
1061 }
1062 
1064  const float* float_t,
1065  size_t num_elements)
1066 {
1067  if (num_elements == 0)
1068  {
1069  return *this;
1070  }
1071 
1072  size_t align = alignment(sizeof(*float_t));
1073  size_t total_size = sizeof(*float_t) * num_elements;
1074  size_t size_aligned = total_size + align;
1075 
1076  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
1077  {
1078  // Save last datasize.
1079  last_data_size_ = sizeof(*float_t);
1080 
1081  // Align if there are any elements
1082  if (num_elements)
1083  {
1085  }
1086 
1087  if (swap_bytes_)
1088  {
1089  const char* dst = reinterpret_cast<const char*>(float_t);
1090  const char* end = dst + total_size;
1091 
1092  for (; dst < end; dst += sizeof(*float_t))
1093  {
1094  offset_++ << dst[3];
1095  offset_++ << dst[2];
1096  offset_++ << dst[1];
1097  offset_++ << dst[0];
1098  }
1099  }
1100  else
1101  {
1102  offset_.memcopy(float_t, total_size);
1103  offset_ += total_size;
1104  }
1105 
1106  return *this;
1107  }
1108 
1110 }
1111 
1113  const double* double_t,
1114  size_t num_elements)
1115 {
1116  if (num_elements == 0)
1117  {
1118  return *this;
1119  }
1120 
1121  size_t align = alignment(align64_);
1122  size_t total_size = sizeof(*double_t) * num_elements;
1123  size_t size_aligned = total_size + align;
1124 
1125  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
1126  {
1127  // Save last datasize.
1129 
1130  // Align if there are any elements
1131  if (num_elements)
1132  {
1134  }
1135 
1136  if (swap_bytes_)
1137  {
1138  const char* dst = reinterpret_cast<const char*>(double_t);
1139  const char* end = dst + total_size;
1140 
1141  for (; dst < end; dst += sizeof(*double_t))
1142  {
1143  offset_++ << dst[7];
1144  offset_++ << dst[6];
1145  offset_++ << dst[5];
1146  offset_++ << dst[4];
1147  offset_++ << dst[3];
1148  offset_++ << dst[2];
1149  offset_++ << dst[1];
1150  offset_++ << dst[0];
1151  }
1152  }
1153  else
1154  {
1155  offset_.memcopy(double_t, total_size);
1156  offset_ += total_size;
1157  }
1158 
1159  return *this;
1160  }
1161 
1163 }
1164 
1166  const long double* ldouble_t,
1167  size_t num_elements)
1168 {
1169  if (num_elements == 0)
1170  {
1171  return *this;
1172  }
1173 
1174  size_t align = alignment(align64_);
1175  // Fix for Windows ( long doubles only store 8 bytes )
1176  size_t total_size = 16 * num_elements; // sizeof(*ldouble_t)
1177  size_t size_aligned = total_size + align;
1178 
1179  if (((end_ - offset_) >= size_aligned) || resize(size_aligned))
1180  {
1181  // Save last datasize.
1183 
1184  // Align if there are any elements
1185  if (num_elements)
1186  {
1188  }
1189 
1190 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1191  if (swap_bytes_)
1192  {
1193  for (size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1194  {
1195  __float128 tmp = *ldouble_t;
1196  const char* dst = reinterpret_cast<const char*>(&tmp);
1197  offset_++ << dst[15];
1198  offset_++ << dst[14];
1199  offset_++ << dst[13];
1200  offset_++ << dst[12];
1201  offset_++ << dst[11];
1202  offset_++ << dst[10];
1203  offset_++ << dst[9];
1204  offset_++ << dst[8];
1205  offset_++ << dst[7];
1206  offset_++ << dst[6];
1207  offset_++ << dst[5];
1208  offset_++ << dst[4];
1209  offset_++ << dst[3];
1210  offset_++ << dst[2];
1211  offset_++ << dst[1];
1212  offset_++ << dst[0];
1213  }
1214  }
1215  else
1216  {
1217  for (size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1218  {
1219  __float128 tmp = *ldouble_t;
1220  offset_ << tmp;
1221  offset_ += 16;
1222  }
1223  }
1224 #else
1225 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1226  if (swap_bytes_)
1227  {
1228  const char* dst = reinterpret_cast<const char*>(ldouble_t);
1229  const char* end = dst + total_size;
1230 
1231  for (; dst < end; dst += sizeof(*ldouble_t))
1232  {
1233 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1234  offset_++ << dst[15];
1235  offset_++ << dst[14];
1236  offset_++ << dst[13];
1237  offset_++ << dst[12];
1238  offset_++ << dst[11];
1239  offset_++ << dst[10];
1240  offset_++ << dst[9];
1241  offset_++ << dst[8];
1242 #else
1243  offset_++ << static_cast<char>(0);
1244  offset_++ << static_cast<char>(0);
1245  offset_++ << static_cast<char>(0);
1246  offset_++ << static_cast<char>(0);
1247  offset_++ << static_cast<char>(0);
1248  offset_++ << static_cast<char>(0);
1249  offset_++ << static_cast<char>(0);
1250  offset_++ << static_cast<char>(0);
1251 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1252  offset_++ << dst[7];
1253  offset_++ << dst[6];
1254  offset_++ << dst[5];
1255  offset_++ << dst[4];
1256  offset_++ << dst[3];
1257  offset_++ << dst[2];
1258  offset_++ << dst[1];
1259  offset_++ << dst[0];
1260  }
1261  }
1262  else
1263  {
1264 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1265  offset_.memcopy(ldouble_t, total_size);
1266  offset_ += total_size;
1267 #else
1268  for (size_t i = 0; i < num_elements; ++i)
1269  {
1270  offset_ << static_cast<long double>(0);
1271  offset_ += 8;
1272  offset_ << ldouble_t[i];
1273  offset_ += 8;
1274  }
1275 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1276  }
1277 #else
1278 #error unsupported long double type and no __float128 available
1279 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1280 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1281 
1282  return *this;
1283  }
1284 
1286 }
1287 
1289  char& char_t)
1290 {
1291  if ((end_ - offset_) >= sizeof(char_t))
1292  {
1293  // Save last datasize.
1294  last_data_size_ = sizeof(char_t);
1295 
1296  offset_++ >> char_t;
1297  return *this;
1298  }
1299 
1301 }
1302 
1304  int16_t& short_t)
1305 {
1306  size_t align = alignment(sizeof(short_t));
1307  size_t size_aligned = sizeof(short_t) + align;
1308 
1309  if ((end_ - offset_) >= size_aligned)
1310  {
1311  // Save last datasize.
1312  last_data_size_ = sizeof(short_t);
1313 
1314  // Align
1316 
1317  if (swap_bytes_)
1318  {
1319  char* dst = reinterpret_cast<char*>(&short_t);
1320 
1321  offset_++ >> dst[1];
1322  offset_++ >> dst[0];
1323  }
1324  else
1325  {
1326  offset_ >> short_t;
1327  offset_ += sizeof(short_t);
1328  }
1329 
1330  return *this;
1331  }
1332 
1334 }
1335 
1337  int32_t& long_t)
1338 {
1339  size_t align = alignment(sizeof(long_t));
1340  size_t size_aligned = sizeof(long_t) + align;
1341 
1342  if ((end_ - offset_) >= size_aligned)
1343  {
1344  // Save last datasize.
1345  last_data_size_ = sizeof(long_t);
1346 
1347  // Align
1349 
1350  if (swap_bytes_)
1351  {
1352  char* dst = reinterpret_cast<char*>(&long_t);
1353 
1354  offset_++ >> dst[3];
1355  offset_++ >> dst[2];
1356  offset_++ >> dst[1];
1357  offset_++ >> dst[0];
1358  }
1359  else
1360  {
1361  offset_ >> long_t;
1362  offset_ += sizeof(long_t);
1363  }
1364 
1365  return *this;
1366  }
1367 
1369 }
1370 
1372  int64_t& longlong_t)
1373 {
1374  size_t align = alignment(align64_);
1375  size_t size_aligned = sizeof(longlong_t) + align;
1376 
1377  if ((end_ - offset_) >= size_aligned)
1378  {
1379  // Save last datasize.
1381 
1382  // Align.
1384 
1385  if (swap_bytes_)
1386  {
1387  char* dst = reinterpret_cast<char*>(&longlong_t);
1388 
1389  offset_++ >> dst[7];
1390  offset_++ >> dst[6];
1391  offset_++ >> dst[5];
1392  offset_++ >> dst[4];
1393  offset_++ >> dst[3];
1394  offset_++ >> dst[2];
1395  offset_++ >> dst[1];
1396  offset_++ >> dst[0];
1397  }
1398  else
1399  {
1400  offset_ >> longlong_t;
1401  offset_ += sizeof(longlong_t);
1402  }
1403 
1404  return *this;
1405  }
1406 
1408 }
1409 
1411  float& float_t)
1412 {
1413  size_t align = alignment(sizeof(float_t));
1414  size_t size_aligned = sizeof(float_t) + align;
1415 
1416  if ((end_ - offset_) >= size_aligned)
1417  {
1418  // Save last datasize.
1419  last_data_size_ = sizeof(float_t);
1420 
1421  // Align.
1423 
1424  if (swap_bytes_)
1425  {
1426  char* dst = reinterpret_cast<char*>(&float_t);
1427 
1428  offset_++ >> dst[3];
1429  offset_++ >> dst[2];
1430  offset_++ >> dst[1];
1431  offset_++ >> dst[0];
1432  }
1433  else
1434  {
1435  offset_ >> float_t;
1436  offset_ += sizeof(float_t);
1437  }
1438 
1439  return *this;
1440  }
1441 
1443 }
1444 
1446  double& double_t)
1447 {
1448  size_t align = alignment(align64_);
1449  size_t size_aligned = sizeof(double_t) + align;
1450 
1451  if ((end_ - offset_) >= size_aligned)
1452  {
1453  // Save last datasize.
1455 
1456  // Align.
1458 
1459  if (swap_bytes_)
1460  {
1461  char* dst = reinterpret_cast<char*>(&double_t);
1462 
1463  offset_++ >> dst[7];
1464  offset_++ >> dst[6];
1465  offset_++ >> dst[5];
1466  offset_++ >> dst[4];
1467  offset_++ >> dst[3];
1468  offset_++ >> dst[2];
1469  offset_++ >> dst[1];
1470  offset_++ >> dst[0];
1471  }
1472  else
1473  {
1474  offset_ >> double_t;
1475  offset_ += sizeof(double_t);
1476  }
1477 
1478  return *this;
1479  }
1480 
1482 }
1483 
1485  long double& ldouble_t)
1486 {
1487  size_t align = alignment(align64_);
1488  size_t size_aligned = sizeof(ldouble_t) + align;
1489 
1490  if ((end_ - offset_) >= size_aligned)
1491  {
1492  // Save last datasize.
1494 
1495  // Align.
1497 
1498  if (swap_bytes_)
1499  {
1500 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1501  __float128 tmp = ldouble_t;
1502  char* dst = reinterpret_cast<char*>(&tmp);
1503 #else
1504  char* dst = reinterpret_cast<char*>(&ldouble_t);
1505 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1506 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1507  offset_++ >> dst[15];
1508  offset_++ >> dst[14];
1509  offset_++ >> dst[13];
1510  offset_++ >> dst[12];
1511  offset_++ >> dst[11];
1512  offset_++ >> dst[10];
1513  offset_++ >> dst[9];
1514  offset_++ >> dst[8];
1515  offset_++ >> dst[7];
1516  offset_++ >> dst[6];
1517  offset_++ >> dst[5];
1518  offset_++ >> dst[4];
1519  offset_++ >> dst[3];
1520  offset_++ >> dst[2];
1521  offset_++ >> dst[1];
1522  offset_++ >> dst[0];
1523 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1524  ldouble_t = static_cast<long double>(tmp);
1525 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1526 #else
1527 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1528  offset_ += 8;
1529  offset_++ >> dst[7];
1530  offset_++ >> dst[6];
1531  offset_++ >> dst[5];
1532  offset_++ >> dst[4];
1533  offset_++ >> dst[3];
1534  offset_++ >> dst[2];
1535  offset_++ >> dst[1];
1536  offset_++ >> dst[0];
1537 #else
1538 #error unsupported long double type and no __float128 available
1539 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1540 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1541  }
1542  else
1543  {
1544 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1545  __float128 tmp;
1546  offset_ >> tmp;
1547  offset_ += 16;
1548  ldouble_t = static_cast<long double>(tmp);
1549 #else
1550 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1551 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1552  offset_ += 8;
1553 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1554  offset_ >> ldouble_t;
1555  offset_ += sizeof(ldouble_t);
1556 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1557 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1558  }
1559 
1560  return *this;
1561  }
1562 
1564 }
1565 
1567  bool& bool_t)
1568 {
1569  uint8_t value = 0;
1570 
1571  if ((end_ - offset_) >= sizeof(uint8_t))
1572  {
1573  // Save last datasize.
1574  last_data_size_ = sizeof(uint8_t);
1575 
1576  offset_++ >> value;
1577 
1578  if (value == 1)
1579  {
1580  bool_t = true;
1581  return *this;
1582  }
1583  else if (value == 0)
1584  {
1585  bool_t = false;
1586  return *this;
1587  }
1588 
1589  throw BadParamException("Unexpected byte value in Cdr::deserialize(bool), expected 0 or 1");
1590  }
1591 
1593 }
1594 
1596  char*& string_t)
1597 {
1598  uint32_t length = 0;
1599  Cdr::state state_before_error(*this);
1600 
1601  deserialize(length);
1602 
1603  if (length == 0)
1604  {
1605  string_t = nullptr;
1606  return *this;
1607  }
1608  else if ((end_ - offset_) >= length)
1609  {
1610  // Save last datasize.
1611  last_data_size_ = sizeof(uint8_t);
1612 
1613  // Allocate memory.
1614  string_t =
1615  reinterpret_cast<char*>(calloc(length + ((&offset_)[length - 1] == '\0' ? 0 : 1),
1616  sizeof(char)));
1617  memcpy(string_t, &offset_, length);
1618  offset_ += length;
1619  return *this;
1620  }
1621 
1622  set_state(state_before_error);
1624 }
1625 
1627  wchar_t*& string_t)
1628 {
1629  uint32_t length = 0;
1630  Cdr::state state_before_error(*this);
1631 
1632  deserialize(length);
1633 
1634  if (length == 0)
1635  {
1636  string_t = nullptr;
1637  return *this;
1638  }
1639  else if ((end_ - offset_) >= (length * 2))
1640  {
1641  // Save last datasize.
1642  last_data_size_ = sizeof(uint16_t);
1643  // Allocate memory.
1644  string_t = reinterpret_cast<wchar_t*>(calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero
1645 
1646  deserialize_array(string_t, length);
1647 
1648  return *this;
1649  }
1650 
1651  set_state(state_before_error);
1653 }
1654 
1655 const char* Cdr::read_string(
1656  uint32_t& length)
1657 {
1658  const char* ret_value = "";
1659  state state_before_error(*this);
1660 
1661  *this >> length;
1662 
1663  if (length == 0)
1664  {
1665  return ret_value;
1666  }
1667  else if ((end_ - offset_) >= length)
1668  {
1669  // Save last datasize.
1670  last_data_size_ = sizeof(uint8_t);
1671 
1672  ret_value = &offset_;
1673  offset_ += length;
1674  if (ret_value[length - 1] == '\0')
1675  {
1676  --length;
1677  }
1678  return ret_value;
1679  }
1680 
1681  set_state(state_before_error);
1684 }
1685 
1686 const std::wstring Cdr::read_wstring(
1687  uint32_t& length)
1688 {
1689  std::wstring ret_value = L"";
1690  state state_(*this);
1691 
1692  *this >> length;
1693  uint32_t bytes_length = length * 2;
1694 
1695  if (bytes_length == 0)
1696  {
1697  return ret_value;
1698  }
1699  else if ((end_ - offset_) >= bytes_length)
1700  {
1701  // Save last datasize.
1702  last_data_size_ = sizeof(uint16_t);
1703 
1704  ret_value.resize(length);
1705  deserialize_array(const_cast<wchar_t*>(ret_value.c_str()), length);
1706  if (ret_value[length - 1] == L'\0')
1707  {
1708  --length;
1709  ret_value.erase(length);
1710  }
1711  return ret_value;
1712  }
1713 
1714  set_state(state_);
1717 }
1718 
1720  bool* bool_t,
1721  size_t num_elements)
1722 {
1723  size_t total_size = sizeof(*bool_t) * num_elements;
1724 
1725  if ((end_ - offset_) >= total_size)
1726  {
1727  // Save last datasize.
1728  last_data_size_ = sizeof(*bool_t);
1729 
1730  for (size_t count = 0; count < num_elements; ++count)
1731  {
1732  uint8_t value = 0;
1733  offset_++ >> value;
1734 
1735  if (value == 1)
1736  {
1737  bool_t[count] = true;
1738  }
1739  else if (value == 0)
1740  {
1741  bool_t[count] = false;
1742  }
1743  }
1744 
1745  return *this;
1746  }
1747 
1749 }
1750 
1752  char* char_t,
1753  size_t num_elements)
1754 {
1755  size_t total_size = sizeof(*char_t) * num_elements;
1756 
1757  if ((end_ - offset_) >= total_size)
1758  {
1759  // Save last datasize.
1760  last_data_size_ = sizeof(*char_t);
1761 
1762  offset_.rmemcopy(char_t, total_size);
1763  offset_ += total_size;
1764  return *this;
1765  }
1766 
1768 }
1769 
1771  int16_t* short_t,
1772  size_t num_elements)
1773 {
1774  if (num_elements == 0)
1775  {
1776  return *this;
1777  }
1778 
1779  size_t align = alignment(sizeof(*short_t));
1780  size_t total_size = sizeof(*short_t) * num_elements;
1781  size_t size_aligned = total_size + align;
1782 
1783  if ((end_ - offset_) >= size_aligned)
1784  {
1785  // Save last datasize.
1786  last_data_size_ = sizeof(*short_t);
1787 
1788  // Align if there are any elements
1789  if (num_elements)
1790  {
1792  }
1793 
1794  if (swap_bytes_)
1795  {
1796  char* dst = reinterpret_cast<char*>(short_t);
1797  char* end = dst + total_size;
1798 
1799  for (; dst < end; dst += sizeof(*short_t))
1800  {
1801  offset_++ >> dst[1];
1802  offset_++ >> dst[0];
1803  }
1804  }
1805  else
1806  {
1807  offset_.rmemcopy(short_t, total_size);
1808  offset_ += total_size;
1809  }
1810 
1811  return *this;
1812  }
1813 
1815 }
1816 
1818  int32_t* long_t,
1819  size_t num_elements)
1820 {
1821  if (num_elements == 0)
1822  {
1823  return *this;
1824  }
1825 
1826  size_t align = alignment(sizeof(*long_t));
1827  size_t total_size = sizeof(*long_t) * num_elements;
1828  size_t size_aligned = total_size + align;
1829 
1830  if ((end_ - offset_) >= size_aligned)
1831  {
1832  // Save last datasize.
1833  last_data_size_ = sizeof(*long_t);
1834 
1835  // Align if there are any elements
1836  if (num_elements)
1837  {
1839  }
1840 
1841  if (swap_bytes_)
1842  {
1843  char* dst = reinterpret_cast<char*>(long_t);
1844  char* end = dst + total_size;
1845 
1846  for (; dst < end; dst += sizeof(*long_t))
1847  {
1848  offset_++ >> dst[3];
1849  offset_++ >> dst[2];
1850  offset_++ >> dst[1];
1851  offset_++ >> dst[0];
1852  }
1853  }
1854  else
1855  {
1856  offset_.rmemcopy(long_t, total_size);
1857  offset_ += total_size;
1858  }
1859 
1860  return *this;
1861  }
1862 
1864 }
1865 
1867  wchar_t* wchar,
1868  size_t num_elements)
1869 {
1870  if (num_elements == 0)
1871  {
1872  return *this;
1873  }
1874 
1875  uint16_t value;
1876  for (size_t count = 0; count < num_elements; ++count)
1877  {
1878  deserialize(value);
1879  wchar[count] = static_cast<wchar_t>(value);
1880  }
1881  return *this;
1882 }
1883 
1885  int64_t* longlong_t,
1886  size_t num_elements)
1887 {
1888  if (num_elements == 0)
1889  {
1890  return *this;
1891  }
1892 
1893  size_t align = alignment(align64_);
1894  size_t total_size = sizeof(*longlong_t) * num_elements;
1895  size_t size_aligned = total_size + align;
1896 
1897  if ((end_ - offset_) >= size_aligned)
1898  {
1899  // Save last datasize.
1901 
1902  // Align if there are any elements
1903  if (num_elements)
1904  {
1906  }
1907 
1908  if (swap_bytes_)
1909  {
1910  char* dst = reinterpret_cast<char*>(longlong_t);
1911  char* end = dst + total_size;
1912 
1913  for (; dst < end; dst += sizeof(*longlong_t))
1914  {
1915  offset_++ >> dst[7];
1916  offset_++ >> dst[6];
1917  offset_++ >> dst[5];
1918  offset_++ >> dst[4];
1919  offset_++ >> dst[3];
1920  offset_++ >> dst[2];
1921  offset_++ >> dst[1];
1922  offset_++ >> dst[0];
1923  }
1924  }
1925  else
1926  {
1927  offset_.rmemcopy(longlong_t, total_size);
1928  offset_ += total_size;
1929  }
1930 
1931  return *this;
1932  }
1933 
1935 }
1936 
1938  float* float_t,
1939  size_t num_elements)
1940 {
1941  if (num_elements == 0)
1942  {
1943  return *this;
1944  }
1945 
1946  size_t align = alignment(sizeof(*float_t));
1947  size_t total_size = sizeof(*float_t) * num_elements;
1948  size_t size_aligned = total_size + align;
1949 
1950  if ((end_ - offset_) >= size_aligned)
1951  {
1952  // Save last datasize.
1953  last_data_size_ = sizeof(*float_t);
1954 
1955  // Align if there are any elements
1956  if (num_elements)
1957  {
1959  }
1960 
1961  if (swap_bytes_)
1962  {
1963  char* dst = reinterpret_cast<char*>(float_t);
1964  char* end = dst + total_size;
1965 
1966  for (; dst < end; dst += sizeof(*float_t))
1967  {
1968  offset_++ >> dst[3];
1969  offset_++ >> dst[2];
1970  offset_++ >> dst[1];
1971  offset_++ >> dst[0];
1972  }
1973  }
1974  else
1975  {
1976  offset_.rmemcopy(float_t, total_size);
1977  offset_ += total_size;
1978  }
1979 
1980  return *this;
1981  }
1982 
1984 }
1985 
1987  double* double_t,
1988  size_t num_elements)
1989 {
1990  if (num_elements == 0)
1991  {
1992  return *this;
1993  }
1994 
1995  size_t align = alignment(align64_);
1996  size_t total_size = sizeof(*double_t) * num_elements;
1997  size_t size_aligned = total_size + align;
1998 
1999  if ((end_ - offset_) >= size_aligned)
2000  {
2001  // Save last datasize.
2003 
2004  // Align if there are any elements
2005  if (num_elements)
2006  {
2008  }
2009 
2010  if (swap_bytes_)
2011  {
2012  char* dst = reinterpret_cast<char*>(double_t);
2013  char* end = dst + total_size;
2014 
2015  for (; dst < end; dst += sizeof(*double_t))
2016  {
2017  offset_++ >> dst[7];
2018  offset_++ >> dst[6];
2019  offset_++ >> dst[5];
2020  offset_++ >> dst[4];
2021  offset_++ >> dst[3];
2022  offset_++ >> dst[2];
2023  offset_++ >> dst[1];
2024  offset_++ >> dst[0];
2025  }
2026  }
2027  else
2028  {
2029  offset_.rmemcopy(double_t, total_size);
2030  offset_ += total_size;
2031  }
2032 
2033  return *this;
2034  }
2035 
2037 }
2038 
2040  long double* ldouble_t,
2041  size_t num_elements)
2042 {
2043  if (num_elements == 0)
2044  {
2045  return *this;
2046  }
2047 
2048  size_t align = alignment(align64_);
2049  // Fix for Windows ( long doubles only store 8 bytes )
2050  size_t total_size = 16 * num_elements;
2051  size_t size_aligned = total_size + align;
2052 
2053  if ((end_ - offset_) >= size_aligned)
2054  {
2055  // Save last datasize.
2057 
2058  // Align if there are any elements
2059  if (num_elements)
2060  {
2062  }
2063 
2064 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2065  if (swap_bytes_)
2066  {
2067  for (size_t i = 0; i < num_elements; ++i)
2068  {
2069  __float128 tmp;
2070  char* dst = reinterpret_cast<char*>(&tmp);
2071  offset_++ >> dst[15];
2072  offset_++ >> dst[14];
2073  offset_++ >> dst[13];
2074  offset_++ >> dst[12];
2075  offset_++ >> dst[11];
2076  offset_++ >> dst[10];
2077  offset_++ >> dst[9];
2078  offset_++ >> dst[8];
2079  offset_++ >> dst[7];
2080  offset_++ >> dst[6];
2081  offset_++ >> dst[5];
2082  offset_++ >> dst[4];
2083  offset_++ >> dst[3];
2084  offset_++ >> dst[2];
2085  offset_++ >> dst[1];
2086  offset_++ >> dst[0];
2087  ldouble_t[i] = static_cast<long double>(tmp);
2088  }
2089  }
2090  else
2091  {
2092  for (size_t i = 0; i < num_elements; ++i)
2093  {
2094  __float128 tmp;
2095  offset_ >> tmp;
2096  offset_ += 16;
2097  ldouble_t[i] = static_cast<long double>(tmp);
2098  }
2099  }
2100 #else
2101 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2102  if (swap_bytes_)
2103  {
2104  char* dst = reinterpret_cast<char*>(ldouble_t);
2105  char* end = dst + num_elements * sizeof(*ldouble_t);
2106 
2107  for (; dst < end; dst += sizeof(*ldouble_t))
2108  {
2109 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2110  offset_++ >> dst[15];
2111  offset_++ >> dst[14];
2112  offset_++ >> dst[13];
2113  offset_++ >> dst[12];
2114  offset_++ >> dst[11];
2115  offset_++ >> dst[10];
2116  offset_++ >> dst[9];
2117  offset_++ >> dst[8];
2118 #else
2119  offset_ += 8;
2120 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2121  offset_++ >> dst[7];
2122  offset_++ >> dst[6];
2123  offset_++ >> dst[5];
2124  offset_++ >> dst[4];
2125  offset_++ >> dst[3];
2126  offset_++ >> dst[2];
2127  offset_++ >> dst[1];
2128  offset_++ >> dst[0];
2129  }
2130  }
2131  else
2132  {
2133 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2134  offset_.rmemcopy(ldouble_t, total_size);
2135  offset_ += total_size;
2136 #else
2137  for (size_t i = 0; i < num_elements; ++i)
2138  {
2139  offset_ += 8; // ignore first 8 bytes
2140  offset_ >> ldouble_t[i];
2141  offset_ += 8;
2142  }
2143 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2144  }
2145 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2146 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2147 
2148  return *this;
2149  }
2150 
2152 }
2153 
2155  const std::vector<bool>& vector_t)
2156 {
2157  state state_before_error(*this);
2158 
2159  size_t total_size = vector_t.size() * sizeof(bool);
2160 
2161  if (((end_ - offset_) >= total_size) || resize(total_size))
2162  {
2163  // Save last datasize.
2164  last_data_size_ = sizeof(bool);
2165 
2166  for (size_t count = 0; count < vector_t.size(); ++count)
2167  {
2168  uint8_t value = 0;
2169  std::vector<bool>::const_reference ref = vector_t[count];
2170 
2171  if (ref)
2172  {
2173  value = 1;
2174  }
2175  offset_++ << value;
2176  }
2177  }
2178  else
2179  {
2180  set_state(state_before_error);
2182  }
2183 
2185  {
2186  serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
2187  }
2188 
2189  return *this;
2190 }
2191 
2193  const std::vector<bool>& vector_t)
2194 {
2195  state state_before_error(*this);
2196 
2197  *this << static_cast<int32_t>(vector_t.size());
2198 
2199  size_t total_size = vector_t.size() * sizeof(bool);
2200 
2201  if (((end_ - offset_) >= total_size) || resize(total_size))
2202  {
2203  // Save last datasize.
2204  last_data_size_ = sizeof(bool);
2205 
2206  for (size_t count = 0; count < vector_t.size(); ++count)
2207  {
2208  uint8_t value = 0;
2209  std::vector<bool>::const_reference ref = vector_t[count];
2210 
2211  if (ref)
2212  {
2213  value = 1;
2214  }
2215  offset_++ << value;
2216  }
2217  }
2218  else
2219  {
2220  set_state(state_before_error);
2222  }
2223 
2225  {
2226  serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
2227  }
2228 
2229  return *this;
2230 }
2231 
2233  std::vector<bool>& vector_t)
2234 {
2235  state state_before_error(*this);
2236 
2237  size_t total_size = vector_t.size() * sizeof(bool);
2238 
2239  if ((end_ - offset_) >= total_size)
2240  {
2241  // Save last datasize.
2242  last_data_size_ = sizeof(bool);
2243 
2244  for (uint32_t count = 0; count < vector_t.size(); ++count)
2245  {
2246  uint8_t value = 0;
2247  offset_++ >> value;
2248 
2249  if (value == 1)
2250  {
2251  vector_t[count] = true;
2252  }
2253  else if (value == 0)
2254  {
2255  vector_t[count] = false;
2256  }
2257  else
2258  {
2259  throw BadParamException("Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2260  }
2261  }
2262  }
2263  else
2264  {
2265  set_state(state_before_error);
2267  }
2268 
2269  return *this;
2270 }
2271 
2273  std::vector<bool>& vector_t)
2274 {
2275  uint32_t sequence_length {0};
2276  state state_before_error(*this);
2277 
2278  *this >> sequence_length;
2279 
2280  size_t total_size = sequence_length * sizeof(bool);
2281 
2282  if ((end_ - offset_) >= total_size)
2283  {
2284  vector_t.resize(sequence_length);
2285  // Save last datasize.
2286  last_data_size_ = sizeof(bool);
2287 
2288  for (uint32_t count = 0; count < sequence_length; ++count)
2289  {
2290  uint8_t value = 0;
2291  offset_++ >> value;
2292 
2293  if (value == 1)
2294  {
2295  vector_t[count] = true;
2296  }
2297  else if (value == 0)
2298  {
2299  vector_t[count] = false;
2300  }
2301  else
2302  {
2303  throw BadParamException("Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2304  }
2305  }
2306  }
2307  else
2308  {
2309  set_state(state_before_error);
2311  }
2312 
2313  return *this;
2314 }
2315 
2317  std::string*& sequence_t,
2318  size_t& num_elements)
2319 {
2320  uint32_t sequence_length {0};
2321 
2323  {
2324  uint32_t dheader {0};
2325  deserialize(dheader);
2326 
2327  auto offset = offset_;
2328 
2329  deserialize(sequence_length);
2330 
2331  try
2332  {
2333  sequence_t = new std::string[sequence_length];
2334 
2335  uint32_t count {0};
2336  while (offset_ - offset < dheader && count < sequence_length)
2337  {
2338  deserialize(sequence_t[count]);
2339  ++count;
2340  }
2341 
2342  if (offset_ - offset != dheader)
2343  {
2344  throw BadParamException("Member size greater than size specified by DHEADER");
2345  }
2346  }
2347  catch (exception::Exception& ex)
2348  {
2349  delete [] sequence_t;
2350  sequence_t = nullptr;
2351  ex.raise();
2352  }
2353  }
2354  else
2355  {
2356  state state_before_error(*this);
2357 
2358  deserialize(sequence_length);
2359 
2360  try
2361  {
2362  sequence_t = new std::string[sequence_length];
2363  deserialize_array(sequence_t, sequence_length);
2364  }
2365  catch (exception::Exception& ex)
2366  {
2367  delete [] sequence_t;
2368  sequence_t = nullptr;
2369  set_state(state_before_error);
2370  ex.raise();
2371  }
2372  }
2373 
2374  num_elements = sequence_length;
2375  return *this;
2376 }
2377 
2379  std::wstring*& sequence_t,
2380  size_t& num_elements)
2381 {
2382  uint32_t sequence_length {0};
2383 
2385  {
2386  uint32_t dheader {0};
2387  deserialize(dheader);
2388 
2389  auto offset = offset_;
2390 
2391  deserialize(sequence_length);
2392 
2393  try
2394  {
2395  sequence_t = new std::wstring[sequence_length];
2396 
2397  uint32_t count {0};
2398  while (offset_ - offset < dheader && count < sequence_length)
2399  {
2400  deserialize(sequence_t[count]);
2401  ++count;
2402  }
2403 
2404  if (offset_ - offset != dheader)
2405  {
2406  throw BadParamException("Member size greater than size specified by DHEADER");
2407  }
2408  }
2409  catch (exception::Exception& ex)
2410  {
2411  delete [] sequence_t;
2412  sequence_t = nullptr;
2413  ex.raise();
2414  }
2415  }
2416  else
2417  {
2418  state state_before_error(*this);
2419 
2420  deserialize(sequence_length);
2421 
2422  try
2423  {
2424  sequence_t = new std::wstring[sequence_length];
2425  deserialize_array(sequence_t, sequence_length);
2426  }
2427  catch (exception::Exception& ex)
2428  {
2429  delete [] sequence_t;
2430  sequence_t = nullptr;
2431  set_state(state_before_error);
2432  ex.raise();
2433  }
2434  }
2435 
2436  num_elements = sequence_length;
2437  return *this;
2438 }
2439 
2444  const MemberId& member_id)
2445 {
2446  assert(0x3F00 >= member_id.id);
2447 
2449 
2450  uint16_t flags_and_member_id = static_cast<uint16_t>(member_id.must_understand ? 0x4000 : 0x0) |
2451  static_cast<uint16_t>(member_id.id);
2452  serialize(flags_and_member_id);
2453  uint16_t size = 0;
2454  serialize(size);
2455  reset_alignment();
2456 }
2457 
2459  const MemberId& member_id,
2460  size_t member_serialized_size)
2461 {
2462  static_cast<void>(member_id);
2463  assert(0x3F00 >= member_id.id);
2464  assert(std::numeric_limits<uint16_t>::max() >= member_serialized_size );
2466  jump(sizeof(uint16_t));
2467  uint16_t size = static_cast<uint16_t>(member_serialized_size);
2468  serialize(size);
2469 }
2470 
2472  const MemberId& member_id)
2473 {
2475 
2476  uint16_t flags_and_extended_pid = static_cast<uint16_t>(member_id.must_understand ? 0x4000 : 0x0) |
2477  static_cast<uint16_t>(PID_EXTENDED);
2478  serialize(flags_and_extended_pid);
2479  uint16_t size = PID_EXTENDED_LENGTH;
2480  serialize(size);
2481  uint32_t id = member_id.id;
2482  serialize(id);
2483  uint32_t msize = 0;
2484  serialize(msize);
2485  reset_alignment();
2486 }
2487 
2489  const MemberId&,
2490  size_t member_serialized_size)
2491 {
2492  jump(sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t));
2493  uint32_t msize = static_cast<uint32_t>(member_serialized_size);
2494  serialize(msize);
2495 }
2496 
2498  const MemberId& member_id,
2499  size_t member_serialized_size)
2500 {
2501  assert(0x3F00 >= member_id.id);
2502  assert(std::numeric_limits<uint16_t>::max() >= member_serialized_size );
2503 
2504  uint16_t flags_and_member_id = static_cast<uint16_t>(member_id.must_understand ? 0x4000 : 0x0) |
2505  static_cast<uint16_t>(member_id.id);
2506  serialize(flags_and_member_id);
2507  uint16_t size = static_cast<uint16_t>(member_serialized_size);
2508  serialize(size);
2509  memmove(&offset_, &offset_ + 8, member_serialized_size);
2510 }
2511 
2513  const MemberId& member_id,
2514  size_t member_serialized_size)
2515 {
2516  if (0 < (end_ - offset_ - member_serialized_size - 11))
2517  {
2518  memmove(&offset_ + 12, &offset_ + 4, member_serialized_size);
2519  }
2520  else
2521  {
2523  }
2524  uint16_t flags_and_extended_pid = static_cast<uint16_t>(member_id.must_understand ? 0x4000 : 0x0) |
2525  static_cast<uint16_t>(PID_EXTENDED);
2526  serialize(flags_and_extended_pid);
2527  uint16_t size = PID_EXTENDED_LENGTH;
2528  serialize(size);
2529  uint32_t id = member_id.id;
2530  serialize(id);
2531  uint32_t msize = static_cast<uint32_t>(member_serialized_size);
2532  serialize(msize);
2533 }
2534 
2536  MemberId& member_id,
2537  Cdr::state& current_state)
2538 {
2539  bool ret_value = true;
2541  uint16_t flags_and_member_id = 0;
2542  deserialize(flags_and_member_id);
2543  member_id.must_understand = (flags_and_member_id & 0x4000);
2544  uint16_t id = (flags_and_member_id & 0x3FFF);
2545 
2546 
2547  if (PID_EXTENDED > id)
2548  {
2549  member_id.id = id;
2550  uint16_t size = 0;
2551  deserialize(size);
2552  current_state.member_size_ = size;
2553  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER;
2554  reset_alignment();
2555  }
2556  else if (PID_EXTENDED == id) // PID_EXTENDED
2557  {
2558  uint16_t size = 0;
2559  deserialize(size);
2560  if (PID_EXTENDED_LENGTH != size)
2561  {
2562  throw BadParamException("PID_EXTENDED comes with a size different than 8");
2563  }
2564  uint32_t mid = 0;
2565  deserialize(mid);
2566  member_id.id = mid;
2567  deserialize(current_state.member_size_);
2568  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2569  reset_alignment();
2570  }
2571  else if (PID_SENTINEL == id) // PID_SENTINEL
2572  {
2573  uint16_t size = 0;
2574  deserialize(size);
2575  if (0 != size)
2576  {
2577  throw BadParamException("PID_SENTINEL comes with a size different than 0");
2578  }
2579  current_state.member_size_ = size;
2580  ret_value = false;
2581  }
2582 
2583  return ret_value;
2584 }
2585 
2587  const MemberId& member_id)
2588 {
2589  assert(0x10000000 > member_id.id);
2590 
2591  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id;
2592  serialize(flags_and_member_id);
2593 }
2594 
2596  const MemberId& member_id,
2597  size_t member_serialized_size)
2598 {
2599  assert(0x10000000 > member_id.id);
2600  assert(8 >= member_serialized_size);
2601 
2602  uint32_t lc = get_short_lc(member_serialized_size);
2603  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id;
2604  serialize(flags_and_member_id);
2605 }
2606 
2608  const MemberId& member_id)
2609 {
2610  assert(0x10000000 > member_id.id);
2611 
2612  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id;
2613  serialize(flags_and_member_id);
2614  uint32_t size = 0;
2615  serialize(size);
2616 }
2617 
2619  const MemberId& member_id,
2620  size_t member_serialized_size)
2621 {
2622  assert(0x10000000 > member_id.id);
2623 
2624  uint32_t lc = 0 == member_serialized_size ? get_long_lc(serialized_member_size_) : 0x40000000;
2625  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id;
2626  serialize(flags_and_member_id);
2627  if (0 < member_serialized_size)
2628  {
2629  uint32_t size = static_cast<uint32_t>(member_serialized_size);
2630  serialize(size);
2631  }
2632 }
2633 
2635  const MemberId& member_id,
2636  size_t member_serialized_size)
2637 {
2638  assert(0x10000000 > member_id.id);
2639  assert(8 >= member_serialized_size);
2640 
2641  uint32_t lc = get_short_lc(member_serialized_size);
2642  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id;
2643  serialize(flags_and_member_id);
2644  memmove(&offset_, &offset_ + 4, member_serialized_size);
2645 }
2646 
2648  const MemberId& member_id,
2649  size_t member_serialized_size)
2650 {
2651  assert(0x10000000 > member_id.id);
2652 
2653  if (0 < (end_ - offset_ - member_serialized_size - 7))
2654  {
2655  memmove(&offset_ + 8, &offset_ + 4, member_serialized_size);
2656  }
2657  else
2658  {
2660  }
2661  uint32_t lc = get_long_lc(serialized_member_size_);
2662  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id;
2663  serialize(flags_and_member_id);
2664  uint32_t size = static_cast<uint32_t>(member_serialized_size);
2665  serialize(size);
2666 }
2667 
2669  const MemberId& member_id,
2670  const FastBuffer::iterator& offset)
2671 {
2672  assert(0x10000000 > member_id.id);
2673 
2674  memmove(&offset_ + 4, &offset_ + 8, offset - offset_ - 8);
2675  uint32_t lc = get_long_lc(serialized_member_size_);
2676  uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id;
2677  serialize(flags_and_member_id);
2678 }
2679 
2681  const MemberId& member_id,
2682  bool is_present,
2683  Cdr::state& current_state,
2684  Cdr::XCdrHeaderSelection header_selection)
2685 {
2686  static_cast<void>(is_present);
2687  assert(is_present);
2688  assert(MEMBER_ID_INVALID != member_id);
2690  assert(current_state == Cdr::state(*this));
2693 
2695  {
2696  if (0x3F00 >= member_id.id)
2697  {
2698  switch (header_selection)
2699  {
2700  case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2701  case XCdrHeaderSelection::SHORT_HEADER:
2703  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER;
2704  break;
2705  case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2706  case XCdrHeaderSelection::LONG_HEADER:
2708  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2709  break;
2710  }
2711  }
2712  else
2713  {
2714  switch (header_selection)
2715  {
2716  case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2717  case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2718  case XCdrHeaderSelection::LONG_HEADER:
2720  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2721  break;
2722  default:
2723  throw BadParamException(
2724  "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2725  }
2726  }
2727  current_state.header_selection_ = header_selection;
2728  }
2729  current_state.next_member_id_ = member_id;
2731 
2732  return *this;
2733 }
2734 
2736  const Cdr::state& current_state)
2737 {
2738  assert(MEMBER_ID_INVALID != current_state.next_member_id_);
2741 
2743  {
2744  auto last_offset = offset_;
2745  auto member_origin = origin_;
2746  set_state(current_state);
2748  const size_t member_serialized_size = last_offset - offset_ -
2749  (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 12);
2750  if (member_serialized_size > std::numeric_limits<uint16_t>::max())
2751  {
2752  switch (current_state.header_serialized_)
2753  {
2754  case XCdrHeaderSelection::SHORT_HEADER:
2756  {
2757  xcdr1_change_to_long_member_header(current_state.next_member_id_, member_serialized_size);
2758  member_origin += 8;
2759  }
2760  else
2761  {
2762  throw BadParamException(
2763  "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
2764  }
2765  break;
2766  case XCdrHeaderSelection::LONG_HEADER:
2767  xcdr1_end_long_member_header(current_state.next_member_id_, member_serialized_size);
2768  break;
2769  default:
2770  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
2771  }
2772  }
2773  else
2774  {
2775  switch (current_state.header_serialized_)
2776  {
2777  case XCdrHeaderSelection::SHORT_HEADER:
2778  xcdr1_end_short_member_header(current_state.next_member_id_, member_serialized_size);
2779  break;
2780  case XCdrHeaderSelection::LONG_HEADER:
2781  if (LONG_HEADER == current_state.header_selection_ ||
2782  0x3F00 < current_state.next_member_id_.id)
2783  {
2784  xcdr1_end_long_member_header(current_state.next_member_id_, member_serialized_size);
2785  }
2786  else if (AUTO_WITH_LONG_HEADER_BY_DEFAULT == current_state.header_selection_)
2787  {
2788  xcdr1_change_to_short_member_header(current_state.next_member_id_, member_serialized_size);
2789  member_origin -= 8;
2790  }
2791  break;
2792  default:
2793  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
2794  }
2795  }
2796  origin_ = member_origin; // Don't POP(origin)
2797  jump(member_serialized_size);
2798  }
2799 
2801 
2802  return *this;
2803 }
2804 
2806  const MemberId& member_id,
2807  bool is_present,
2808  Cdr::state& current_state,
2809  Cdr::XCdrHeaderSelection header_selection)
2810 {
2811  assert(MEMBER_ID_INVALID != member_id);
2813  assert(current_state == Cdr::state(*this));
2816 
2817  if (is_present || EncodingAlgorithmFlag::PL_CDR != current_encoding_)
2818  {
2819  if (0x3F00 >= member_id.id)
2820  {
2821  switch (header_selection)
2822  {
2823  case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2824  case XCdrHeaderSelection::SHORT_HEADER:
2826  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER;
2827  break;
2828  case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2829  case XCdrHeaderSelection::LONG_HEADER:
2831  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2832  break;
2833  }
2834  }
2835  else
2836  {
2837  switch (header_selection)
2838  {
2839  case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2840  case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2841  case XCdrHeaderSelection::LONG_HEADER:
2843  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2844  break;
2845  default:
2846  throw BadParamException(
2847  "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2848  }
2849  }
2850  current_state.header_selection_ = header_selection;
2851  }
2852  current_state.member_size_ = is_present ? 1 : 0;
2853  current_state.next_member_id_ = member_id;
2855 
2856  return *this;
2857 }
2858 
2860  const Cdr::state& current_state)
2861 {
2862  assert(MEMBER_ID_INVALID != current_state.next_member_id_);
2865 
2866  if (0 < current_state.member_size_)
2867  {
2868  auto last_offset = offset_;
2869  auto member_origin = origin_;
2870  set_state(current_state);
2872  const size_t member_serialized_size = last_offset - offset_ -
2873  (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 12);
2874  if (member_serialized_size > std::numeric_limits<uint16_t>::max())
2875  {
2876  switch (current_state.header_serialized_)
2877  {
2878  case XCdrHeaderSelection::SHORT_HEADER:
2880  {
2881  xcdr1_change_to_long_member_header(current_state.next_member_id_, member_serialized_size);
2882  member_origin += 8;
2883  }
2884  else
2885  {
2886  throw BadParamException(
2887  "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
2888  }
2889  break;
2890  case XCdrHeaderSelection::LONG_HEADER:
2891  xcdr1_end_long_member_header(current_state.next_member_id_, member_serialized_size);
2892  break;
2893  default:
2894  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
2895  }
2896  }
2897  else
2898  {
2899  switch (current_state.header_serialized_)
2900  {
2901  case XCdrHeaderSelection::SHORT_HEADER:
2902  xcdr1_end_short_member_header(current_state.next_member_id_, member_serialized_size);
2903  break;
2904  case XCdrHeaderSelection::LONG_HEADER:
2905  if (LONG_HEADER == current_state.header_selection_ ||
2906  0x3F00 < current_state.next_member_id_.id)
2907  {
2908  xcdr1_end_long_member_header(current_state.next_member_id_, member_serialized_size);
2909  }
2910  else if (AUTO_WITH_LONG_HEADER_BY_DEFAULT == current_state.header_selection_)
2911  {
2912  xcdr1_change_to_short_member_header(current_state.next_member_id_, member_serialized_size);
2913  member_origin -= 8;
2914  }
2915  break;
2916  default:
2917  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
2918  }
2919  }
2920  origin_ = member_origin; // Don't POP(origin)
2921  jump(member_serialized_size);
2922  }
2923 
2925 
2926  return *this;
2927 }
2928 
2930  const MemberId& member_id,
2931  bool is_present,
2932  Cdr::state& current_state,
2933  XCdrHeaderSelection header_selection)
2934 {
2935  assert(MEMBER_ID_INVALID != member_id);
2937  assert(current_state == Cdr::state(*this));
2941 
2943  {
2944  if (0x10000000 <= member_id.id)
2945  {
2946  throw BadParamException("Cannot serialize a member identifier equal or greater than 0x10000000");
2947  }
2948 
2949  switch (header_selection)
2950  {
2951  case XCdrHeaderSelection::SHORT_HEADER:
2952  case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2954  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER;
2955  break;
2956  case XCdrHeaderSelection::LONG_HEADER:
2957  case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2959  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
2960  break;
2961  }
2962  current_state.header_selection_ = header_selection;
2963  }
2964 
2965  current_state.member_size_ = is_present ? 1 : 0;
2966  current_state.next_member_id_ = member_id;
2968 
2969  return *this;
2970 }
2971 
2973  const Cdr::state& current_state)
2974 {
2975  assert(MEMBER_ID_INVALID != current_state.next_member_id_);
2979 
2981  {
2982  auto last_offset = offset_;
2983  set_state(current_state);
2984  make_alignment(alignment(sizeof(uint32_t)));
2985  if (NO_SERIALIZED_MEMBER_SIZE == serialized_member_size_)
2986  {
2987  const size_t member_serialized_size = last_offset - offset_ -
2988  (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 8);
2989  if (8 < member_serialized_size)
2990  {
2991  switch (current_state.header_serialized_)
2992  {
2993  case XCdrHeaderSelection::SHORT_HEADER:
2995  {
2996  xcdr2_change_to_long_member_header(current_state.next_member_id_, member_serialized_size);
2997  }
2998  else
2999  {
3000  throw BadParamException("Cannot encode XCDRv2 LongMemberHeader");
3001  }
3002  break;
3003  case XCdrHeaderSelection::LONG_HEADER:
3004  xcdr2_end_long_member_header(current_state.next_member_id_, member_serialized_size);
3005  break;
3006  default:
3007  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
3008  }
3009  }
3010  else
3011  {
3012  switch (current_state.header_serialized_)
3013  {
3014  case XCdrHeaderSelection::SHORT_HEADER:
3015  xcdr2_end_short_member_header(current_state.next_member_id_, member_serialized_size);
3016  break;
3017  case XCdrHeaderSelection::LONG_HEADER:
3019  {
3020  xcdr2_change_to_short_member_header(current_state.next_member_id_, member_serialized_size);
3021  }
3022  else
3023  {
3024  xcdr2_end_long_member_header(current_state.next_member_id_, member_serialized_size);
3025  }
3026  break;
3027  default:
3028  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
3029  }
3030  }
3031 
3032  jump(member_serialized_size);
3033  }
3034  else
3035  {
3036  // Use inner type DHEADER as NEXTINT
3037  switch (current_state.header_serialized_)
3038  {
3039  case XCdrHeaderSelection::SHORT_HEADER:
3041  {
3043  offset_ = last_offset;
3044  }
3045  else
3046  {
3047  throw BadParamException("Cannot encode XCDRv2 LongMemberHeader");
3048  }
3049  break;
3050  case XCdrHeaderSelection::LONG_HEADER:
3051  xcdr2_shrink_to_long_member_header(current_state.next_member_id_, last_offset);
3052  offset_ = last_offset;
3053  offset_ -= sizeof(uint32_t);
3054  break;
3055  default:
3056  assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER
3057  }
3058 
3059  last_data_size_ = 0;
3060  }
3061  }
3062 
3064  serialized_member_size_ = NO_SERIALIZED_MEMBER_SIZE;
3065 
3066  return *this;
3067 }
3068 
3070  MemberId& member_id,
3071  Cdr::state& current_state)
3072 {
3073  uint32_t flags_and_member_id = 0;
3074  deserialize(flags_and_member_id);
3075  member_id.must_understand = (flags_and_member_id & 0x80000000);
3076  uint32_t mid = (flags_and_member_id & 0x0FFFFFFF);
3077  uint32_t lc = (flags_and_member_id & 0x70000000) >> 28;
3078 
3079  member_id.id = mid;
3080 
3081  if (4 > lc)
3082  {
3083  switch (lc)
3084  {
3085  case 0:
3086  current_state.member_size_ = 1;
3087  break;
3088  case 1:
3089  current_state.member_size_ = 2;
3090  break;
3091  case 2:
3092  current_state.member_size_ = 4;
3093  break;
3094  case 3:
3095  current_state.member_size_ = 8;
3096  break;
3097  default:
3098  break;
3099  }
3100  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER;
3101  }
3102  else if (4 == lc)
3103  {
3104  uint32_t size = 0;
3105  deserialize(size);
3106  current_state.member_size_ = size;
3107  current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER;
3108  }
3109  else
3110  {
3111  uint32_t size = 0;
3112  deserialize(size);
3113  current_state.member_size_ = 4 + (size * (5 == lc ? 1 : (6 == lc ? 4 : 8)));
3114  current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER; // Avoid take into account DHEADER after.
3115  offset_ -= sizeof(uint32_t);
3116  }
3117 }
3118 
3120  Cdr::state& current_state,
3121  EncodingAlgorithmFlag type_encoding) noexcept
3122 {
3123  assert(current_state == Cdr::state(*this));
3124  assert(EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_ ||
3125  EncodingAlgorithmFlag::PL_CDR == current_encoding_);
3126  assert(EncodingAlgorithmFlag::PLAIN_CDR == type_encoding ||
3127  EncodingAlgorithmFlag::PL_CDR == type_encoding);
3128  current_state.previous_encoding_ = current_encoding_;
3129  current_encoding_ = type_encoding;
3130  return *this;
3131 }
3132 
3134  const Cdr::state& current_state)
3135 {
3138 
3140  {
3144  }
3145 
3146  current_encoding_ = current_state.previous_encoding_;
3147 
3148  return *this;
3149 }
3150 
3152  Cdr::state& current_state,
3153  EncodingAlgorithmFlag type_encoding)
3154 {
3155  assert(current_state == Cdr::state(*this));
3159  assert(EncodingAlgorithmFlag::PLAIN_CDR2 == type_encoding ||
3160  EncodingAlgorithmFlag::DELIMIT_CDR2 == type_encoding ||
3161  EncodingAlgorithmFlag::PL_CDR2 == type_encoding);
3162  if (EncodingAlgorithmFlag::PLAIN_CDR2 != type_encoding)
3163  {
3164  uint32_t dheader {0};
3165  serialize(dheader);
3166  }
3167  serialized_member_size_ = NO_SERIALIZED_MEMBER_SIZE; // Avoid error when serializing arrays, sequences, etc..
3168  current_state.previous_encoding_ = current_encoding_;
3169  current_encoding_ = type_encoding;
3170  return *this;
3171 }
3172 
3174  const Cdr::state& current_state)
3175 {
3180  {
3181  auto last_offset = offset_;
3182  set_state(current_state);
3183  const size_t member_serialized_size = last_offset - offset_ /*DHEADER ->*/ - 4 - alignment(4);
3184  serialize(static_cast<uint32_t>(member_serialized_size));
3185  jump(member_serialized_size);
3186  serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
3187  }
3188  current_encoding_ = current_state.previous_encoding_;
3189  return *this;
3190 }
3191 
3193  EncodingAlgorithmFlag type_encoding,
3194  std::function<bool (Cdr&, const MemberId&)> functor)
3195 {
3196  assert(EncodingAlgorithmFlag::PLAIN_CDR == type_encoding ||
3197  EncodingAlgorithmFlag::PL_CDR == type_encoding);
3198  Cdr::state current_state(*this);
3199 
3200  if (EncodingAlgorithmFlag::PL_CDR == type_encoding)
3201  {
3202  while (xcdr1_deserialize_member_header(next_member_id_, current_state))
3203  {
3204  auto prev_offset = offset_;
3205  bool deser_value = functor(*this, next_member_id_);
3206 
3207  if (!deser_value)
3208  {
3210  {
3211  throw BadParamException("Cannot deserialize a member with flag must_understand");
3212  }
3213  else
3214  {
3215  jump(current_state.member_size_);
3216  }
3217  }
3218 
3219  if (current_state.member_size_ != offset_ - prev_offset)
3220  {
3221  throw BadParamException(
3222  "Member size provided by member header is not equal to the real decoded member size");
3223  }
3224  }
3225  }
3226  else
3227  {
3229 
3230  while (offset_ != end_ && functor(*this, next_member_id_))
3231  {
3232  ++next_member_id_.id;
3233  }
3234  }
3235 
3236  next_member_id_ = current_state.next_member_id_;
3237 
3238  return *this;
3239 }
3240 
3242  EncodingAlgorithmFlag type_encoding,
3243  std::function<bool (Cdr&, const MemberId&)> functor)
3244 {
3245  assert(EncodingAlgorithmFlag::PLAIN_CDR2 == type_encoding ||
3246  EncodingAlgorithmFlag::DELIMIT_CDR2 == type_encoding ||
3247  EncodingAlgorithmFlag::PL_CDR2 == type_encoding);
3248 
3249 
3250  if (EncodingAlgorithmFlag::PLAIN_CDR2 != type_encoding)
3251  {
3252  uint32_t dheader {0};
3253  deserialize(dheader);
3254 
3255  Cdr::state current_state(*this);
3256 
3257  if (EncodingAlgorithmFlag::PL_CDR2 == type_encoding)
3258  {
3259  while (offset_ - current_state.offset_ != dheader)
3260  {
3261  if (offset_ - current_state.offset_ > dheader)
3262  {
3263  throw BadParamException("Member size greater than size specified by DHEADER");
3264  }
3265 
3266  auto offset = offset_;
3267 
3269  bool deser_value = functor(*this, next_member_id_);
3270  if (!deser_value)
3271  {
3273  {
3274  throw BadParamException("Cannot deserialize a member with flag must_understand");
3275  }
3276  else
3277  {
3278  jump(current_state.member_size_);
3279  }
3280  }
3281 
3282  if (!(0 == current_state.member_size_ &&
3283  0 == offset_ - offset) &&
3284  !(0 < current_state.member_size_ &&
3285  current_state.member_size_ == offset_ - offset -
3286  alignment_on_state(current_state.origin_, offset, sizeof(uint32_t)) -
3287  (XCdrHeaderSelection::SHORT_HEADER == current_state.header_serialized_ ? 4 : 8)))
3288  {
3289  throw BadParamException(
3290  "Member size provided by member header is not equal to the real decoded size");
3291  }
3292  }
3293 
3294  next_member_id_ = current_state.next_member_id_;
3295  }
3296  else
3297  {
3299 
3300  while (offset_ - current_state.offset_ < dheader && functor(*this, next_member_id_))
3301  {
3302  ++next_member_id_.id;
3303  }
3304  size_t jump_size = dheader - (offset_ - current_state.offset_);
3305  jump(jump_size);
3306 
3307  next_member_id_ = current_state.next_member_id_;
3308  }
3309  }
3310  else
3311  {
3312  Cdr::state current_state(*this);
3314 
3315  while (offset_ != end_ && functor(*this, next_member_id_))
3316  {
3317  ++next_member_id_.id;
3318  }
3319 
3320  next_member_id_ = current_state.next_member_id_;
3321  }
3322 
3323  return *this;
3324 }
3325 
3327  const MemberId&,
3328  bool,
3329  Cdr::state&,
3331 {
3333  return *this;
3334 }
3335 
3337  const Cdr::state&)
3338 {
3340  return *this;
3341 }
3342 
3344  Cdr::state& current_state,
3345  EncodingAlgorithmFlag type_encoding)
3346 {
3347  static_cast<void>(type_encoding);
3348  assert(EncodingAlgorithmFlag::PLAIN_CDR == type_encoding);
3349  current_state.previous_encoding_ = current_encoding_;
3350  current_encoding_ = type_encoding;
3351  return *this;
3352 }
3353 
3355  const Cdr::state& current_state)
3356 {
3357  current_encoding_ = current_state.previous_encoding_;
3358  return *this;
3359 }
3360 
3362  EncodingAlgorithmFlag type_encoding,
3363  std::function<bool (Cdr&, const MemberId&)> functor)
3364 {
3365  static_cast<void>(type_encoding);
3366  assert(EncodingAlgorithmFlag::PLAIN_CDR == type_encoding);
3367 
3368  Cdr::state current_state(*this);
3370 
3371  while (offset_ != end_ && functor(*this, next_member_id_))
3372  {
3373  ++next_member_id_.id;
3374  }
3375 
3376  next_member_id_ = current_state.next_member_id_;
3377  return *this;
3378 }
3379 
3381 {
3382  Cdr::state dheader_state(*this);
3383 
3385  {
3386  // Serialize DHEADER
3387  uint32_t dheader {0};
3388  serialize(dheader);
3389  }
3390 
3391  return dheader_state;
3392 }
3393 
3395  const Cdr::state& dheader_state)
3396 {
3398  {
3399  auto offset = offset_;
3400  Cdr::state state_after(*this);
3401  set_state(dheader_state);
3402  size_t dheader = offset - offset_ - (4 + alignment(sizeof(uint32_t))); /* DHEADER */
3403  serialize(static_cast<uint32_t>(dheader));
3404  set_state(state_after);
3405  serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
3406  }
3407 }
3408 
3409 } // namespace fastcdr
3410 } // namespace eprosima
eprosima::fastcdr::Cdr::state::previous_encoding_
EncodingAlgorithmFlag previous_encoding_
Not related with the state. Used by encoding algorithms to store the previous encoding algorithm.
Definition: Cdr.h:153
eprosima::fastcdr::Cdr::xcdr1_end_serialize_member
Cdr & xcdr1_end_serialize_member(const Cdr::state &current_state)
Tells to the encoder to finish the encoding of the member.
Definition: Cdr.cpp:2735
eprosima::fastcdr::Cdr::set_dds_cdr_options
Cdr_DllAPI void set_dds_cdr_options(const std::array< uint8_t, 2 > &options)
This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:361
eprosima::fastcdr::Cdr::change_endianness
Cdr_DllAPI void change_endianness(Endianness endianness)
This function sets the current endianness used by the CDR type.
Definition: Cdr.cpp:367
eprosima::fastcdr::Cdr::state::next_member_id_
MemberId next_member_id_
Not related with the state. Next member id which will be encoded.
Definition: Cdr.h:141
eprosima::fastcdr::Cdr::endianness_
uint8_t endianness_
The endianness that will be applied over the buffer.
Definition: Cdr.h:3512
eprosima::fastcdr::exception::BadParamException
This class is thrown as an exception when an invalid parameter is being serialized.
Definition: BadParamException.h:27
eprosima::fastcdr::_FastBuffer_iterator::memcopy
void memcopy(const void *src, const size_t size)
This function copies a buffer into the raw buffer.
Definition: FastBuffer.h:126
eprosima::fastcdr::Cdr::deserialize_string_sequence
Cdr_DllAPI Cdr & deserialize_string_sequence(std::string *&sequence_t, size_t &num_elements)
Definition: Cdr.cpp:2316
eprosima::fastcdr::PID_SENTINEL_LENGTH
constexpr uint16_t PID_SENTINEL_LENGTH
Definition: Cdr.cpp:34
eprosima::fastcdr::Cdr::origin_
FastBuffer::iterator origin_
The position from where the alignment is calculated.
Definition: Cdr.h:3524
detail::state
state
Definition: core.h:2305
align
Definition: core.h:2016
eprosima::fastcdr::Cdr::xcdr2_change_to_short_member_header
void xcdr2_change_to_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv2.
Definition: Cdr.cpp:2634
eprosima::fastcdr::Cdr::set_encoding_flag
Cdr_DllAPI bool set_encoding_flag(EncodingAlgorithmFlag encoding_flag)
Sets the EncodingAlgorithmFlag for the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
Definition: Cdr.cpp:339
eprosima::fastcdr::Cdr::begin_serialize_opt_member_
begin_serialize_opt_member_functor begin_serialize_opt_member_
Definition: Cdr.h:3476
eprosima::fastcdr::Cdr::state::state
Cdr_DllAPI state(const Cdr &cdr)
Default constructor.
Definition: Cdr.cpp:95
eprosima::fastcdr::Cdr::get_long_lc
uint32_t get_long_lc(SerializedMemberSizeForNextInt serialized_member_size)
Definition: Cdr.cpp:50
eprosima::fastcdr::Cdr::xcdr2_end_long_member_header
void xcdr2_end_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a long member header of a member according to XCDRv2.
Definition: Cdr.cpp:2618
eprosima::fastcdr::Cdr::state::operator==
Cdr_DllAPI bool operator==(const state &other_state) const
Compares two states.
Definition: Cdr.cpp:117
eprosima::fastcdr::Cdr::end_serialize_type_
end_serialize_type_functor end_serialize_type_
Definition: Cdr.h:3489
eprosima::fastcdr::Cdr::get_dds_cdr_options
Cdr_DllAPI std::array< uint8_t, 2 > get_dds_cdr_options() const
This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
Definition: Cdr.cpp:356
eprosima::fastcdr::Cdr::xcdr1_end_serialize_opt_member
Cdr & xcdr1_end_serialize_opt_member(const Cdr::state &current_state)
Tells to the encoder to finish the encoding of the member.
Definition: Cdr.cpp:2859
eprosima::fastcdr::MemberId::must_understand
bool must_understand
Definition: MemberId.hpp:59
eprosima::fastcdr::Cdr::xcdr1_begin_serialize_opt_member
Cdr & xcdr1_begin_serialize_opt_member(const MemberId &member_id, bool is_present, Cdr::state &current_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv1.
Definition: Cdr.cpp:2805
eprosima::fastcdr::_FastBuffer_iterator::rmemcopy
void rmemcopy(void *dst, const size_t size)
This function copies from the raw buffer to a external buffer.
Definition: FastBuffer.h:142
eprosima::fastcdr::PID_EXTENDED
constexpr uint16_t PID_EXTENDED
Definition: Cdr.cpp:31
eprosima::fastcdr::Cdr::state::header_selection_
XCdrHeaderSelection header_selection_
Not related with the state. Used by encoding algorithms to store the selected member header version.
Definition: Cdr.h:147
eprosima::fastcdr::Cdr::AUTO_WITH_LONG_HEADER_BY_DEFAULT
@ AUTO_WITH_LONG_HEADER_BY_DEFAULT
Initially a long member header is allocated but can be changed to the shorter version.
Definition: Cdr.h:98
eprosima::fastcdr::Cdr::xcdr2_serialize_short_member_header
void xcdr2_serialize_short_member_header(const MemberId &member_id)
Encodes a short member header of a member according to XCDRv2.
Definition: Cdr.cpp:2586
eprosima::fastcdr::Cdr::cdr_end_serialize_member
Cdr & cdr_end_serialize_member(const Cdr::state &current_state)
Definition: Cdr.cpp:3336
eprosima::fastcdr::MemberId::id
uint32_t id
Definition: MemberId.hpp:57
eprosima::fastcdr::Cdr::deserialize_array
Cdr & deserialize_array(_T *value, size_t num_elements)
Decodes an array of a type not managed by this encoder from the buffer.
Definition: Cdr.h:2143
eprosima::fastcdr::Cdr::Endianness
Endianness
This enumeration represents endianness types.
Definition: Cdr.h:74
eprosima::fastcdr::Cdr::reset_alignment
void reset_alignment()
This function resets the alignment to the current position in the buffer.
Definition: Cdr.h:305
eprosima::fastcdr::Cdr::xcdr2_begin_serialize_type
Cdr & xcdr2_begin_serialize_type(Cdr::state &current_state, EncodingAlgorithmFlag type_encoding)
Tells to the encoder a new type and its members start to be encoded according to XCDRv2.
Definition: Cdr.cpp:3151
eprosima::fastcdr::Cdr::xcdr1_deserialize_type
Cdr & xcdr1_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members start to be decoded according to XCDRv1.
Definition: Cdr.cpp:3192
eprosima::fastcdr::Cdr::jump
Cdr_DllAPI bool jump(size_t num_bytes)
This function skips a number of bytes in the CDR stream buffer.
Definition: Cdr.cpp:382
eprosima::fastcdr::FastBuffer::begin
iterator begin()
This function returns a iterator that points to the begining of the stream.
Definition: FastBuffer.h:317
eprosima::fastcdr::PL_CDR
@ PL_CDR
Specifies that the content is PL_CDR,.
Definition: CdrEncoding.hpp:42
eprosima::fastcdr::Cdr::xcdr1_deserialize_member_header
Cdr_DllAPI bool xcdr1_deserialize_member_header(MemberId &member_id, Cdr::state &current_state)
Decodes a member header according to XCDRv1.
Definition: Cdr.cpp:2535
eprosima::fastcdr::Cdr::get_serialized_data_length
Cdr_DllAPI size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Definition: Cdr.cpp:407
eprosima::fastcdr::Cdr::cdr_begin_serialize_type
Cdr & cdr_begin_serialize_type(Cdr::state &current_state, EncodingAlgorithmFlag type_encoding)
Definition: Cdr.cpp:3343
eprosima::fastcdr::CdrVersion
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
Definition: CdrEncoding.hpp:24
eprosima::fastcdr::alignment_on_state
size_t alignment_on_state(const FastBuffer::iterator &origin, const FastBuffer::iterator &offset, size_t data_size)
Definition: Cdr.cpp:42
eprosima::fastcdr::Cdr::encoding_flag_
EncodingAlgorithmFlag encoding_flag_
Stores the main encoding algorithm.
Definition: Cdr.h:3503
eprosima::fastcdr::Cdr::move_alignment_forward
Cdr_DllAPI bool move_alignment_forward(size_t num_bytes)
This function moves the alignment forward.
Definition: Cdr.cpp:440
eprosima::fastcdr::CORBA_CDR
@ CORBA_CDR
Common CORBA CDR serialization.
Definition: CdrEncoding.hpp:27
eprosima::fastcdr::Cdr
This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an...
Definition: Cdr.h:67
eprosima::fastcdr::Cdr::xcdr2_end_serialize_member
Cdr & xcdr2_end_serialize_member(const Cdr::state &current_state)
Tells to the encoder to finish the encoding of the member.
Definition: Cdr.cpp:2972
eprosima::fastcdr::Cdr::begin_serialize_type_
begin_serialize_type_functor begin_serialize_type_
Definition: Cdr.h:3485
eprosima::fastcdr::Cdr::next_member_id_
MemberId next_member_id_
Next member identifier to be processed.
Definition: Cdr.h:3530
eprosima::fastcdr::Cdr::serialize_array
Cdr & serialize_array(const _T *value, size_t num_elements)
Encodes an array of a type not managed by this encoder into the buffer.
Definition: Cdr.h:957
eprosima::fastcdr::FastBuffer::resize
bool resize(size_t min_size_inc)
This function resizes the raw buffer. It will call the user's defined function for this purpose.
Definition: FastBuffer.cpp:59
eprosima::fastcdr::Cdr::Cdr
Cdr_DllAPI Cdr(FastBuffer &cdr_buffer, const Endianness endianness=DEFAULT_ENDIAN, const CdrVersion cdr_version=XCDRv2)
This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize the assigned...
Definition: Cdr.cpp:130
dummy
int dummy
Definition: lstrlib.c:1350
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
eprosima::fastcdr::PLAIN_CDR
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
Definition: CdrEncoding.hpp:40
eprosima::fastcdr::Cdr::xcdr2_begin_serialize_member
Cdr & xcdr2_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state &current_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv2.
Definition: Cdr.cpp:2929
eprosima::fastcdr::Cdr::xcdr2_deserialize_type
Cdr & xcdr2_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members start to be decoded according to XCDRv2.
Definition: Cdr.cpp:3241
eprosima::fastcdr::Cdr::xcdr2_end_short_member_header
void xcdr2_end_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a short member header of a member according to XCDRv2.
Definition: Cdr.cpp:2595
eprosima::fastcdr::Cdr::deserialize_bool_sequence
Cdr_DllAPI Cdr & deserialize_bool_sequence(std::vector< bool > &vector_t)
Definition: Cdr.cpp:2272
eprosima::fastcdr::Cdr::begin_serialize_member_
begin_serialize_member_functor begin_serialize_member_
Definition: Cdr.h:3465
eprosima::fastcdr::PLAIN_CDR2
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
Definition: CdrEncoding.hpp:44
eprosima::fastcdr::XCDRv2
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Definition: CdrEncoding.hpp:33
eprosima::fastcdr::Cdr::serialize_encapsulation
Cdr_DllAPI Cdr & serialize_encapsulation()
This function writes the encapsulation of the CDR stream. If the CDR stream should contain an encapsu...
Definition: Cdr.cpp:284
eprosima::fastcdr::Cdr::state::origin_
const FastBuffer::iterator origin_
The position from the alignment is calculated, when the state was created.
Definition: Cdr.h:132
eprosima::fastcdr::Cdr::xcdr1_begin_serialize_member
Cdr & xcdr1_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state &current_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv1.
Definition: Cdr.cpp:2680
eprosima::fastcdr::Cdr::xcdr2_deserialize_member_header
void xcdr2_deserialize_member_header(MemberId &member_id, Cdr::state &current_state)
Decodes a member header according to XCDRv2.
Definition: Cdr.cpp:3069
eprosima::fastcdr::Cdr::endianness
Cdr_DllAPI Endianness endianness() const
This function returns the current endianness used by the CDR type.
Definition: Cdr.cpp:377
eprosima::fastcdr::MemberId
Definition: MemberId.hpp:27
eprosima::fastcdr::Cdr::read_wstring
const Cdr_DllAPI std::wstring read_wstring(uint32_t &length)
Definition: Cdr.cpp:1686
size_to_uint32
uint32_t size_to_uint32(size_t val)
Definition: FastBuffer.h:25
eprosima::fastcdr::Cdr::xcdr2_shrink_to_long_member_header
void xcdr2_shrink_to_long_member_header(const MemberId &member_id, const FastBuffer::iterator &offset)
Join the previous encoded long header with the next DHEADER which was serialized after.
Definition: Cdr.cpp:2668
eprosima::fastcdr::Cdr::allocate_xcdrv2_dheader
Cdr_DllAPI state allocate_xcdrv2_dheader()
Encodes an empty DHEADER if the encoding version is XCDRv2. After serializing the members's type,...
Definition: Cdr.cpp:3380
eprosima::fastcdr::Cdr::deserialize_bool_array
Cdr_DllAPI Cdr & deserialize_bool_array(std::vector< bool > &vector_t)
Definition: Cdr.cpp:2232
eprosima::fastcdr::Cdr::get_current_position
Cdr_DllAPI char * get_current_position()
This function returns the current position in the CDR stream.
Definition: Cdr.cpp:402
eprosima::fastcdr::Cdr::deserialize_wstring_sequence
Cdr_DllAPI Cdr & deserialize_wstring_sequence(std::wstring *&sequence_t, size_t &num_elements)
Definition: Cdr.cpp:2378
eprosima::fastcdr::Cdr::align64_
size_t align64_
Align for types equal or greater than 64bits.
Definition: Cdr.h:3533
eprosima::fastcdr::Cdr::get_buffer_pointer
Cdr_DllAPI char * get_buffer_pointer()
This function returns the pointer to the current used buffer.
Definition: Cdr.cpp:397
eprosima::fastcdr::Cdr::LONG_HEADER
@ LONG_HEADER
Initially a long member header is allocated and cannot be changed.
Definition: Cdr.h:94
eprosima::fastcdr::Cdr::state::last_data_size_
size_t last_data_size_
Stores the last datasize serialized/deserialized when the state was created.
Definition: Cdr.h:138
eprosima::fastcdr::MEMBER_ID_INVALID
static const MemberId MEMBER_ID_INVALID
Definition: MemberId.hpp:67
eprosima::fastcdr::DELIMIT_CDR2
@ DELIMIT_CDR2
Specifies that the content is DELIMIT_CDR2.
Definition: CdrEncoding.hpp:46
eprosima::fastcdr::Cdr::last_data_size_
size_t last_data_size_
Stores the last datasize serialized/deserialized. It's used to optimize.
Definition: Cdr.h:3518
eprosima::fastcdr::Cdr::reset
Cdr_DllAPI void reset()
This function resets the current position in the buffer to the beginning.
Definition: Cdr.cpp:427
eprosima::fastcdr::Cdr::xcdr2_end_serialize_type
Cdr & xcdr2_end_serialize_type(const Cdr::state &current_state)
Tells to the encoder to finish the encoding of the type.
Definition: Cdr.cpp:3173
eprosima::fastcdr::Cdr::NO_SERIALIZED_MEMBER_SIZE
enum eprosima::fastcdr::Cdr::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to optimize XCDRv2 member headers.
eprosima::fastcdr::Cdr::xcdr1_serialize_short_member_header
void xcdr1_serialize_short_member_header(const MemberId &member_id)
XCDR extensions.
Definition: Cdr.cpp:2443
eprosima::fastcdr::exception::Exception
This abstract class is used to create exceptions.
Definition: Exception.h:29
eprosima::fastcdr::Cdr::cdr_version_
CdrVersion cdr_version_
The type of CDR that will be use in serialization/deserialization.
Definition: Cdr.h:3500
eprosima::fastcdr::PID_EXTENDED_LENGTH
constexpr uint16_t PID_EXTENDED_LENGTH
Definition: Cdr.cpp:32
eprosima::fastcdr::Cdr::cdr_begin_serialize_member
Cdr & cdr_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state &current_state, XCdrHeaderSelection header_selection)
Definition: Cdr.cpp:3326
eprosima::fastcdr::Cdr::get_state
Cdr_DllAPI state get_state() const
Returns the current state of the CDR serialization process.
Definition: Cdr.cpp:412
eprosima::fastcdr::Cdr::end_serialize_member_
end_serialize_member_functor end_serialize_member_
Definition: Cdr.h:3469
assert
#define assert(condition)
Definition: lz4.c:271
eprosima::fastcdr::Cdr::deserialize_type_
deserialize_type_functor deserialize_type_
Definition: Cdr.h:3494
eprosima::fastcdr::Cdr::read_encapsulation
Cdr_DllAPI Cdr & read_encapsulation()
This function reads the encapsulation of the CDR stream. If the CDR stream contains an encapsulation,...
Definition: Cdr.cpp:194
eprosima::fastcdr::Cdr::reset_callbacks
void reset_callbacks()
Resets the internal callbacks depending on the current selected Cdr version.
Definition: Cdr.cpp:160
eprosima::fastcdr::Cdr::swap_bytes_
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes.
Definition: Cdr.h:3515
eprosima::fastcdr::Cdr::state::header_serialized_
XCdrHeaderSelection header_serialized_
Not related with the state. Used by encoding algorithms to store the allocated member header version.
Definition: Cdr.h:150
Cdr.h
eprosima::fastcdr::Cdr::current_encoding_
EncodingAlgorithmFlag current_encoding_
Stores the current encoding algorithm.
Definition: Cdr.h:3506
eprosima::fastcdr::Cdr::get_encoding_flag
Cdr_DllAPI EncodingAlgorithmFlag get_encoding_flag() const
Returns the EncodingAlgorithmFlag set in the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
Definition: Cdr.cpp:334
eprosima::fastcdr::Cdr::DEFAULT_ENDIAN
static const Cdr_DllAPI Endianness DEFAULT_ENDIAN
Default endianess in the system.
Definition: Cdr.h:83
eprosima::fastcdr::Cdr::AUTO_WITH_SHORT_HEADER_BY_DEFAULT
@ AUTO_WITH_SHORT_HEADER_BY_DEFAULT
Initially a short member header is allocated but can be changed to the longer version.
Definition: Cdr.h:96
eprosima::fastcdr::FastBuffer::getBuffer
char * getBuffer() const
This function returns the stream that the eprosima::fastcdr::FastBuffers uses to serialize data.
Definition: FastBuffer.h:298
eprosima::fastcdr::XCDRv1
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
Definition: CdrEncoding.hpp:31
eprosima::fastcdr::Cdr::end_
FastBuffer::iterator end_
The last position in the buffer;.
Definition: Cdr.h:3527
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::Cdr::cdr_end_serialize_type
Cdr & cdr_end_serialize_type(const Cdr::state &current_state)
Definition: Cdr.cpp:3354
eprosima::fastcdr::Cdr::resize
bool resize(size_t min_size_inc)
This function resizes the internal buffer. It only applies if the FastBuffer object was created with ...
Definition: Cdr.cpp:455
eprosima::fastcdr::Cdr::SERIALIZED_MEMBER_SIZE
@ SERIALIZED_MEMBER_SIZE
Default. No serialized member size in a DHEADER.
Definition: Cdr.h:3542
eprosima::fastcdr::Cdr::set_state
Cdr_DllAPI void set_state(const state &state)
Sets a previous state of the CDR serialization process;.
Definition: Cdr.cpp:417
eprosima::fastcdr::Cdr::options_
std::array< uint8_t, 2 > options_
This attribute stores the option flags when the CDR type is DDS_CDR;.
Definition: Cdr.h:3509
eprosima::fastcdr::Cdr::end_serialize_opt_member_
end_serialize_member_functor end_serialize_opt_member_
Definition: Cdr.h:3480
eprosima::fastcdr::Cdr::read_string
const Cdr_DllAPI char * read_string(uint32_t &length)
Definition: Cdr.cpp:1655
eprosima::fastcdr::exception::Exception::raise
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
eprosima::fastcdr::Cdr::serialize_bool_sequence
Cdr_DllAPI Cdr & serialize_bool_sequence(const std::vector< bool > &vector_t)
Definition: Cdr.cpp:2192
eprosima::fastcdr::Cdr::SerializedMemberSizeForNextInt
SerializedMemberSizeForNextInt
Definition: Cdr.h:3539
eprosima::fastcdr::Cdr::serialize_bool_array
Cdr_DllAPI Cdr & serialize_bool_array(const std::vector< bool > &vector_t)
Definition: Cdr.cpp:2154
eprosima::fastcdr::Cdr::xcdr1_change_to_short_member_header
void xcdr1_change_to_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv1.
Definition: Cdr.cpp:2497
eprosima::fastcdr::Cdr::serialize
Cdr & serialize(const _T &value)
Encodes the value of a type into the buffer.
Definition: Cdr.h:380
eprosima::fastcdr::Cdr::deserialize
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
Definition: Cdr.h:1428
eprosima::fastcdr::Cdr::xcdr1_begin_serialize_type
Cdr & xcdr1_begin_serialize_type(Cdr::state &current_state, EncodingAlgorithmFlag type_encoding) noexcept
Tells to the encoder a new type and its members start to be encoded according to XCDRv1.
Definition: Cdr.cpp:3119
eprosima::fastcdr::Cdr::XCdrHeaderSelection
XCdrHeaderSelection
Definition: Cdr.h:89
eprosima::fastcdr::FastBuffer
This class represents a stream of bytes that contains (or will contain) serialized data....
Definition: FastBuffer.h:243
eprosima::fastcdr::Cdr::cdr_deserialize_type
Cdr & cdr_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Definition: Cdr.cpp:3361
eprosima::fastcdr::Cdr::cdr_buffer_
FastBuffer & cdr_buffer_
Reference to the buffer that will be serialized/deserialized.
Definition: Cdr.h:3497
eprosima::fastcdr::Cdr::state::member_size_
uint32_t member_size_
Not related with the state. Used by encoding algorithms to set the encoded member size.
Definition: Cdr.h:144
eprosima::fastcdr::PL_CDR2
@ PL_CDR2
Specifies that the content is PL_CDR2.
Definition: CdrEncoding.hpp:48
eprosima::fastcdr::Cdr::state::swap_bytes_
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes when the state is created.
Definition: Cdr.h:135
eprosima::fastcdr::Cdr::make_alignment
void make_alignment(size_t align)
This function jumps the number of bytes of the alignment. These bytes should be calculated with the f...
Definition: Cdr.h:3049
eprosima::fastcdr::EncodingAlgorithmFlag
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
Definition: CdrEncoding.hpp:37
dst
char * dst
Definition: lz4.h:792
eprosima
Definition: fixed_size_string.hpp:32
eprosima::fastcdr::Cdr::set_xcdrv2_dheader
Cdr_DllAPI void set_xcdrv2_dheader(const state &state)
Uses the state to calculate the member's type size and serialize the value in the previous allocated ...
Definition: Cdr.cpp:3394
eprosima::fastcdr::Cdr::xcdr2_serialize_long_member_header
void xcdr2_serialize_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv2.
Definition: Cdr.cpp:2607
eprosima::fastcdr::Cdr::xcdr1_end_short_member_header
void xcdr1_end_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a short member header of a member according to XCDRv1.
Definition: Cdr.cpp:2458
eprosima::fastcdr::Cdr::get_short_lc
uint32_t get_short_lc(size_t member_serialized_size)
Definition: Cdr.cpp:73
char_t
typename detail::char_t_impl< S >::type char_t
Definition: core.h:664
eprosima::fastcdr::Cdr::xcdr2_change_to_long_member_header
void xcdr2_change_to_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv2.
Definition: Cdr.cpp:2647
eprosima::fastcdr::Cdr::state
This class stores the current state of a CDR serialization.
Definition: Cdr.h:104
eprosima::fastcdr::Cdr::get_cdr_version
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the CdrVersion used by the instance.
Definition: Cdr.cpp:329
eprosima::fastcdr::Cdr::xcdr1_serialize_long_member_header
void xcdr1_serialize_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv1.
Definition: Cdr.cpp:2471
eprosima::fastcdr::PID_SENTINEL
constexpr uint16_t PID_SENTINEL
Definition: Cdr.cpp:33
eprosima::fastcdr::FastBuffer::end
iterator end()
This function returns a iterator that points to the end of the stream.
Definition: FastBuffer.h:327
eprosima::fastcdr::Cdr::xcdr1_change_to_long_member_header
void xcdr1_change_to_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded short header to a long header according to XCDRv1.
Definition: Cdr.cpp:2512
eprosima::fastcdr::Cdr::offset_
FastBuffer::iterator offset_
The current position in the serialization/deserialization process.
Definition: Cdr.h:3521
eprosima::fastcdr::Cdr::xcdr1_end_long_member_header
void xcdr1_end_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a long member header of a member according to XCDRv1.
Definition: Cdr.cpp:2488
eprosima::fastcdr::Cdr::alignment
static size_t alignment(size_t current_alignment, size_t data_size)
Returns the number of bytes needed to align a position to certain data size.
Definition: Cdr.h:274
eprosima::fastcdr::Cdr::xcdr1_end_serialize_type
Cdr & xcdr1_end_serialize_type(const Cdr::state &current_state)
Tells to the encoder to finish the encoding of the type.
Definition: Cdr.cpp:3133
eprosima::fastcdr::_FastBuffer_iterator
This class implements the iterator used to go through a FastBuffer.
Definition: FastBuffer.h:42
eprosima::fastcdr::exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
static const Cdr_DllAPI char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
Definition: NotEnoughMemoryException.h:78
eprosima::fastcdr::Cdr::state::offset_
const FastBuffer::iterator offset_
The position in the buffer when the state was created.
Definition: Cdr.h:129


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43