pjmsg_mcap_wrapper
Loading...
Searching...
No Matches
FastCdr.h
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#ifndef _FASTCDR_FASTCDR_H_
16#define _FASTCDR_FASTCDR_H_
17
18#include <array>
19#include <cstdint>
20#include <cstring>
21#include <string>
22#include <vector>
23
24#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
25#include <malloc.h>
26#else
27#include <stdlib.h>
28#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
29
30#include "fastcdr_dll.h"
31#include "FastBuffer.h"
34
35namespace eprosima {
36namespace fastcdr {
37/*!
38 * @brief This class offers an interface to serialize/deserialize some basic types using a modified CDR protocol inside a eprosima::FastBuffer.
39 * This modified CDR protocol provides a serialization mechanism much faster than common CDR protocol, because it doesn't use alignment.
40 * @ingroup FASTCDRAPIREFERENCE
41 */
43{
44public:
45
46 /*!
47 * @brief This class stores the current state of a CDR serialization.
48 */
50 {
51 friend class FastCdr;
52
53 public:
54
55 /*!
56 * @brief Default constructor.
57 */
58 state(
59 const FastCdr& fastcdr);
60
61 /*!
62 * @brief Copy constructor.
63 */
64 state(
65 const state&);
66
67 private:
68
69 state& operator =(
70 const state&) = delete;
71
72 //! @brief The position in the buffer when the state was created.
74 };
75 /*!
76 * @brief This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize
77 * the assigned buffer.
78 *
79 * @param cdr_buffer A reference to the buffer that contains (or will contain) the CDR representation.
80 */
81 FastCdr(
82 FastBuffer& cdr_buffer);
83
84 /*!
85 * @brief This function skips a number of bytes in the CDR stream buffer.
86 * @param num_bytes The number of bytes that will be jumped.
87 * @return True is returned when the jump operation works successfully. Otherwise, false is returned.
88 */
89 bool jump(
90 size_t num_bytes);
91
92 /*!
93 * @brief This function resets the current position in the buffer to the begining.
94 */
95 void reset();
96
97 /*!
98 * @brief This function returns the current position in the CDR stream.
99 * @return Pointer to the current position in the buffer.
100 */
101 char* get_current_position();
102
103 /*!
104 * @brief This function returns the length of the serialized data inside the stream.
105 * @return The length of the serialized data.
106 */
107 inline size_t get_serialized_data_length() const
108 {
109 return current_position_ - cdr_buffer_.begin();
110 }
111
112 /*!
113 * @brief This function returns the current state of the CDR stream.
114 * @return The current state of the buffer.
115 */
116 FastCdr::state get_state();
117
118 /*!
119 * @brief This function sets a previous state of the CDR stream;
120 * @param state Previous state that will be set again.
121 */
122 void set_state(
123 FastCdr::state& state);
124
125 /*!
126 * @brief This operator serializes an octet.
127 * @param octet_t The value of the octet that will be serialized in the buffer.
128 * @return Reference to the eprosima::fastcdr::FastCdr object.
129 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
130 */
131 inline FastCdr& operator <<(
132 const uint8_t octet_t)
133 {
134 return serialize(octet_t);
135 }
136
137 /*!
138 * @brief This operator serializes a character.
139 * @param char_t The value of the character that will be serialized in the buffer.
140 * @return Reference to the eprosima::fastcdr::FastCdr object.
141 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
142 */
143 inline FastCdr& operator <<(
144 const char char_t)
145 {
146 return serialize(char_t);
147 }
148
149 /*!
150 * @brief This operator serializes a int8_t.
151 * @param int8 The value of the int8_t that will be serialized in the buffer.
152 * @return Reference to the eprosima::fastcdr::FastCdr object.
153 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
154 */
155 inline FastCdr& operator <<(
156 const int8_t int8)
157 {
158 return serialize(int8);
159 }
160
161 /*!
162 * @brief This operator serializes an unsigned short.
163 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
164 * @return Reference to the eprosima::fastcdr::FastCdr object.
165 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
166 */
167 inline FastCdr& operator <<(
168 const uint16_t ushort_t)
169 {
170 return serialize(ushort_t);
171 }
172
173 /*!
174 * @brief This operator serializes a short.
175 * @param short_t The value of the short that will be serialized in the buffer.
176 * @return Reference to the eprosima::fastcdr::FastCdr object.
177 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
178 */
179 inline FastCdr& operator <<(
180 const int16_t short_t)
181 {
182 return serialize(short_t);
183 }
184
185 /*!
186 * @brief This operator serializes an unsigned long.
187 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
188 * @return Reference to the eprosima::fastcdr::FastCdr object.
189 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
190 */
191 inline FastCdr& operator <<(
192 const uint32_t ulong_t)
193 {
194 return serialize(ulong_t);
195 }
196
197 /*!
198 * @brief This operator serializes a long.
199 * @param long_t The value of the long that will be serialized in the buffer.
200 * @return Reference to the eprosima::fastcdr::FastCdr object.
201 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
202 */
203 inline FastCdr& operator <<(
204 const int32_t long_t)
205 {
206 return serialize(long_t);
207 }
208
209 /*!
210 * @brief This operator serializes a wide-char.
211 * @param wchar The value of the wide-char that will be serialized in the buffer.
212 * @return Reference to the eprosima::fastcdr::FastCdr object.
213 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
214 */
215 inline FastCdr& operator <<(
216 const wchar_t wchar)
217 {
218 return serialize(wchar);
219 }
220
221 /*!
222 * @brief This operator serializes an unsigned long long.
223 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
224 * @return Reference to the eprosima::fastcdr::FastCdr object.
225 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
226 */
227 inline FastCdr& operator <<(
228 const uint64_t ulonglong_t)
229 {
230 return serialize(ulonglong_t);
231 }
232
233 /*!
234 * @brief This operator serializes a long long.
235 * @param longlong_t The value of the long long that will be serialized in the buffer.
236 * @return Reference to the eprosima::fastcdr::FastCdr object.
237 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
238 */
239 inline FastCdr& operator <<(
240 const int64_t longlong_t)
241 {
242 return serialize(longlong_t);
243 }
244
245 /*!
246 * @brief This operator serializes a float.
247 * @param float_t The value of the float that will be serialized in the buffer.
248 * @return Reference to the eprosima::fastcdr::FastCdr object.
249 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
250 */
251 inline FastCdr& operator <<(
252 const float float_t)
253 {
254 return serialize(float_t);
255 }
256
257 /*!
258 * @brief This operator serializes a ldouble.
259 * @param double_t The value of the double that will be serialized in the buffer.
260 * @return Reference to the eprosima::fastcdr::FastCdr object.
261 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
262 */
263 inline FastCdr& operator <<(
264 const double double_t)
265 {
266 return serialize(double_t);
267 }
268
269 /*!
270 * @brief This operator serializes a long double.
271 * @param ldouble_t The value of the long double that will be serialized in the buffer.
272 * @return Reference to the eprosima::fastcdr::FastCdr object.
273 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
274 */
275 inline FastCdr& operator <<(
276 const long double ldouble_t)
277 {
278 return serialize(ldouble_t);
279 }
280
281 /*!
282 * @brief This operator serializes a boolean.
283 * @param bool_t The value of the boolean that will be serialized in the buffer.
284 * @return Reference to the eprosima::fastcdr::FastCdr object.
285 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
286 */
287 inline FastCdr& operator <<(
288 const bool bool_t)
289 {
290 return serialize(bool_t);
291 }
292
293 /*!
294 * @brief This operator serializes a null-terminated string.
295 * @param string_t The value of the string that will be serialized in the buffer.
296 * @return Reference to the eprosima::fastcdr::FastCdr object.
297 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
298 */
299 inline FastCdr& operator <<(
300 const char* string_t)
301 {
302 return serialize(string_t);
303 }
304
305 /*!
306 * @brief This operator serializes a null-terminated wide-string.
307 * @param string_t The value of the wide-string that will be serialized in the buffer.
308 * @return Reference to the eprosima::fastcdr::FastCdr object.
309 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
310 */
311 inline FastCdr& operator <<(
312 const wchar_t* string_t)
313 {
314 return serialize(string_t);
315 }
316
317 /*!
318 * @brief This operator serializes a string.
319 * @param string_t The string that will be serialized in the buffer.
320 * @return Reference to the eprosima::fastcdr::FastCdr object.
321 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
322 */
323 inline FastCdr& operator <<(
324 const std::string& string_t)
325 {
326 return serialize(string_t);
327 }
328
329 /*!
330 * @brief This operator serializes a wstring.
331 * @param string_t The wstring that will be serialized in the buffer.
332 * @return Reference to the eprosima::fastcdr::FastCdr object.
333 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
334 */
335 inline FastCdr& operator <<(
336 const std::wstring& string_t)
337 {
338 return serialize(string_t);
339 }
340
341 /*!
342 * @brief This operator template is used to serialize arrays.
343 * @param array_t The array that will be serialized in the buffer.
344 * @return Reference to the eprosima::fastcdr::FastCdr object.
345 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
346 */
347 template<class _T, size_t _Size>
348 inline FastCdr& operator <<(
349 const std::array<_T, _Size>& array_t)
350 {
351 return serialize<_T, _Size>(array_t);
352 }
353
354 /*!
355 * @brief This operator template is used to serialize sequences.
356 * @param vector_t The sequence that will be serialized in the buffer.
357 * @return Reference to the eprosima::fastcdr::FastCdr object.
358 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
359 */
360 template<class _T>
361 inline FastCdr& operator <<(
362 const std::vector<_T>& vector_t)
363 {
364 return serialize<_T>(vector_t);
365 }
366
367 /*!
368 * @brief This operator template is used to serialize non-basic types.
369 * @param type_t The object that will be serialized in the buffer.
370 * @return Reference to the eprosima::fastcdr::FastCdr object.
371 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
372 */
373 template<class _T>
374 inline FastCdr& operator <<(
375 const _T& type_t)
376 {
377 type_t.serialize(*this);
378 return *this;
379 }
380
381 /*!
382 * @brief This operator deserializes an octet.
383 * @param octet_t The variable that will store the octet read from the buffer.
384 * @return Reference to the eprosima::fastcdr::FastCdr object.
385 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
386 */
387 inline FastCdr& operator >>(
388 uint8_t& octet_t)
389 {
390 return deserialize(octet_t);
391 }
392
393 /*!
394 * @brief This operator deserializes a character.
395 * @param char_t The variable that will store the character read from the buffer.
396 * @return Reference to the eprosima::fastcdr::FastCdr object.
397 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
398 */
399 inline FastCdr& operator >>(
400 char& char_t)
401 {
402 return deserialize(char_t);
403 }
404
405 /*!
406 * @brief This operator deserializes an int8_t.
407 * @param int8 The variable that will store the int8_t read from the buffer.
408 * @return Reference to the eprosima::fastcdr::FastCdr object.
409 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
410 */
411 inline FastCdr& operator >>(
412 int8_t& int8)
413 {
414 return deserialize(int8);
415 }
416
417 /*!
418 * @brief This operator deserializes an unsigned short.
419 * @param ushort_t The variable that will store the unsigned short read from the buffer.
420 * @return Reference to the eprosima::fastcdr::FastCdr object.
421 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
422 */
423 inline FastCdr& operator >>(
424 uint16_t& ushort_t)
425 {
426 return deserialize(ushort_t);
427 }
428
429 /*!
430 * @brief This operator deserializes a short.
431 * @param short_t The variable that will store the short read from the buffer.
432 * @return Reference to the eprosima::fastcdr::FastCdr object.
433 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
434 */
435 inline FastCdr& operator >>(
436 int16_t& short_t)
437 {
438 return deserialize(short_t);
439 }
440
441 /*!
442 * @brief This operator deserializes an unsigned long.
443 * @param ulong_t The variable that will store the unsigned long read from the buffer.
444 * @return Reference to the eprosima::fastcdr::FastCdr object.
445 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
446 */
447 inline FastCdr& operator >>(
448 uint32_t& ulong_t)
449 {
450 return deserialize(ulong_t);
451 }
452
453 /*!
454 * @brief This operator deserializes a long.
455 * @param long_t The variable that will store the long read from the buffer.
456 * @return Reference to the eprosima::fastcdr::FastCdr object.
457 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
458 */
459 inline FastCdr& operator >>(
460 int32_t& long_t)
461 {
462 return deserialize(long_t);
463 }
464
465 /*!
466 * @brief This operator deserializes a wide-char.
467 * @param wchar The variable that will store the wide-char read from the buffer.
468 * @return Reference to the eprosima::fastcdr::FastCdr object.
469 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
470 */
471 inline FastCdr& operator >>(
472 wchar_t& wchar)
473 {
474 return deserialize(wchar);
475 }
476
477 /*!
478 * @brief This operator deserializes an unsigned long long.
479 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
480 * @return Reference to the eprosima::fastcdr::FastCdr object.
481 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
482 */
483 inline FastCdr& operator >>(
484 uint64_t& ulonglong_t)
485 {
486 return deserialize(ulonglong_t);
487 }
488
489 /*!
490 * @brief This operator deserializes a long long.
491 * @param longlong_t The variable that will store the long long read from the buffer.
492 * @return Reference to the eprosima::fastcdr::FastCdr object.
493 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
494 */
495 inline FastCdr& operator >>(
496 int64_t& longlong_t)
497 {
498 return deserialize(longlong_t);
499 }
500
501 /*!
502 * @brief This operator deserializes a float.
503 * @param float_t The variable that will store the float read from the buffer.
504 * @return Reference to the eprosima::fastcdr::FastCdr object.
505 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
506 */
507 inline FastCdr& operator >>(
508 float& float_t)
509 {
510 return deserialize(float_t);
511 }
512
513 /*!
514 * @brief This operator deserializes a double.
515 * @param double_t The variable that will store the double read from the buffer.
516 * @return Reference to the eprosima::fastcdr::FastCdr object.
517 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
518 */
519 inline FastCdr& operator >>(
520 double& double_t)
521 {
522 return deserialize(double_t);
523 }
524
525 /*!
526 * @brief This operator deserializes a long double.
527 * @param ldouble_t The variable that will store the long double read from the buffer.
528 * @return Reference to the eprosima::fastcdr::FastCdr object.
529 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
530 */
531 inline FastCdr& operator >>(
532 long double& ldouble_t)
533 {
534 return deserialize(ldouble_t);
535 }
536
537 /*!
538 * @brief This operator deserializes a boolean.
539 * @param bool_t The variable that will store the boolean read from the buffer.
540 * @return Reference to the eprosima::fastcdr::FastCdr object.
541 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
542 * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
543 */
544 inline FastCdr& operator >>(
545 bool& bool_t)
546 {
547 return deserialize(bool_t);
548 }
549
550 /*!
551 * @brief This operator deserializes a null-terminated c-string.
552 * @param string_t The variable that will store the c-string read from the buffer.
553 * Please note that a newly allocated string will be returned.
554 * The caller should free the returned pointer when appropiate.
555 * @return Reference to the eprosima::fastcdr::FastCdr object.
556 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
557 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
558 */
559 inline FastCdr& operator >>(
560 char*& string_t)
561 {
562 return deserialize(string_t);
563 }
564
565 /*!
566 * @brief This operator deserializes a string.
567 * @param string_t The variable that will store the string read from the buffer.
568 * @return Reference to the eprosima::fastcdr::FastCdr object.
569 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
570 */
571 inline FastCdr& operator >>(
572 std::string& string_t)
573 {
574 return deserialize(string_t);
575 }
576
577 /*!
578 * @brief This operator deserializes a wstring.
579 * @param string_t The variable that will store the wstring read from the buffer.
580 * @return Reference to the eprosima::fastcdr::FastCdr object.
581 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
582 */
583 inline FastCdr& operator >>(
584 std::wstring& string_t)
585 {
586 return deserialize(string_t);
587 }
588
589 /*!
590 * @brief This operator template is used to deserialize arrays.
591 * @param array_t The variable that will store the array read from the buffer.
592 * @return Reference to the eprosima::fastcdr::FastCdr object.
593 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
594 */
595 template<class _T, size_t _Size>
596 inline FastCdr& operator >>(
597 std::array<_T, _Size>& array_t)
598 {
599 return deserialize<_T, _Size>(array_t);
600 }
601
602 /*!
603 * @brief This operator template is used to deserialize sequences.
604 * @param vector_t The variable that will store the sequence read from the buffer.
605 * @return Reference to the eprosima::fastcdr::FastCdr object.
606 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
607 */
608 template<class _T>
609 inline FastCdr& operator >>(
610 std::vector<_T>& vector_t)
611 {
612 return deserialize<_T>(vector_t);
613 }
614
615 /*!
616 * @brief This operator template is used to deserialize non-basic types.
617 * @param type_t The variable that will store the object read from the buffer.
618 * @return Reference to the eprosima::fastcdr::FastCdr object.
619 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
620 */
621 template<class _T>
622 inline FastCdr& operator >>(
623 _T& type_t)
624 {
625 type_t.deserialize(*this);
626 return *this;
627 }
628
629 /*!
630 * @brief This function serializes an octet.
631 * @param octet_t The value of the octet that will be serialized in the buffer.
632 * @return Reference to the eprosima::fastcdr::FastCdr object.
633 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
634 */
635 inline
637 const uint8_t octet_t)
638 {
639 return serialize(static_cast<char>(octet_t));
640 }
641
642 /*!
643 * @brief This function serializes a character.
644 * @param char_t The value of the character that will be serialized in the buffer.
645 * @return Reference to the eprosima::fastcdr::FastCdr object.
646 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
647 */
648 inline
650 const char char_t)
651 {
652 if (((last_position_ - current_position_) >= sizeof(char_t)) || resize(sizeof(char_t)))
653 {
654 current_position_++ << char_t;
655 return *this;
656 }
657
658 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
659 }
660
661 /*!
662 * @brief This function serializes an int8_t.
663 * @param int8 The value of the int8_t that will be serialized in the buffer.
664 * @return Reference to the eprosima::fastcdr::FastCdr object.
665 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
666 */
667 inline
669 const int8_t int8)
670 {
671 return serialize(static_cast<char>(int8));
672 }
673
674 /*!
675 * @brief This function serializes an unsigned short.
676 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
677 * @return Reference to the eprosima::fastcdr::FastCdr object.
678 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
679 */
680 inline
682 const uint16_t ushort_t)
683 {
684 return serialize(static_cast<int16_t>(ushort_t));
685 }
686
687 /*!
688 * @brief This function serializes a short.
689 * @param short_t The value of the short that will be serialized in the buffer.
690 * @return Reference to the eprosima::fastcdr::FastCdr object.
691 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
692 */
693 inline
695 const int16_t short_t)
696 {
697 if (((last_position_ - current_position_) >= sizeof(short_t)) || resize(sizeof(short_t)))
698 {
699 current_position_ << short_t;
700 current_position_ += sizeof(short_t);
701
702 return *this;
703 }
704
705 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
706 }
707
708 /*!
709 * @brief This function serializes an unsigned long.
710 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
711 * @return Reference to the eprosima::fastcdr::FastCdr object.
712 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
713 */
714 inline
716 const uint32_t ulong_t)
717 {
718 return serialize(static_cast<int32_t>(ulong_t));
719 }
720
721 /*!
722 * @brief This function serializes a long.
723 * @param long_t The value of the long that will be serialized in the buffer.
724 * @return Reference to the eprosima::fastcdr::FastCdr object.
725 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
726 */
727 inline
729 const int32_t long_t)
730 {
731 if (((last_position_ - current_position_) >= sizeof(long_t)) || resize(sizeof(long_t)))
732 {
733 current_position_ << long_t;
734 current_position_ += sizeof(long_t);
735
736 return *this;
737 }
738
739 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
740 }
741
742 /*!
743 * @brief This function serializes a wide-char.
744 * @param wchar The value of the wide-char that will be serialized in the buffer.
745 * @return Reference to the eprosima::fastcdr::FastCdr object.
746 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
747 */
748 inline
750 const wchar_t wchar)
751 {
752 return serialize(static_cast<uint32_t>(wchar));
753 }
754
755 /*!
756 * @brief This function serializes an unsigned long long.
757 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
758 * @return Reference to the eprosima::fastcdr::FastCdr object.
759 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
760 */
761 inline
763 const uint64_t ulonglong_t)
764 {
765 return serialize(static_cast<int64_t>(ulonglong_t));
766 }
767
768 /*!
769 * @brief This function serializes a long long.
770 * @param longlong_t The value of the long long that will be serialized in the buffer.
771 * @return Reference to the eprosima::fastcdr::FastCdr object.
772 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
773 */
774 inline
776 const int64_t longlong_t)
777 {
778 if (((last_position_ - current_position_) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
779 {
780 current_position_ << longlong_t;
781 current_position_ += sizeof(longlong_t);
782
783 return *this;
784 }
785
786 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
787 }
788
789 /*!
790 * @brief This function serializes a float.
791 * @param float_t The value of the float that will be serialized in the buffer.
792 * @return Reference to the eprosima::fastcdr::FastCdr object.
793 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
794 */
795 inline
797 const float float_t)
798 {
799 if (((last_position_ - current_position_) >= sizeof(float_t)) || resize(sizeof(float_t)))
800 {
801 current_position_ << float_t;
802 current_position_ += sizeof(float_t);
803
804 return *this;
805 }
806
807 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
808 }
809
810 /*!
811 * @brief This function serializes a double.
812 * @param double_t The value of the double that will be serialized in the buffer.
813 * @return Reference to the eprosima::fastcdr::FastCdr object.
814 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
815 */
816 inline
818 const double double_t)
819 {
820 if (((last_position_ - current_position_) >= sizeof(double_t)) || resize(sizeof(double_t)))
821 {
822 current_position_ << double_t;
823 current_position_ += sizeof(double_t);
824
825 return *this;
826 }
827
828 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
829 }
830
831 /*!
832 * @brief This function serializes a long double.
833 * @param ldouble_t The value of the long double that will be serialized in the buffer.
834 * @return Reference to the eprosima::fastcdr::FastCdr object.
835 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
836 */
837 inline
839 const long double ldouble_t)
840 {
841 if (((last_position_ - current_position_) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
842 {
843 current_position_ << ldouble_t;
844#if defined(_WIN32)
845 current_position_ += sizeof(ldouble_t);
846 current_position_ << static_cast<long double>(0);
847#endif // if defined(_WIN32)
848 current_position_ += sizeof(ldouble_t);
849
850 return *this;
851 }
852
853 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
854 }
855
856 /*!
857 * @brief This function serializes a boolean.
858 * @param bool_t The value of the boolean that will be serialized in the buffer.
859 * @return Reference to the eprosima::fastcdr::FastCdr object.
860 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
861 */
863 const bool bool_t);
864
865 /*!
866 * @brief This function serializes a string.
867 * @param string_t The pointer to the string that will be serialized in the buffer.
868 * @return Reference to the eprosima::fastcdr::FastCdr object.
869 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
870 */
872 const char* string_t);
873
874 /*!
875 * @brief This function serializes a wstring.
876 * @param string_t The pointer to the wstring that will be serialized in the buffer.
877 * @return Reference to the eprosima::fastcdr::FastCdr object.
878 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
879 */
881 const wchar_t* string_t);
882
883 /*!
884 * @brief This function serializes a std::string.
885 * @param string_t The string that will be serialized in the buffer.
886 * @return Reference to the eprosima::fastcdr::FastCdr object.
887 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
888 * @exception exception::BadParamException This exception is thrown when trying to serialize a string with null characters.
889 */
890 inline
892 const std::string& string_t)
893 {
894 // Check there are no null characters in the string.
895 const char* c_str = string_t.c_str();
896 const auto str_len = strlen(c_str);
897 if (string_t.size() > str_len)
898 {
899 throw exception::BadParamException("The string contains null characters");
900 }
901
902 return serialize(c_str);
903 }
904
905 /*!
906 * @brief This function serializes a std::wstring.
907 * @param string_t The wstring that will be serialized in the buffer.
908 * @return Reference to the eprosima::fastcdr::FastCdr object.
909 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
910 */
911 inline
913 const std::wstring& string_t)
914 {
915 return serialize(string_t.c_str());
916 }
917
918 /*!
919 * @brief This function template serializes an array.
920 * @param array_t The array that will be serialized in the buffer.
921 * @return Reference to the eprosima::fastcdr::FastCdr object.
922 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
923 */
924 template<class _T, size_t _Size>
926 const std::array<_T, _Size>& array_t)
927 {
928 return serialize_array(array_t.data(), array_t.size());
929 }
930
931 /*!
932 * @brief This function template serializes a sequence of booleans.
933 * @param vector_t The sequence that will be serialized in the buffer.
934 * @return Reference to the eprosima::fastcdr::FastCdr object.
935 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
936 */
937 template<class _T = bool>
939 const std::vector<bool>& vector_t)
940 {
941 return serialize_bool_sequence(vector_t);
942 }
943
944 /*!
945 * @brief This function template serializes a sequence.
946 * @param vector_t The sequence that will be serialized in the buffer.
947 * @return Reference to the eprosima::fastcdr::FastCdr object.
948 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
949 */
950 template<class _T>
952 const std::vector<_T>& vector_t)
953 {
954 state state_before_error(*this);
955
956 *this << static_cast<int32_t>(vector_t.size());
957
958 try
959 {
960 return serialize_array(vector_t.data(), vector_t.size());
961 }
963 {
964 set_state(state_before_error);
965 ex.raise();
966 }
967
968 return *this;
969 }
970
971#ifdef _MSC_VER
972 /*!
973 * @brief This function template serializes a sequence of booleans.
974 * @param vector_t The sequence that will be serialized in the buffer.
975 * @return Reference to the eprosima::fastcdr::FastCdr object.
976 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
977 */
978 template<>
979 FastCdr& serialize<bool>(
980 const std::vector<bool>& vector_t)
981 {
982 return serialize_bool_sequence(vector_t);
983 }
984
985#endif // ifdef _MSC_VER
986
987 /*!
988 * @brief This function template serializes a non-basic type.
989 * @param type_t The object that will be serialized in the buffer.
990 * @return Reference to the eprosima::fastcdr::FastCdr object.
991 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
992 */
993 template<class _T>
995 const _T& type_t)
996 {
997 type_t.serialize(*this);
998 return *this;
999 }
1000
1001 /*!
1002 * @brief This function serializes an array of octets.
1003 * @param octet_t The sequence of octets that will be serialized in the buffer.
1004 * @param num_elements Number of the elements in the array.
1005 * @return Reference to the eprosima::fastcdr::FastCdr object.
1006 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1007 */
1008 inline
1010 const uint8_t* octet_t,
1011 size_t num_elements)
1012 {
1013 return serialize_array(reinterpret_cast<const char*>(octet_t), num_elements);
1014 }
1015
1016 /*!
1017 * @brief This function serializes an array of characters.
1018 * @param char_t The array of characters that will be serialized in the buffer.
1019 * @param num_elements Number of the elements in the array.
1020 * @return Reference to the eprosima::fastcdr::FastCdr object.
1021 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1022 */
1023 FastCdr& serialize_array(
1024 const char* char_t,
1025 size_t num_elements);
1026
1027 /*!
1028 * @brief This function serializes an array of int8_t.
1029 * @param int8 The sequence of int8_t that will be serialized in the buffer.
1030 * @param num_elements Number of the elements in the array.
1031 * @return Reference to the eprosima::fastcdr::FastCdr object.
1032 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1033 */
1034 inline
1036 const int8_t* int8,
1037 size_t num_elements)
1038 {
1039 return serialize_array(reinterpret_cast<const char*>(int8), num_elements);
1040 }
1041
1042 /*!
1043 * @brief This function serializes an array of unsigned shorts.
1044 * @param ushort_t The array of unsigned shorts that will be serialized in the buffer.
1045 * @param num_elements Number of the elements in the array.
1046 * @return Reference to the eprosima::fastcdr::FastCdr object.
1047 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1048 */
1049 inline
1051 const uint16_t* ushort_t,
1052 size_t num_elements)
1053 {
1054 return serialize_array(reinterpret_cast<const int16_t*>(ushort_t), num_elements);
1055 }
1056
1057 /*!
1058 * @brief This function serializes an array of shorts.
1059 * @param short_t The array of shorts that will be serialized in the buffer.
1060 * @param num_elements Number of the elements in the array.
1061 * @return Reference to the eprosima::fastcdr::FastCdr object.
1062 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1063 */
1064 FastCdr& serialize_array(
1065 const int16_t* short_t,
1066 size_t num_elements);
1067
1068 /*!
1069 * @brief This function serializes an array of unsigned longs.
1070 * @param ulong_t The array of unsigned longs that will be serialized in the buffer.
1071 * @param num_elements Number of the elements in the array.
1072 * @return Reference to the eprosima::fastcdr::FastCdr object.
1073 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1074 */
1075 inline
1077 const uint32_t* ulong_t,
1078 size_t num_elements)
1079 {
1080 return serialize_array(reinterpret_cast<const int32_t*>(ulong_t), num_elements);
1081 }
1082
1083 /*!
1084 * @brief This function serializes an array of longs.
1085 * @param long_t The array of longs that will be serialized in the buffer.
1086 * @param num_elements Number of the elements in the array.
1087 * @return Reference to the eprosima::fastcdr::FastCdr object.
1088 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1089 */
1090 FastCdr& serialize_array(
1091 const int32_t* long_t,
1092 size_t num_elements);
1093
1094 /*!
1095 * @brief This function serializes an array of wide-chars.
1096 * @param wchar The array of wide-chars that will be serialized in the buffer.
1097 * @param num_elements Number of the elements in the array.
1098 * @return Reference to the eprosima::fastcdr::FastCdr object.
1099 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1100 */
1101 FastCdr& serialize_array(
1102 const wchar_t* wchar,
1103 size_t num_elements);
1104
1105 /*!
1106 * @brief This function serializes an array of unsigned long longs.
1107 * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer.
1108 * @param num_elements Number of the elements in the array.
1109 * @return Reference to the eprosima::fastcdr::FastCdr object.
1110 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1111 */
1112 inline
1114 const uint64_t* ulonglong_t,
1115 size_t num_elements)
1116 {
1117 return serialize_array(reinterpret_cast<const int64_t*>(ulonglong_t), num_elements);
1118 }
1119
1120 /*!
1121 * @brief This function serializes an array of long longs.
1122 * @param longlong_t The array of long longs that will be serialized in the buffer.
1123 * @param num_elements Number of the elements in the array.
1124 * @return Reference to the eprosima::fastcdr::FastCdr object.
1125 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1126 */
1127 FastCdr& serialize_array(
1128 const int64_t* longlong_t,
1129 size_t num_elements);
1130
1131 /*!
1132 * @brief This function serializes an array of floats.
1133 * @param float_t The array of floats that will be serialized in the buffer.
1134 * @param num_elements Number of the elements in the array.
1135 * @return Reference to the eprosima::fastcdr::FastCdr object.
1136 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1137 */
1138 FastCdr& serialize_array(
1139 const float* float_t,
1140 size_t num_elements);
1141
1142 /*!
1143 * @brief This function serializes an array of doubles.
1144 * @param double_t The array of doubles that will be serialized in the buffer.
1145 * @param num_elements Number of the elements in the array.
1146 * @return Reference to the eprosima::fastcdr::FastCdr object.
1147 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1148 */
1149 FastCdr& serialize_array(
1150 const double* double_t,
1151 size_t num_elements);
1152
1153 /*!
1154 * @brief This function serializes an array of long doubles.
1155 * @param ldouble_t The array of long doubles that will be serialized in the buffer.
1156 * @param num_elements Number of the elements in the array.
1157 * @return Reference to the eprosima::fastcdr::FastCdr object.
1158 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1159 */
1160 FastCdr& serialize_array(
1161 const long double* ldouble_t,
1162 size_t num_elements);
1163
1164 /*!
1165 * @brief This function serializes an array of booleans.
1166 * @param bool_t The array of booleans that will be serialized in the buffer.
1167 * @param num_elements Number of the elements in the array.
1168 * @return Reference to the eprosima::fastcdr::FastCdr object.
1169 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1170 */
1171 FastCdr& serialize_array(
1172 const bool* bool_t,
1173 size_t num_elements);
1174
1175 /*!
1176 * @brief This function serializes an array of strings.
1177 * @param string_t The array of strings that will be serialized in the buffer.
1178 * @param num_elements Number of the elements in the array.
1179 * @return Reference to the eprosima::fastcdr::FastCdr object.
1180 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1181 */
1182 inline
1184 const std::string* string_t,
1185 size_t num_elements)
1186 {
1187 for (size_t count = 0; count < num_elements; ++count)
1188 {
1189 serialize(string_t[count].c_str());
1190 }
1191 return *this;
1192 }
1193
1194 /*!
1195 * @brief This function serializes an array of wstrings.
1196 * @param string_t The array of wstrings that will be serialized in the buffer.
1197 * @param num_elements Number of the elements in the array.
1198 * @return Reference to the eprosima::fastcdr::FastCdr object.
1199 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1200 */
1201 inline
1203 const std::wstring* string_t,
1204 size_t num_elements)
1205 {
1206 for (size_t count = 0; count < num_elements; ++count)
1207 {
1208 serialize(string_t[count].c_str());
1209 }
1210 return *this;
1211 }
1212
1213 /*!
1214 * @brief This function template serializes an array of sequences.
1215 * @param vector_t The array of sequences that will be serialized in the buffer.
1216 * @param num_elements Number of the elements in the array.
1217 * @return Reference to the eprosima::fastcdr::FastCdr object.
1218 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1219 */
1220 template<class _T>
1222 const std::vector<_T>* vector_t,
1223 size_t num_elements)
1224 {
1225 for (size_t count = 0; count < num_elements; ++count)
1226 {
1227 serialize(vector_t[count]);
1228 }
1229 return *this;
1230 }
1231
1232 /*!
1233 * @brief This function template serializes an array of non-basic type objects.
1234 * @param type_t The array of objects that will be serialized in the buffer.
1235 * @param num_elements Number of the elements in the array.
1236 * @return Reference to the eprosima::fastcdr::FastCdr object.
1237 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1238 */
1239 template<class _T>
1241 const _T* type_t,
1242 size_t num_elements)
1243 {
1244 for (size_t count = 0; count < num_elements; ++count)
1245 {
1246 type_t[count].serialize(*this);
1247 }
1248 return *this;
1249 }
1250
1251 /*!
1252 * @brief This function template serializes a raw sequence.
1253 * @param sequence_t Pointer to the sequence that will be serialized in the buffer.
1254 * @param num_elements The number of elements contained in the sequence.
1255 * @return Reference to the eprosima::fastcdr::FastCdr object.
1256 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
1257 */
1258 template<class _T>
1260 const _T* sequence_t,
1261 size_t num_elements)
1262 {
1263 state state_before_error(*this);
1264
1265 serialize(static_cast<int32_t>(num_elements));
1266
1267 try
1268 {
1269 return serialize_array(sequence_t, num_elements);
1270 }
1272 {
1273 set_state(state_before_error);
1274 ex.raise();
1275 }
1276
1277 return *this;
1278 }
1279
1280 /*!
1281 * @brief This function deserializes an octet.
1282 * @param octet_t The variable that will store the octet read from the buffer.
1283 * @return Reference to the eprosima::fastcdr::FastCdr object.
1284 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1285 */
1286 inline
1288 uint8_t& octet_t)
1289 {
1290 return deserialize(reinterpret_cast<char&>(octet_t));
1291 }
1292
1293 /*!
1294 * @brief This function deserializes a character.
1295 * @param char_t The variable that will store the character read from the buffer.
1296 * @return Reference to the eprosima::fastcdr::FastCdr object.
1297 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1298 */
1299 inline
1301 char& char_t)
1302 {
1303 if ((last_position_ - current_position_) >= sizeof(char_t))
1304 {
1305 current_position_++ >> char_t;
1306 return *this;
1307 }
1308
1309 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1310 }
1311
1312 /*!
1313 * @brief This function deserializes an int8_t.
1314 * @param int8 The variable that will store the int8_t read from the buffer.
1315 * @return Reference to the eprosima::fastcdr::FastCdr object.
1316 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1317 */
1318 inline
1320 int8_t& int8)
1321 {
1322 return deserialize(reinterpret_cast<char&>(int8));
1323 }
1324
1325 /*!
1326 * @brief This function deserializes an unsigned short.
1327 * @param ushort_t The variable that will store the unsigned short read from the buffer.
1328 * @return Reference to the eprosima::fastcdr::FastCdr object.
1329 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1330 */
1331 inline
1333 uint16_t& ushort_t)
1334 {
1335 return deserialize(reinterpret_cast<int16_t&>(ushort_t));
1336 }
1337
1338 /*!
1339 * @brief This function deserializes a short.
1340 * @param short_t The variable that will store the short read from the buffer.
1341 * @return Reference to the eprosima::fastcdr::FastCdr object.
1342 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1343 */
1344 inline
1346 int16_t& short_t)
1347 {
1348 if ((last_position_ - current_position_) >= sizeof(short_t))
1349 {
1350 current_position_ >> short_t;
1351 current_position_ += sizeof(short_t);
1352
1353 return *this;
1354 }
1355
1356 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1357 }
1358
1359 /*!
1360 * @brief This function deserializes an unsigned long.
1361 * @param ulong_t The variable that will store the unsigned long read from the buffer.
1362 * @return Reference to the eprosima::fastcdr::FastCdr object.
1363 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1364 */
1365 inline
1367 uint32_t& ulong_t)
1368 {
1369 return deserialize(reinterpret_cast<int32_t&>(ulong_t));
1370 }
1371
1372 /*!
1373 * @brief This function deserializes a long.
1374 * @param long_t The variable that will store the long read from the buffer.
1375 * @return Reference to the eprosima::fastcdr::FastCdr object.
1376 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1377 */
1378 inline
1380 int32_t& long_t)
1381 {
1382 if ((last_position_ - current_position_) >= sizeof(long_t))
1383 {
1384 current_position_ >> long_t;
1385 current_position_ += sizeof(long_t);
1386
1387 return *this;
1388 }
1389
1390 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1391 }
1392
1393 /*!
1394 * @brief This function deserializes a wide-char.
1395 * @param wchar The variable that will store the wide-char read from the buffer.
1396 * @return Reference to the eprosima::fastcdr::FastCdr object.
1397 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1398 */
1399 inline
1401 wchar_t& wchar)
1402 {
1403 uint32_t ret;
1404 deserialize(ret);
1405 wchar = static_cast<wchar_t>(ret);
1406 return *this;
1407 }
1408
1409 /*!
1410 * @brief This function deserializes an unsigned long long.
1411 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
1412 * @return Reference to the eprosima::fastcdr::FastCdr object.
1413 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1414 */
1415 inline
1417 uint64_t& ulonglong_t)
1418 {
1419 return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
1420 }
1421
1422 /*!
1423 * @brief This function deserializes a long long.
1424 * @param longlong_t The variable that will store the long long read from the buffer.
1425 * @return Reference to the eprosima::fastcdr::FastCdr object.
1426 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1427 */
1428 inline
1430 int64_t& longlong_t)
1431 {
1432 if ((last_position_ - current_position_) >= sizeof(longlong_t))
1433 {
1434 current_position_ >> longlong_t;
1435 current_position_ += sizeof(longlong_t);
1436
1437 return *this;
1438 }
1439
1440 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1441 }
1442
1443 /*!
1444 * @brief This function deserializes a float.
1445 * @param float_t The variable that will store the float read from the buffer.
1446 * @return Reference to the eprosima::fastcdr::FastCdr object.
1447 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1448 */
1449 inline
1451 float& float_t)
1452 {
1453 if ((last_position_ - current_position_) >= sizeof(float_t))
1454 {
1455 current_position_ >> float_t;
1456 current_position_ += sizeof(float_t);
1457
1458 return *this;
1459 }
1460
1461 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1462 }
1463
1464 /*!
1465 * @brief This function deserializes a double.
1466 * @param double_t The variable that will store the double read from the buffer.
1467 * @return Reference to the eprosima::fastcdr::FastCdr object.
1468 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1469 */
1470 inline
1472 double& double_t)
1473 {
1474 if ((last_position_ - current_position_) >= sizeof(double_t))
1475 {
1476 current_position_ >> double_t;
1477 current_position_ += sizeof(double_t);
1478
1479 return *this;
1480 }
1481
1482 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1483 }
1484
1485 /*!
1486 * @brief This function deserializes a long double.
1487 * @param ldouble_t The variable that will store the long double read from the buffer.
1488 * @return Reference to the eprosima::fastcdr::FastCdr object.
1489 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1490 */
1491 inline
1493 long double& ldouble_t)
1494 {
1495 if ((last_position_ - current_position_) >= sizeof(ldouble_t))
1496 {
1497 current_position_ >> ldouble_t;
1498 current_position_ += sizeof(ldouble_t);
1499#if defined(_WIN32)
1500 current_position_ += sizeof(ldouble_t);
1501#endif // if defined(_WIN32)
1502
1503 return *this;
1504 }
1505
1506 throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
1507 }
1508
1509 /*!
1510 * @brief This function deserializes a boolean.
1511 * @param bool_t The variable that will store the boolean read from the buffer.
1512 * @return Reference to the eprosima::fastcdr::FastCdr object.
1513 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1514 * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
1515 */
1517 bool& bool_t);
1518
1519 /*!
1520 * @brief This function deserializes a string.
1521 * This function allocates memory to store the string. The user pointer will be set to point this allocated memory.
1522 * The user will have to free this allocated memory using free()
1523 * @param string_t The pointer that will point to the string read from the buffer.
1524 * The user will have to free the allocated memory using free()
1525 * @return Reference to the eprosima::fastcdr::FastCdr object.
1526 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1527 */
1529 char*& string_t);
1530
1531 /*!
1532 * @brief This function deserializes a wide string.
1533 * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory.
1534 * The user will have to free this allocated memory using free()
1535 * @param string_t The pointer that will point to the wide string read from the buffer.
1536 * The user will have to free the allocated memory using free()
1537 * @return Reference to the eprosima::fastcdr::FastCdr object.
1538 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1539 */
1541 wchar_t*& string_t);
1542
1543 /*!
1544 * @brief This function deserializes a std::string.
1545 * @param string_t The variable that will store the string read from the buffer.
1546 * @return Reference to the eprosima::fastcdr::FastCdr object.
1547 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1548 */
1549 inline
1551 std::string& string_t)
1552 {
1553 uint32_t length = 0;
1554 const char* str = read_string(length);
1555 string_t.assign(str, length);
1556 return *this;
1557 }
1558
1559 /*!
1560 * @brief This function deserializes a std::wstring.
1561 * @param string_t The variable that will store the wstring read from the buffer.
1562 * @return Reference to the eprosima::fastcdr::FastCdr object.
1563 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1564 */
1565 inline
1567 std::wstring& string_t)
1568 {
1569 uint32_t length = 0;
1570 string_t = read_wstring(length);
1571 return *this;
1572 }
1573
1574 /*!
1575 * @brief This function template deserializes an array.
1576 * @param array_t The variable that will store the array read from the buffer.
1577 * @return Reference to the eprosima::fastcdr::FastCdr object.
1578 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1579 */
1580 template<class _T, size_t _Size>
1582 std::array<_T, _Size>& array_t)
1583 {
1584 return deserialize_array(array_t.data(), array_t.size());
1585 }
1586
1587 /*!
1588 * @brief This function template deserializes a sequence of booleans.
1589 * @param vector_t The variable that will store the sequence read from the buffer.
1590 * @return Reference to the eprosima::fastcdr::FastCdr object.
1591 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1592 */
1593 template<class _T = bool>
1595 std::vector<bool>& vector_t)
1596 {
1597 return deserialize_bool_sequence(vector_t);
1598 }
1599
1600 /*!
1601 * @brief This function template deserializes a sequence.
1602 * @param vector_t The variable that will store the sequence read from the buffer.
1603 * @return Reference to the eprosima::fastcdr::FastCdr object.
1604 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1605 */
1606 template<class _T>
1608 std::vector<_T>& vector_t)
1609 {
1610 uint32_t sequence_length = 0;
1611 state state_before_error(*this);
1612
1613 *this >> sequence_length;
1614
1615 try
1616 {
1617 vector_t.resize(sequence_length);
1618 return deserialize_array(vector_t.data(), vector_t.size());
1619 }
1621 {
1622 set_state(state_before_error);
1623 ex.raise();
1624 }
1625
1626 return *this;
1627 }
1628
1629#ifdef _MSC_VER
1630 /*!
1631 * @brief This function template deserializes a sequence of booleans.
1632 * @param vector_t The variable that will store the sequence read from the buffer.
1633 * @return Reference to the eprosima::fastcdr::FastCdr object.
1634 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1635 */
1636 template<>
1637 FastCdr& deserialize<bool>(
1638 std::vector<bool>& vector_t)
1639 {
1640 return deserialize_bool_sequence(vector_t);
1641 }
1642
1643#endif // ifdef _MSC_VER
1644
1645 /*!
1646 * @brief This function template deserializes a non-basic type object.
1647 * @param type_t The variable that will store the object read from the buffer.
1648 * @return Reference to the eprosima::fastcdr::FastCdr object.
1649 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1650 */
1651 template<class _T>
1653 _T& type_t)
1654 {
1655 type_t.deserialize(*this);
1656 return *this;
1657 }
1658
1659 /*!
1660 * @brief This function deserializes an array of octets.
1661 * @param octet_t The variable that will store the array of octets read from the buffer.
1662 * @param num_elements Number of the elements in the array.
1663 * @return Reference to the eprosima::fastcdr::FastCdr object.
1664 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1665 */
1666 inline
1668 uint8_t* octet_t,
1669 size_t num_elements)
1670 {
1671 return deserialize_array(reinterpret_cast<char*>(octet_t), num_elements);
1672 }
1673
1674 /*!
1675 * @brief This function deserializes an array of characters.
1676 * @param char_t The variable that will store the array of characters read from the buffer.
1677 * @param num_elements Number of the elements in the array.
1678 * @return Reference to the eprosima::fastcdr::FastCdr object.
1679 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1680 */
1681 FastCdr& deserialize_array(
1682 char* char_t,
1683 size_t num_elements);
1684
1685 /*!
1686 * @brief This function deserializes an array of int8_t.
1687 * @param int8 The variable that will store the array of int8_t read from the buffer.
1688 * @param num_elements Number of the elements in the array.
1689 * @return Reference to the eprosima::fastcdr::FastCdr object.
1690 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1691 */
1692 inline
1694 int8_t* int8,
1695 size_t num_elements)
1696 {
1697 return deserialize_array(reinterpret_cast<char*>(int8), num_elements);
1698 }
1699
1700 /*!
1701 * @brief This function deserializes an array of unsigned shorts.
1702 * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer.
1703 * @param num_elements Number of the elements in the array.
1704 * @return Reference to the eprosima::fastcdr::FastCdr object.
1705 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1706 */
1707 inline
1709 uint16_t* ushort_t,
1710 size_t num_elements)
1711 {
1712 return deserialize_array(reinterpret_cast<int16_t*>(ushort_t), num_elements);
1713 }
1714
1715 /*!
1716 * @brief This function deserializes an array of shorts.
1717 * @param short_t The variable that will store the array of shorts read from the buffer.
1718 * @param num_elements Number of the elements in the array.
1719 * @return Reference to the eprosima::fastcdr::FastCdr object.
1720 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1721 */
1722 FastCdr& deserialize_array(
1723 int16_t* short_t,
1724 size_t num_elements);
1725
1726 /*!
1727 * @brief This function deserializes an array of unsigned longs.
1728 * @param ulong_t The variable that will store the array of unsigned longs read from the buffer.
1729 * @param num_elements Number of the elements in the array.
1730 * @return Reference to the eprosima::fastcdr::FastCdr object.
1731 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1732 */
1733 inline
1735 uint32_t* ulong_t,
1736 size_t num_elements)
1737 {
1738 return deserialize_array(reinterpret_cast<int32_t*>(ulong_t), num_elements);
1739 }
1740
1741 /*!
1742 * @brief This function deserializes an array of longs.
1743 * @param long_t The variable that will store the array of longs read from the buffer.
1744 * @param num_elements Number of the elements in the array.
1745 * @return Reference to the eprosima::fastcdr::FastCdr object.
1746 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1747 */
1748 FastCdr& deserialize_array(
1749 int32_t* long_t,
1750 size_t num_elements);
1751
1752 /*!
1753 * @brief This function deserializes an array of wide-chars.
1754 * @param wchar The variable that will store the array of wide-chars read from the buffer.
1755 * @param num_elements Number of the elements in the array.
1756 * @return Reference to the eprosima::fastcdr::FastCdr object.
1757 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1758 */
1759 FastCdr& deserialize_array(
1760 wchar_t* wchar,
1761 size_t num_elements);
1762
1763 /*!
1764 * @brief This function deserializes an array of unsigned long longs.
1765 * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer.
1766 * @param num_elements Number of the elements in the array.
1767 * @return Reference to the eprosima::fastcdr::FastCdr object.
1768 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1769 */
1770 inline
1772 uint64_t* ulonglong_t,
1773 size_t num_elements)
1774 {
1775 return deserialize_array(reinterpret_cast<int64_t*>(ulonglong_t), num_elements);
1776 }
1777
1778 /*!
1779 * @brief This function deserializes an array of long longs.
1780 * @param longlong_t The variable that will store the array of long longs read from the buffer.
1781 * @param num_elements Number of the elements in the array.
1782 * @return Reference to the eprosima::fastcdr::FastCdr object.
1783 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1784 */
1785 FastCdr& deserialize_array(
1786 int64_t* longlong_t,
1787 size_t num_elements);
1788
1789 /*!
1790 * @brief This function deserializes an array of floats.
1791 * @param float_t The variable that will store the array of floats read from the buffer.
1792 * @param num_elements Number of the elements in the array.
1793 * @return Reference to the eprosima::fastcdr::FastCdr object.
1794 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1795 */
1796 FastCdr& deserialize_array(
1797 float* float_t,
1798 size_t num_elements);
1799
1800 /*!
1801 * @brief This function deserializes an array of doubles.
1802 * @param double_t The variable that will store the array of doubles read from the buffer.
1803 * @param num_elements Number of the elements in the array.
1804 * @return Reference to the eprosima::fastcdr::FastCdr object.
1805 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1806 */
1807 FastCdr& deserialize_array(
1808 double* double_t,
1809 size_t num_elements);
1810
1811 /*!
1812 * @brief This function deserializes an array of long doubles.
1813 * @param ldouble_t The variable that will store the array of long doubles read from the buffer.
1814 * @param num_elements Number of the elements in the array.
1815 * @return Reference to the eprosima::fastcdr::FastCdr object.
1816 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1817 */
1818 FastCdr& deserialize_array(
1819 long double* ldouble_t,
1820 size_t num_elements);
1821
1822 /*!
1823 * @brief This function deserializes an array of booleans.
1824 * @param bool_t The variable that will store the array of booleans read from the buffer.
1825 * @param num_elements Number of the elements in the array.
1826 * @return Reference to the eprosima::fastcdr::FastCdr object.
1827 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1828 */
1829 FastCdr& deserialize_array(
1830 bool* bool_t,
1831 size_t num_elements);
1832
1833 /*!
1834 * @brief This function deserializes an array of strings.
1835 * @param string_t The variable that will store the array of strings read from the buffer.
1836 * @param num_elements Number of the elements in the array.
1837 * @return Reference to the eprosima::fastcdr::FastCdr object.
1838 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1839 */
1840 inline
1842 std::string* string_t,
1843 size_t num_elements)
1844 {
1845 for (size_t count = 0; count < num_elements; ++count)
1846 {
1847 deserialize(string_t[count]);
1848 }
1849 return *this;
1850 }
1851
1852 /*!
1853 * @brief This function deserializes an array of wide-strings.
1854 * @param string_t The variable that will store the array of strings read from the buffer.
1855 * @param num_elements Number of the elements in the array.
1856 * @return Reference to the eprosima::fastcdr::FastCdr object.
1857 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1858 */
1859 inline
1861 std::wstring* string_t,
1862 size_t num_elements)
1863 {
1864 for (size_t count = 0; count < num_elements; ++count)
1865 {
1866 deserialize(string_t[count]);
1867 }
1868 return *this;
1869 }
1870
1871 /*!
1872 * @brief This function template deserializes an array of sequences.
1873 * @param vector_t The variable that will store the array of sequences read from the buffer.
1874 * @param num_elements Number of the elements in the array.
1875 * @return Reference to the eprosima::fastcdr::FastCdr object.
1876 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1877 */
1878 template<class _T>
1880 std::vector<_T>* vector_t,
1881 size_t num_elements)
1882 {
1883 for (size_t count = 0; count < num_elements; ++count)
1884 {
1885 deserialize(vector_t[count]);
1886 }
1887 return *this;
1888 }
1889
1890 /*!
1891 * @brief This function template deserializes an array of non-basic type objects.
1892 * @param type_t The variable that will store the array of objects read from the buffer.
1893 * @param num_elements Number of the elements in the array.
1894 * @return Reference to the eprosima::fastcdr::FastCdr object.
1895 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1896 */
1897 template<class _T>
1899 _T* type_t,
1900 size_t num_elements)
1901 {
1902 for (size_t count = 0; count < num_elements; ++count)
1903 {
1904 type_t[count].deserialize(*this);
1905 }
1906 return *this;
1907 }
1908
1909 /*!
1910 * @brief This function template deserializes a string sequence.
1911 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
1912 * The user will have to free this allocated memory using free()
1913 * @param sequence_t The pointer that will store the sequence read from the buffer.
1914 * @param num_elements This variable return the number of elements of the sequence.
1915 * @return Reference to the eprosima::fastcdr::FastCdr object.
1916 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1917 */
1918 template<class _T = std::string>
1920 std::string*& sequence_t,
1921 size_t& num_elements)
1922 {
1923 return deserialize_string_sequence(sequence_t, num_elements);
1924 }
1925
1926 /*!
1927 * @brief This function template deserializes a wide-string sequence.
1928 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
1929 * The user will have to free this allocated memory using free()
1930 * @param sequence_t The pointer that will store the sequence read from the buffer.
1931 * @param num_elements This variable return the number of elements of the sequence.
1932 * @return Reference to the eprosima::fastcdr::FastCdr object.
1933 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1934 */
1935 template<class _T = std::wstring>
1937 std::wstring*& sequence_t,
1938 size_t& num_elements)
1939 {
1940 return deserialize_wstring_sequence(sequence_t, num_elements);
1941 }
1942
1943 /*!
1944 * @brief This function template deserializes a raw sequence.
1945 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
1946 * The user will have to free this allocated memory using free()
1947 * @param sequence_t The pointer that will store the sequence read from the buffer.
1948 * @param num_elements This variable return the number of elements of the sequence.
1949 * @return Reference to the eprosima::fastcdr::FastCdr object.
1950 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1951 */
1952 template<class _T>
1954 _T*& sequence_t,
1955 size_t& num_elements)
1956 {
1957 uint32_t sequence_length = 0;
1958 state state_before_error(*this);
1959
1960 deserialize(sequence_length);
1961
1962 try
1963 {
1964 sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T)));
1965 deserialize_array(sequence_t, sequence_length);
1966 }
1968 {
1969 free(sequence_t);
1970 sequence_t = NULL;
1971 set_state(state_before_error);
1972 ex.raise();
1973 }
1974
1975 num_elements = sequence_length;
1976 return *this;
1977 }
1978
1979#ifdef _MSC_VER
1980 /*!
1981 * @brief This function template deserializes a string sequence.
1982 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
1983 * The user will have to free this allocated memory using free()
1984 * @param sequence_t The pointer that will store the sequence read from the buffer.
1985 * @param num_elements This variable return the number of elements of the sequence.
1986 * @return Reference to the eprosima::fastcdr::FastCdr object.
1987 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
1988 */
1989 template<>
1990 FastCdr& deserialize_sequence<std::string>(
1991 std::string*& sequence_t,
1992 size_t& num_elements)
1993 {
1994 return deserialize_string_sequence(sequence_t, num_elements);
1995 }
1996
1997 /*!
1998 * @brief This function template deserializes a wide-string sequence.
1999 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
2000 * The user will have to free this allocated memory using free()
2001 * @param sequence_t The pointer that will store the sequence read from the buffer.
2002 * @param num_elements This variable return the number of elements of the sequence.
2003 * @return Reference to the eprosima::fastcdr::FastCdr object.
2004 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
2005 */
2006 template<>
2007 FastCdr& deserialize_sequence<std::wstring>(
2008 std::wstring*& sequence_t,
2009 size_t& num_elements)
2010 {
2011 return deserialize_wstring_sequence(sequence_t, num_elements);
2012 }
2013
2014#endif // ifdef _MSC_VER
2015
2016private:
2017
2019 const FastCdr&) = delete;
2020
2021 FastCdr& operator =(
2022 const FastCdr&) = delete;
2023
2024 FastCdr& serialize_bool_sequence(
2025 const std::vector<bool>& vector_t);
2026
2027 FastCdr& deserialize_bool_sequence(
2028 std::vector<bool>& vector_t);
2029
2030 FastCdr& deserialize_string_sequence(
2031 std::string*& sequence_t,
2032 size_t& num_elements);
2033
2034 FastCdr& deserialize_wstring_sequence(
2035 std::wstring*& sequence_t,
2036 size_t& num_elements);
2037
2038 /*!
2039 * @brief This function template detects the content type of the STD container array and serializes the array.
2040 * @param array_t The array that will be serialized in the buffer.
2041 * @param num_elements Number of the elements in the array.
2042 * @return Reference to the eprosima::fastcdr::FastCdr object.
2043 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
2044 */
2045 template<class _T, size_t _Size>
2047 const std::array<_T, _Size>* array_t,
2048 size_t num_elements)
2049 {
2050 return serialize_array(array_t->data(), num_elements * array_t->size());
2051 }
2052
2053 /*!
2054 * @brief This function template detects the content type of the STD container array and deserializes the array.
2055 * @param array_t The variable that will store the array read from the buffer.
2056 * @param num_elements Number of the elements in the array.
2057 * @return Reference to the eprosima::fastcdr::FastCdr object.
2058 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
2059 */
2060 template<class _T, size_t _Size>
2062 std::array<_T, _Size>* array_t,
2063 size_t num_elements)
2064 {
2065 return deserialize_array(array_t->data(), num_elements * array_t->size());
2066 }
2067
2068 bool resize(
2069 size_t min_size_inc);
2070
2071 const char* read_string(
2072 uint32_t& length);
2073
2074 std::wstring read_wstring(
2075 uint32_t& length);
2076
2077 //! @brief Reference to the buffer that will be serialized/deserialized.
2079
2080 //! @brief The current position in the serialization/deserialization process.
2082
2083 //! @brief The last position in the buffer;
2085};
2086} //namespace fastcdr
2087} //namespace eprosima
2088
2089#endif //_FASTCDR_FASTCDR_H_
T assign(T... args)
T c_str(T... args)
This class represents a stream of bytes that contains (or will contain) serialized data....
Definition FastBuffer.h:244
This class stores the current state of a CDR serialization.
Definition FastCdr.h:50
const FastBuffer::iterator current_position_
The position in the buffer when the state was created.
Definition FastCdr.h:73
This class offers an interface to serialize/deserialize some basic types using a modified CDR protoco...
Definition FastCdr.h:43
FastCdr & deserialize_sequence(std::wstring *&sequence_t, size_t &num_elements)
This function template deserializes a wide-string sequence. This function allocates memory to store t...
Definition FastCdr.h:1936
FastCdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
Definition FastCdr.h:1771
FastCdr & deserialize(long double &ldouble_t)
This function deserializes a long double.
Definition FastCdr.h:1492
FastCdr & serialize_array(const std::array< _T, _Size > *array_t, size_t num_elements)
This function template detects the content type of the STD container array and serializes the array.
Definition FastCdr.h:2046
FastBuffer::iterator current_position_
The current position in the serialization/deserialization process.
Definition FastCdr.h:2081
FastCdr & serialize(const _T &type_t)
This function template serializes a non-basic type.
Definition FastCdr.h:994
FastCdr & deserialize(int32_t &long_t)
This function deserializes a long.
Definition FastCdr.h:1379
FastCdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Definition FastCdr.h:1708
FastCdr & serialize(const int16_t short_t)
This function serializes a short.
Definition FastCdr.h:694
FastCdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
Definition FastCdr.h:1400
FastCdr & deserialize_array(std::wstring *string_t, size_t num_elements)
This function deserializes an array of wide-strings.
Definition FastCdr.h:1860
FastCdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wstrings.
Definition FastCdr.h:1202
FastCdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
Definition FastCdr.h:1009
FastCdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
Definition FastCdr.h:681
FastCdr & serialize(const std::string &string_t)
This function serializes a std::string.
Definition FastCdr.h:891
FastCdr & deserialize_array(_T *type_t, size_t num_elements)
This function template deserializes an array of non-basic type objects.
Definition FastCdr.h:1898
FastCdr & deserialize_array(std::string *string_t, size_t num_elements)
This function deserializes an array of strings.
Definition FastCdr.h:1841
FastCdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence.
Definition FastCdr.h:951
FastCdr & serialize(const uint8_t octet_t)
This function serializes an octet.
Definition FastCdr.h:636
FastCdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence. This function allocates memory to store the seque...
Definition FastCdr.h:1953
FastCdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
Definition FastCdr.h:938
FastBuffer::iterator last_position_
The last position in the buffer;.
Definition FastCdr.h:2084
FastCdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Definition FastCdr.h:1550
FastCdr & deserialize(float &float_t)
This function deserializes a float.
Definition FastCdr.h:1450
FastCdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
Definition FastCdr.h:1183
FastBuffer & cdr_buffer_
Reference to the buffer that will be serialized/deserialized.
Definition FastCdr.h:2078
FastCdr & deserialize(char &char_t)
This function deserializes a character.
Definition FastCdr.h:1300
FastCdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence of booleans.
Definition FastCdr.h:1594
FastCdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Definition FastCdr.h:1113
FastCdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
Definition FastCdr.h:1035
FastCdr & deserialize(double &double_t)
This function deserializes a double.
Definition FastCdr.h:1471
FastCdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
Definition FastCdr.h:1366
FastCdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
Definition FastCdr.h:762
FastCdr & serialize_array(const std::vector< _T > *vector_t, size_t num_elements)
This function template serializes an array of sequences.
Definition FastCdr.h:1221
FastCdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
Definition FastCdr.h:715
FastCdr & deserialize_array(std::array< _T, _Size > *array_t, size_t num_elements)
This function template detects the content type of the STD container array and deserializes the array...
Definition FastCdr.h:2061
FastCdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
Definition FastCdr.h:749
FastCdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
Definition FastCdr.h:912
FastCdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Definition FastCdr.h:1287
FastCdr & serialize_array(const _T *type_t, size_t num_elements)
This function template serializes an array of non-basic type objects.
Definition FastCdr.h:1240
FastCdr & serialize(const long double ldouble_t)
This function serializes a long double.
Definition FastCdr.h:838
FastCdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
Definition FastCdr.h:1667
FastCdr & deserialize(int16_t &short_t)
This function deserializes a short.
Definition FastCdr.h:1345
FastCdr & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence.
Definition FastCdr.h:1607
FastCdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
Definition FastCdr.h:925
FastCdr & serialize(const int32_t long_t)
This function serializes a long.
Definition FastCdr.h:728
FastCdr(const FastCdr &)=delete
size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Definition FastCdr.h:107
FastCdr & serialize(const char char_t)
This function serializes a character.
Definition FastCdr.h:649
FastCdr & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
Definition FastCdr.h:1581
FastCdr & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence.
Definition FastCdr.h:1259
FastCdr & deserialize_sequence(std::string *&sequence_t, size_t &num_elements)
This function template deserializes a string sequence. This function allocates memory to store the se...
Definition FastCdr.h:1919
FastCdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
Definition FastCdr.h:1050
FastCdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Definition FastCdr.h:1416
FastCdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
Definition FastCdr.h:1693
FastCdr & serialize(const int64_t longlong_t)
This function serializes a long long.
Definition FastCdr.h:775
FastCdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
Definition FastCdr.h:1734
FastCdr & deserialize(_T &type_t)
This function template deserializes a non-basic type object.
Definition FastCdr.h:1652
FastCdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
Definition FastCdr.h:1332
FastCdr & serialize(const float float_t)
This function serializes a float.
Definition FastCdr.h:796
FastCdr & serialize(const int8_t int8)
This function serializes an int8_t.
Definition FastCdr.h:668
FastCdr & serialize(const double double_t)
This function serializes a double.
Definition FastCdr.h:817
FastCdr & deserialize_array(std::vector< _T > *vector_t, size_t num_elements)
This function template deserializes an array of sequences.
Definition FastCdr.h:1879
FastCdr & deserialize(int64_t &longlong_t)
This function deserializes a long long.
Definition FastCdr.h:1429
FastCdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Definition FastCdr.h:1566
FastCdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Definition FastCdr.h:1319
FastCdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
Definition FastCdr.h:1076
This class implements the iterator used to go through a FastBuffer.
Definition FastBuffer.h:43
This class is thrown as an exception when an invalid parameter is being serialized.
This abstract class is used to create exceptions.
Definition Exception.h:30
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
T data(T... args)
#define Cdr_DllAPI
Definition fastcdr_dll.h:51
void serialize(Cdr &, const _T &)
void deserialize(Cdr &, _T &)
Definition Cdr.h:49
T resize(T... args)
T size(T... args)