/src/Fast-CDR/include/fastcdr/Cdr.h
Line | Count | Source (jump to first uncovered line) |
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_CDR_H_ |
16 | | #define _FASTCDR_CDR_H_ |
17 | | |
18 | | #include "fastcdr_dll.h" |
19 | | #include "FastBuffer.h" |
20 | | #include "exceptions/NotEnoughMemoryException.h" |
21 | | #include <stdint.h> |
22 | | #include <string> |
23 | | #include <vector> |
24 | | #include <map> |
25 | | #include <iostream> |
26 | | |
27 | | #if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ |
28 | | #include <malloc.h> |
29 | | #else |
30 | | #include <stdlib.h> |
31 | | #endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ |
32 | | |
33 | | #if HAVE_CXX0X |
34 | | #include <array> |
35 | | #endif // if HAVE_CXX0X |
36 | | |
37 | | namespace eprosima { |
38 | | namespace fastcdr { |
39 | | /*! |
40 | | * @brief This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an eprosima::fastcdr::FastBuffer. |
41 | | * @ingroup FASTCDRAPIREFERENCE |
42 | | */ |
43 | | class Cdr_DllAPI Cdr |
44 | | { |
45 | | public: |
46 | | |
47 | | //! @brief This enumeration represents the two kinds of CDR serialization supported by eprosima::fastcdr::CDR. |
48 | | typedef enum |
49 | | { |
50 | | //! @brief Common CORBA CDR serialization. |
51 | | CORBA_CDR, |
52 | | //! @brief DDS CDR serialization. |
53 | | DDS_CDR |
54 | | } CdrType; |
55 | | |
56 | | //! @brief This enumeration represents the two posible values of the flag that points if the content is a parameter list (only in DDS CDR). |
57 | | |
58 | | #ifdef HAVE_CXX0X |
59 | | typedef enum : uint8_t |
60 | | #else |
61 | | typedef enum |
62 | | #endif // ifdef HAVE_CXX0X |
63 | | { |
64 | | //! @brief Specifies that the content is not a parameter list. |
65 | | DDS_CDR_WITHOUT_PL = 0x0, |
66 | | //! @brief Specifies that the content is a parameter list. |
67 | | DDS_CDR_WITH_PL = 0x2 |
68 | | } DDSCdrPlFlag; |
69 | | |
70 | | /*! |
71 | | * @brief This enumeration represents endianness types. |
72 | | */ |
73 | | #ifdef HAVE_CXX0X |
74 | | typedef enum : uint8_t |
75 | | #else |
76 | | typedef enum |
77 | | #endif // ifdef HAVE_CXX0X |
78 | | { |
79 | | //! @brief Big endianness. |
80 | | BIG_ENDIANNESS = 0x0, |
81 | | //! @brief Little endianness. |
82 | | LITTLE_ENDIANNESS = 0x1 |
83 | | } Endianness; |
84 | | |
85 | | //! @brief Default endiness in the system. |
86 | | static const Endianness DEFAULT_ENDIAN; |
87 | | |
88 | | /*! |
89 | | * @brief This class stores the current state of a CDR serialization. |
90 | | */ |
91 | | class Cdr_DllAPI state |
92 | | { |
93 | | friend class Cdr; |
94 | | |
95 | | public: |
96 | | |
97 | | /*! |
98 | | * @brief Default constructor. |
99 | | */ |
100 | | state( |
101 | | const Cdr& cdr); |
102 | | |
103 | | /*! |
104 | | * @brief Copy constructor. |
105 | | */ |
106 | | state( |
107 | | const state&); |
108 | | |
109 | | private: |
110 | | |
111 | | state& operator =( |
112 | | const state&) = delete; |
113 | | |
114 | | //! @brief The position in the buffer when the state was created. |
115 | | const FastBuffer::iterator m_currentPosition; |
116 | | |
117 | | //! @brief The position from the aligment is calculated, when the state was created.. |
118 | | const FastBuffer::iterator m_alignPosition; |
119 | | |
120 | | //! @brief This attribute specified if it is needed to swap the bytes when the state was created.. |
121 | | bool m_swapBytes; |
122 | | |
123 | | //! @brief Stores the last datasize serialized/deserialized when the state was created. |
124 | | size_t m_lastDataSize; |
125 | | }; |
126 | | |
127 | | /*! |
128 | | * @brief This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize |
129 | | * the assigned buffer. |
130 | | * |
131 | | * @param cdrBuffer A reference to the buffer that contains (or will contain) the CDR representation. |
132 | | * @param endianness The initial endianness that will be used. The default value is the endianness of the system. |
133 | | * @param cdrType Represents the type of CDR that will be used in serialization/deserialization. The default value is CORBA CDR. |
134 | | */ |
135 | | Cdr( |
136 | | FastBuffer& cdrBuffer, |
137 | | const Endianness endianness = DEFAULT_ENDIAN, |
138 | | const CdrType cdrType = CORBA_CDR); |
139 | | |
140 | | /*! |
141 | | * @brief This function reads the encapsulation of the CDR stream. |
142 | | * If the CDR stream contains an encapsulation, then this function should be called before starting to deserialize. |
143 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
144 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
145 | | * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value. |
146 | | */ |
147 | | Cdr& read_encapsulation(); |
148 | | |
149 | | /*! |
150 | | * @brief This function writes the encapsulation of the CDR stream. |
151 | | * If the CDR stream should contain an encapsulation, then this function should be called before starting to serialize. |
152 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
153 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
154 | | */ |
155 | | Cdr& serialize_encapsulation(); |
156 | | |
157 | | /*! |
158 | | * @brief This function returns the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR. |
159 | | * @return The flag that specifies if the content is a parameter list. |
160 | | */ |
161 | | DDSCdrPlFlag getDDSCdrPlFlag() const; |
162 | | |
163 | | /*! |
164 | | * @brief This function sets the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR. |
165 | | * @param plFlag New value for the flag that specifies if the content is a parameter list. |
166 | | */ |
167 | | void setDDSCdrPlFlag( |
168 | | DDSCdrPlFlag plFlag); |
169 | | |
170 | | /*! |
171 | | * @brief This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR. |
172 | | * @return The option flags. |
173 | | */ |
174 | | uint16_t getDDSCdrOptions() const; |
175 | | |
176 | | /*! |
177 | | * @brief This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR. |
178 | | * @param options New value for the option flags. |
179 | | */ |
180 | | void setDDSCdrOptions( |
181 | | uint16_t options); |
182 | | |
183 | | /*! |
184 | | * @brief This function sets the current endianness used by the CDR type. |
185 | | * @param endianness The new endianness value. |
186 | | */ |
187 | | void changeEndianness( |
188 | | Endianness endianness); |
189 | | |
190 | | /*! |
191 | | * @brief This function returns the current endianness used by the CDR type. |
192 | | * @return The endianness. |
193 | | */ |
194 | | Endianness endianness() const |
195 | 0 | { |
196 | 0 | return static_cast<Endianness>(m_endianness); |
197 | 0 | } |
198 | | |
199 | | /*! |
200 | | * @brief This function skips a number of bytes in the CDR stream buffer. |
201 | | * @param numBytes The number of bytes that will be jumped. |
202 | | * @return True is returned when it works successfully. Otherwise, false is returned. |
203 | | */ |
204 | | bool jump( |
205 | | size_t numBytes); |
206 | | |
207 | | /*! |
208 | | * @brief This function resets the current position in the buffer to the beginning. |
209 | | */ |
210 | | void reset(); |
211 | | |
212 | | /*! |
213 | | * @brief This function returns the pointer to the current used buffer. |
214 | | * @return Pointer to the starting position of the buffer. |
215 | | */ |
216 | | char* getBufferPointer(); |
217 | | |
218 | | /*! |
219 | | * @brief This function returns the current position in the CDR stream. |
220 | | * @return Pointer to the current position in the buffer. |
221 | | */ |
222 | | char* getCurrentPosition(); |
223 | | |
224 | | /*! |
225 | | * @brief This function returns the length of the serialized data inside the stream. |
226 | | * @return The length of the serialized data. |
227 | | */ |
228 | | inline size_t getSerializedDataLength() const |
229 | 0 | { |
230 | 0 | return m_currentPosition - m_cdrBuffer.begin(); |
231 | 0 | } |
232 | | |
233 | | /*! |
234 | | * @brief Get the number of bytes needed to align a position to certain data size. |
235 | | * @param current_alignment Position to be aligned. |
236 | | * @param dataSize Size of next data to process (should be power of two). |
237 | | * @return Number of required alignment bytes. |
238 | | */ |
239 | | inline static size_t alignment( |
240 | | size_t current_alignment, |
241 | | size_t dataSize) |
242 | 0 | { |
243 | 0 | return (dataSize - (current_alignment % dataSize)) & (dataSize - 1); |
244 | 0 | } |
245 | | |
246 | | /*! |
247 | | * @brief This function returns the current state of the CDR serialization process. |
248 | | * @return The current state of the CDR serialization process. |
249 | | */ |
250 | | state getState(); |
251 | | |
252 | | /*! |
253 | | * @brief This function sets a previous state of the CDR serialization process; |
254 | | * @param state Previous state that will be set. |
255 | | */ |
256 | | void setState( |
257 | | state& state); |
258 | | |
259 | | /*! |
260 | | * @brief This function moves the alignment forward. |
261 | | * @param numBytes The number of bytes the alignment should advance. |
262 | | * @return True If alignment was moved successfully. |
263 | | */ |
264 | | bool moveAlignmentForward( |
265 | | size_t numBytes); |
266 | | |
267 | | /*! |
268 | | * @brief This function resets the alignment to the current position in the buffer. |
269 | | */ |
270 | | inline void resetAlignment() |
271 | 0 | { |
272 | 0 | m_alignPosition = m_currentPosition; |
273 | 0 | } |
274 | | |
275 | | /*! |
276 | | * @brief This operator serializes an octet. |
277 | | * @param octet_t The value of the octet that will be serialized in the buffer. |
278 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
279 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
280 | | */ |
281 | | inline Cdr& operator <<( |
282 | | const uint8_t octet_t) |
283 | 0 | { |
284 | 0 | return serialize(octet_t); |
285 | 0 | } |
286 | | |
287 | | /*! |
288 | | * @brief This operator serializes a character. |
289 | | * @param char_t The value of the character that will be serialized in the buffer. |
290 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
291 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
292 | | */ |
293 | | inline Cdr& operator <<( |
294 | | const char char_t) |
295 | 0 | { |
296 | 0 | return serialize(char_t); |
297 | 0 | } |
298 | | |
299 | | /*! |
300 | | * @brief This operator serializes a int8_t. |
301 | | * @param int8 The value of the int8_t that will be serialized in the buffer. |
302 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
303 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
304 | | */ |
305 | | inline Cdr& operator <<( |
306 | | const int8_t int8) |
307 | 0 | { |
308 | 0 | return serialize(int8); |
309 | 0 | } |
310 | | |
311 | | /*! |
312 | | * @brief This operator serializes an unsigned short. |
313 | | * @param ushort_t The value of the unsigned short that will be serialized in the buffer. |
314 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
315 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
316 | | */ |
317 | | inline Cdr& operator <<( |
318 | | const uint16_t ushort_t) |
319 | 0 | { |
320 | 0 | return serialize(ushort_t); |
321 | 0 | } |
322 | | |
323 | | /*! |
324 | | * @brief This operator serializes a short. |
325 | | * @param short_t The value of the short that will be serialized in the buffer. |
326 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
327 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
328 | | */ |
329 | | inline Cdr& operator <<( |
330 | | const int16_t short_t) |
331 | 0 | { |
332 | 0 | return serialize(short_t); |
333 | 0 | } |
334 | | |
335 | | /*! |
336 | | * @brief This operator serializes an unsigned long. |
337 | | * @param ulong_t The value of the unsigned long that will be serialized in the buffer. |
338 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
339 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
340 | | */ |
341 | | inline Cdr& operator <<( |
342 | | const uint32_t ulong_t) |
343 | 0 | { |
344 | 0 | return serialize(ulong_t); |
345 | 0 | } |
346 | | |
347 | | /*! |
348 | | * @brief This operator serializes a long. |
349 | | * @param long_t The value of the long that will be serialized in the buffer. |
350 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
351 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
352 | | */ |
353 | | inline Cdr& operator <<( |
354 | | const int32_t long_t) |
355 | 0 | { |
356 | 0 | return serialize(long_t); |
357 | 0 | } |
358 | | |
359 | | /*! |
360 | | * @brief This operator serializes a wide-char. |
361 | | * @param wchar The value of the wide-char that will be serialized in the buffer. |
362 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
363 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
364 | | */ |
365 | | inline Cdr& operator <<( |
366 | | const wchar_t wchar) |
367 | 0 | { |
368 | 0 | return serialize(wchar); |
369 | 0 | } |
370 | | |
371 | | /*! |
372 | | * @brief This operator serializes an unsigned long long. |
373 | | * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer. |
374 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
375 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
376 | | */ |
377 | | inline Cdr& operator <<( |
378 | | const uint64_t ulonglong_t) |
379 | 0 | { |
380 | 0 | return serialize(ulonglong_t); |
381 | 0 | } |
382 | | |
383 | | /*! |
384 | | * @brief This operator serializes a long long. |
385 | | * @param longlong_t The value of the long long that will be serialized in the buffer. |
386 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
387 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
388 | | */ |
389 | | inline Cdr& operator <<( |
390 | | const int64_t longlong_t) |
391 | 0 | { |
392 | 0 | return serialize(longlong_t); |
393 | 0 | } |
394 | | |
395 | | /*! |
396 | | * @brief This operator serializes a float. |
397 | | * @param float_t The value of the float that will be serialized in the buffer. |
398 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
399 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
400 | | */ |
401 | | inline Cdr& operator <<( |
402 | | const float float_t) |
403 | 0 | { |
404 | 0 | return serialize(float_t); |
405 | 0 | } |
406 | | |
407 | | /*! |
408 | | * @brief This operator serializes a double. |
409 | | * @param double_t The value of the double that will be serialized in the buffer. |
410 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
411 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
412 | | */ |
413 | | inline Cdr& operator <<( |
414 | | const double double_t) |
415 | 0 | { |
416 | 0 | return serialize(double_t); |
417 | 0 | } |
418 | | |
419 | | /*! |
420 | | * @brief This operator serializes a long double. |
421 | | * @param ldouble_t The value of the long double that will be serialized in the buffer. |
422 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
423 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
424 | | */ |
425 | | inline Cdr& operator <<( |
426 | | const long double ldouble_t) |
427 | 0 | { |
428 | 0 | return serialize(ldouble_t); |
429 | 0 | } |
430 | | |
431 | | /*! |
432 | | * @brief This operator serializes a boolean. |
433 | | * @param bool_t The value of the boolean that will be serialized in the buffer. |
434 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
435 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
436 | | */ |
437 | | inline Cdr& operator <<( |
438 | | const bool bool_t) |
439 | 0 | { |
440 | 0 | return serialize(bool_t); |
441 | 0 | } |
442 | | |
443 | | /*! |
444 | | * @brief This operator serializes a null-terminated c-string. |
445 | | * @param string_t Pointer to the begining of the string that will be serialized in the buffer. |
446 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
447 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
448 | | */ |
449 | | inline Cdr& operator <<( |
450 | | const char* string_t) |
451 | 0 | { |
452 | 0 | return serialize(string_t); |
453 | 0 | } |
454 | | |
455 | | /*! |
456 | | * @brief This operator serializes a null-terminated c-string. |
457 | | * @param string_t Pointer to the begining of the string that will be serialized in the buffer. |
458 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
459 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
460 | | */ |
461 | | inline Cdr& operator <<( |
462 | | char* string_t) |
463 | 0 | { |
464 | 0 | return serialize(string_t); |
465 | 0 | } |
466 | | |
467 | | /*! |
468 | | * @brief This operator serializes a string. |
469 | | * @param string_t The string that will be serialized in the buffer. |
470 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
471 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
472 | | */ |
473 | | inline Cdr& operator <<( |
474 | | const std::string& string_t) |
475 | 0 | { |
476 | 0 | return serialize(string_t); |
477 | 0 | } |
478 | | |
479 | | /*! |
480 | | * @brief This operator serializes a wstring. |
481 | | * @param string_t The wstring that will be serialized in the buffer. |
482 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
483 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
484 | | */ |
485 | | inline Cdr& operator <<( |
486 | | const std::wstring& string_t) |
487 | 0 | { |
488 | 0 | return serialize(string_t); |
489 | 0 | } |
490 | | |
491 | | #if HAVE_CXX0X |
492 | | /*! |
493 | | * @brief This operator template is used to serialize arrays. |
494 | | * @param array_t The array that will be serialized in the buffer. |
495 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
496 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
497 | | */ |
498 | | template<class _T, size_t _Size> |
499 | | inline Cdr& operator <<( |
500 | | const std::array<_T, _Size>& array_t) |
501 | | { |
502 | | return serialize<_T, _Size>(array_t); |
503 | | } |
504 | | |
505 | | #endif // if HAVE_CXX0X |
506 | | |
507 | | /*! |
508 | | * @brief This operator template is used to serialize sequences. |
509 | | * @param vector_t The sequence that will be serialized in the buffer. |
510 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
511 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
512 | | */ |
513 | | template<class _T> |
514 | | inline Cdr& operator <<( |
515 | | const std::vector<_T>& vector_t) |
516 | | { |
517 | | return serialize<_T>(vector_t); |
518 | | } |
519 | | |
520 | | /*! |
521 | | * @brief This operator template is used to serialize maps. |
522 | | * @param map_t The map that will be serialized in the buffer. |
523 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
524 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
525 | | */ |
526 | | template<class _K, class _T> |
527 | | inline Cdr& operator <<( |
528 | | const std::map<_K, _T>& map_t) |
529 | | { |
530 | | return serialize<_K, _T>(map_t); |
531 | | } |
532 | | |
533 | | /*! |
534 | | * @brief This operator template is used to serialize any other non-basic type. |
535 | | * @param type_t A reference to the object that will be serialized in the buffer. |
536 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
537 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
538 | | */ |
539 | | template<class _T> |
540 | | inline Cdr& operator <<( |
541 | | const _T& type_t) |
542 | | { |
543 | | type_t.serialize(*this); |
544 | | return *this; |
545 | | } |
546 | | |
547 | | /*! |
548 | | * @brief This operator deserializes an octet. |
549 | | * @param octet_t The variable that will store the octet read from the buffer. |
550 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
551 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
552 | | */ |
553 | | inline Cdr& operator >>( |
554 | | uint8_t& octet_t) |
555 | 0 | { |
556 | 0 | return deserialize(octet_t); |
557 | 0 | } |
558 | | |
559 | | /*! |
560 | | * @brief This operator deserializes a character. |
561 | | * @param char_t The variable that will store the character read from the buffer. |
562 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
563 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
564 | | */ |
565 | | inline Cdr& operator >>( |
566 | | char& char_t) |
567 | 0 | { |
568 | 0 | return deserialize(char_t); |
569 | 0 | } |
570 | | |
571 | | /*! |
572 | | * @brief This operator deserializes a int8_t. |
573 | | * @param int8 The variable that will store the int8_t read from the buffer. |
574 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
575 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
576 | | */ |
577 | | inline Cdr& operator >>( |
578 | | int8_t& int8) |
579 | 0 | { |
580 | 0 | return deserialize(int8); |
581 | 0 | } |
582 | | |
583 | | /*! |
584 | | * @brief This operator deserializes an unsigned short. |
585 | | * @param ushort_t The variable that will store the unsigned short read from the buffer. |
586 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
587 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
588 | | */ |
589 | | inline Cdr& operator >>( |
590 | | uint16_t& ushort_t) |
591 | 0 | { |
592 | 0 | return deserialize(ushort_t); |
593 | 0 | } |
594 | | |
595 | | /*! |
596 | | * @brief This operator deserializes a short. |
597 | | * @param short_t The variable that will store the short read from the buffer. |
598 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
599 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
600 | | */ |
601 | | inline Cdr& operator >>( |
602 | | int16_t& short_t) |
603 | 0 | { |
604 | 0 | return deserialize(short_t); |
605 | 0 | } |
606 | | |
607 | | /*! |
608 | | * @brief This operator deserializes an unsigned long. |
609 | | * @param ulong_t The variable that will store the unsigned long read from the buffer. |
610 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
611 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
612 | | */ |
613 | | inline Cdr& operator >>( |
614 | | uint32_t& ulong_t) |
615 | 0 | { |
616 | 0 | return deserialize(ulong_t); |
617 | 0 | } |
618 | | |
619 | | /*! |
620 | | * @brief This operator deserializes a long. |
621 | | * @param long_t The variable that will store the long read from the buffer. |
622 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
623 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
624 | | */ |
625 | | inline Cdr& operator >>( |
626 | | int32_t& long_t) |
627 | 0 | { |
628 | 0 | return deserialize(long_t); |
629 | 0 | } |
630 | | |
631 | | // TODO in FastCdr |
632 | | /*! |
633 | | * @brief This operator deserializes a wide-char. |
634 | | * @param wchar The variable that will store the wide-char read from the buffer. |
635 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
636 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
637 | | */ |
638 | | inline Cdr& operator >>( |
639 | | wchar_t& wchar) |
640 | 0 | { |
641 | 0 | return deserialize(wchar); |
642 | 0 | } |
643 | | |
644 | | /*! |
645 | | * @brief This operator deserializes a unsigned long long. |
646 | | * @param ulonglong_t The variable that will store the unsigned long long read from the buffer. |
647 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
648 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
649 | | */ |
650 | | inline Cdr& operator >>( |
651 | | uint64_t& ulonglong_t) |
652 | 0 | { |
653 | 0 | return deserialize(ulonglong_t); |
654 | 0 | } |
655 | | |
656 | | /*! |
657 | | * @brief This operator deserializes a long long. |
658 | | * @param longlong_t The variable that will store the long long read from the buffer. |
659 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
660 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
661 | | */ |
662 | | inline Cdr& operator >>( |
663 | | int64_t& longlong_t) |
664 | 0 | { |
665 | 0 | return deserialize(longlong_t); |
666 | 0 | } |
667 | | |
668 | | /*! |
669 | | * @brief This operator deserializes a float. |
670 | | * @param float_t The variable that will store the float read from the buffer. |
671 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
672 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
673 | | */ |
674 | | inline Cdr& operator >>( |
675 | | float& float_t) |
676 | 0 | { |
677 | 0 | return deserialize(float_t); |
678 | 0 | } |
679 | | |
680 | | /*! |
681 | | * @brief This operator deserializes a double. |
682 | | * @param double_t The variable that will store the double read from the buffer. |
683 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
684 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
685 | | */ |
686 | | inline Cdr& operator >>( |
687 | | double& double_t) |
688 | 0 | { |
689 | 0 | return deserialize(double_t); |
690 | 0 | } |
691 | | |
692 | | /*! |
693 | | * @brief This operator deserializes a long double. |
694 | | * @param ldouble_t The variable that will store the long double read from the buffer. |
695 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
696 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
697 | | */ |
698 | | inline Cdr& operator >>( |
699 | | long double& ldouble_t) |
700 | 0 | { |
701 | 0 | return deserialize(ldouble_t); |
702 | 0 | } |
703 | | |
704 | | /*! |
705 | | * @brief This operator deserializes a boolean. |
706 | | * @param bool_t The variable that will store the boolean read from the buffer. |
707 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
708 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
709 | | * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value. |
710 | | */ |
711 | | inline Cdr& operator >>( |
712 | | bool& bool_t) |
713 | 0 | { |
714 | 0 | return deserialize(bool_t); |
715 | 0 | } |
716 | | |
717 | | /*! |
718 | | * @brief This operator deserializes a null-terminated c-string. |
719 | | * @param string_t The variable that will store the c-string read from the buffer. |
720 | | * Please note that a newly allocated string will be returned. |
721 | | * The caller should free the returned pointer when appropiate. |
722 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
723 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
724 | | * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value. |
725 | | */ |
726 | | inline Cdr& operator >>( |
727 | | char*& string_t) |
728 | 0 | { |
729 | 0 | return deserialize(string_t); |
730 | 0 | } |
731 | | |
732 | | /*! |
733 | | * @brief This operator deserializes a string. |
734 | | * @param string_t The variable that will store the string read from the buffer. |
735 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
736 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
737 | | */ |
738 | | inline Cdr& operator >>( |
739 | | std::string& string_t) |
740 | 0 | { |
741 | 0 | return deserialize(string_t); |
742 | 0 | } |
743 | | |
744 | | /*! |
745 | | * @brief This operator deserializes a string. |
746 | | * @param string_t The variable that will store the string read from the buffer. |
747 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
748 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
749 | | */ |
750 | | inline Cdr& operator >>( |
751 | | std::wstring& string_t) |
752 | 0 | { |
753 | 0 | return deserialize(string_t); |
754 | 0 | } |
755 | | |
756 | | #if HAVE_CXX0X |
757 | | /*! |
758 | | * @brief This operator template is used to deserialize arrays. |
759 | | * @param array_t The variable that will store the array read from the buffer. |
760 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
761 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
762 | | */ |
763 | | template<class _T, size_t _Size> |
764 | | inline Cdr& operator >>( |
765 | | std::array<_T, _Size>& array_t) |
766 | | { |
767 | | return deserialize<_T, _Size>(array_t); |
768 | | } |
769 | | |
770 | | #endif // if HAVE_CXX0X |
771 | | |
772 | | /*! |
773 | | * @brief This operator template is used to deserialize sequences. |
774 | | * @param vector_t The variable that will store the sequence read from the buffer. |
775 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
776 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
777 | | */ |
778 | | template<class _T> |
779 | | inline Cdr& operator >>( |
780 | | std::vector<_T>& vector_t) |
781 | | { |
782 | | return deserialize<_T>(vector_t); |
783 | | } |
784 | | |
785 | | /*! |
786 | | * @brief This operator template is used to deserialize maps. |
787 | | * @param map_t The variable that will store the map read from the buffer. |
788 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
789 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
790 | | */ |
791 | | template<class _K, class _T> |
792 | | inline Cdr& operator >>( |
793 | | std::map<_K, _T>& map_t) |
794 | | { |
795 | | return deserialize<_K, _T>(map_t); |
796 | | } |
797 | | |
798 | | /*! |
799 | | * @brief This operator template is used to deserialize any other non-basic type. |
800 | | * @param type_t The variable that will store the object read from the buffer. |
801 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
802 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
803 | | */ |
804 | | template<class _T> |
805 | | inline Cdr& operator >>( |
806 | | _T& type_t) |
807 | | { |
808 | | type_t.deserialize(*this); |
809 | | return *this; |
810 | | } |
811 | | |
812 | | /*! |
813 | | * @brief This function serializes an octet. |
814 | | * @param octet_t The value of the octet that will be serialized in the buffer. |
815 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
816 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
817 | | */ |
818 | | inline |
819 | | Cdr& serialize( |
820 | | const uint8_t octet_t) |
821 | 0 | { |
822 | 0 | return serialize(static_cast<char>(octet_t)); |
823 | 0 | } |
824 | | |
825 | | /*! |
826 | | * @brief This function serializes an octet with a different endianness. |
827 | | * @param octet_t The value of the octet that will be serialized in the buffer. |
828 | | * @param endianness Endianness that will be used in the serialization of this value. |
829 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
830 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
831 | | */ |
832 | | inline |
833 | | Cdr& serialize( |
834 | | const uint8_t octet_t, |
835 | | Endianness endianness) |
836 | 0 | { |
837 | 0 | return serialize(static_cast<char>(octet_t), endianness); |
838 | 0 | } |
839 | | |
840 | | /*! |
841 | | * @brief This function serializes a character. |
842 | | * @param char_t The value of the character that will be serialized in the buffer. |
843 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
844 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
845 | | */ |
846 | | Cdr& serialize( |
847 | | const char char_t); |
848 | | |
849 | | /*! |
850 | | * @brief This function serializes a character with a different endianness. |
851 | | * @param char_t The value of the character that will be serialized in the buffer. |
852 | | * @param endianness Endianness that will be used in the serialization of this value. |
853 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
854 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
855 | | */ |
856 | | inline |
857 | | Cdr& serialize( |
858 | | const char char_t, |
859 | | Endianness endianness) |
860 | 0 | { |
861 | 0 | (void) endianness; |
862 | 0 | return serialize(char_t); |
863 | 0 | } |
864 | | |
865 | | /*! |
866 | | * @brief This function serializes an int8_t. |
867 | | * @param int8 The value of the int8_t that will be serialized in the buffer. |
868 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
869 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
870 | | */ |
871 | | inline |
872 | | Cdr& serialize( |
873 | | const int8_t int8) |
874 | 0 | { |
875 | 0 | return serialize(static_cast<char>(int8)); |
876 | 0 | } |
877 | | |
878 | | /*! |
879 | | * @brief This function serializes an int8_t with a different endianness. |
880 | | * @param int8 The value of the int8_t that will be serialized in the buffer. |
881 | | * @param endianness Endianness that will be used in the serialization of this value. |
882 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
883 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
884 | | */ |
885 | | inline |
886 | | Cdr& serialize( |
887 | | const int8_t int8, |
888 | | Endianness endianness) |
889 | 0 | { |
890 | 0 | return serialize(static_cast<char>(int8), endianness); |
891 | 0 | } |
892 | | |
893 | | /*! |
894 | | * @brief This function serializes an unsigned short. |
895 | | * @param ushort_t The value of the unsigned short that will be serialized in the buffer. |
896 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
897 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
898 | | */ |
899 | | inline |
900 | | Cdr& serialize( |
901 | | const uint16_t ushort_t) |
902 | 0 | { |
903 | 0 | return serialize(static_cast<int16_t>(ushort_t)); |
904 | 0 | } |
905 | | |
906 | | /*! |
907 | | * @brief This function serializes an unsigned short with a different endianness. |
908 | | * @param ushort_t The value of the unsigned short that will be serialized in the buffer. |
909 | | * @param endianness Endianness that will be used in the serialization of this value. |
910 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
911 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
912 | | */ |
913 | | inline |
914 | | Cdr& serialize( |
915 | | const uint16_t ushort_t, |
916 | | Endianness endianness) |
917 | 0 | { |
918 | 0 | return serialize(static_cast<int16_t>(ushort_t), endianness); |
919 | 0 | } |
920 | | |
921 | | /*! |
922 | | * @brief This function serializes a short. |
923 | | * @param short_t The value of the short that will be serialized in the buffer. |
924 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
925 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
926 | | */ |
927 | | Cdr& serialize( |
928 | | const int16_t short_t); |
929 | | |
930 | | /*! |
931 | | * @brief This function serializes a short with a different endianness. |
932 | | * @param short_t The value of the short that will be serialized in the buffer. |
933 | | * @param endianness Endianness that will be used in the serialization of this value. |
934 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
935 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
936 | | */ |
937 | | Cdr& serialize( |
938 | | const int16_t short_t, |
939 | | Endianness endianness); |
940 | | |
941 | | /*! |
942 | | * @brief This function serializes an unsigned long. |
943 | | * @param ulong_t The value of the unsigned long that will be serialized in the buffer. |
944 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
945 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
946 | | */ |
947 | | inline |
948 | | Cdr& serialize( |
949 | | const uint32_t ulong_t) |
950 | 0 | { |
951 | 0 | return serialize(static_cast<int32_t>(ulong_t)); |
952 | 0 | } |
953 | | |
954 | | /*! |
955 | | * @brief This function serializes an unsigned long with a different endianness. |
956 | | * @param ulong_t The value of the unsigned long that will be serialized in the buffer. |
957 | | * @param endianness Endianness that will be used in the serialization of this value. |
958 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
959 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
960 | | */ |
961 | | inline |
962 | | Cdr& serialize( |
963 | | const uint32_t ulong_t, |
964 | | Endianness endianness) |
965 | 0 | { |
966 | 0 | return serialize(static_cast<int32_t>(ulong_t), endianness); |
967 | 0 | } |
968 | | |
969 | | /*! |
970 | | * @brief This function serializes a long. |
971 | | * @param long_t The value of the long that will be serialized in the buffer. |
972 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
973 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
974 | | */ |
975 | | Cdr& serialize( |
976 | | const int32_t long_t); |
977 | | |
978 | | /*! |
979 | | * @brief This function serializes a long with a different endianness. |
980 | | * @param long_t The value of the long that will be serialized in the buffer. |
981 | | * @param endianness Endianness that will be used in the serialization of this value. |
982 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
983 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
984 | | */ |
985 | | Cdr& serialize( |
986 | | const int32_t long_t, |
987 | | Endianness endianness); |
988 | | |
989 | | /*! |
990 | | * @brief This function serializes a wide-char. |
991 | | * @param wchar The value of the wide-char that will be serialized in the buffer. |
992 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
993 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
994 | | */ |
995 | | inline |
996 | | Cdr& serialize( |
997 | | const wchar_t wchar) |
998 | 0 | { |
999 | 0 | return serialize(static_cast<uint32_t>(wchar)); |
1000 | 0 | } |
1001 | | |
1002 | | /*! |
1003 | | * @brief This function serializes a wide-char with a different endianness. |
1004 | | * @param wchar The value of the wide-char that will be serialized in the buffer. |
1005 | | * @param endianness Endianness that will be used in the serialization of this value. |
1006 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1007 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1008 | | */ |
1009 | | inline |
1010 | | Cdr& serialize( |
1011 | | const wchar_t wchar, |
1012 | | Endianness endianness) |
1013 | 0 | { |
1014 | 0 | return serialize(static_cast<uint32_t>(wchar), endianness); |
1015 | 0 | } |
1016 | | |
1017 | | /*! |
1018 | | * @brief This function serializes an unsigned long long. |
1019 | | * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer. |
1020 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1021 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1022 | | */ |
1023 | | inline |
1024 | | Cdr& serialize( |
1025 | | const uint64_t ulonglong_t) |
1026 | 0 | { |
1027 | 0 | return serialize(static_cast<int64_t>(ulonglong_t)); |
1028 | 0 | } |
1029 | | |
1030 | | /*! |
1031 | | * @brief This function serializes an unsigned long long with a different endianness. |
1032 | | * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer. |
1033 | | * @param endianness Endianness that will be used in the serialization of this value. |
1034 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1035 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1036 | | */ |
1037 | | inline |
1038 | | Cdr& serialize( |
1039 | | const uint64_t ulonglong_t, |
1040 | | Endianness endianness) |
1041 | 0 | { |
1042 | 0 | return serialize(static_cast<int64_t>(ulonglong_t), endianness); |
1043 | 0 | } |
1044 | | |
1045 | | /*! |
1046 | | * @brief This function serializes a long long. |
1047 | | * @param longlong_t The value of the long long that will be serialized in the buffer. |
1048 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1049 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1050 | | */ |
1051 | | Cdr& serialize( |
1052 | | const int64_t longlong_t); |
1053 | | |
1054 | | /*! |
1055 | | * @brief This function serializes a long long with a different endianness. |
1056 | | * @param longlong_t The value of the long long that will be serialized in the buffer. |
1057 | | * @param endianness Endianness that will be used in the serialization of this value. |
1058 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1059 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1060 | | */ |
1061 | | Cdr& serialize( |
1062 | | const int64_t longlong_t, |
1063 | | Endianness endianness); |
1064 | | |
1065 | | /*! |
1066 | | * @brief This function serializes a float. |
1067 | | * @param float_t The value of the float that will be serialized in the buffer. |
1068 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1069 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1070 | | */ |
1071 | | Cdr& serialize( |
1072 | | const float float_t); |
1073 | | |
1074 | | /*! |
1075 | | * @brief This function serializes a float with a different endianness. |
1076 | | * @param float_t The value of the float that will be serialized in the buffer. |
1077 | | * @param endianness Endianness that will be used in the serialization of this value. |
1078 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1079 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1080 | | */ |
1081 | | Cdr& serialize( |
1082 | | const float float_t, |
1083 | | Endianness endianness); |
1084 | | |
1085 | | /*! |
1086 | | * @brief This function serializes a double. |
1087 | | * @param double_t The value of the double that will be serialized in the buffer. |
1088 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1089 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1090 | | */ |
1091 | | Cdr& serialize( |
1092 | | const double double_t); |
1093 | | |
1094 | | /*! |
1095 | | * @brief This function serializes a double with a different endianness. |
1096 | | * @param double_t The value of the double that will be serialized in the buffer. |
1097 | | * @param endianness Endianness that will be used in the serialization of this value. |
1098 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1099 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1100 | | */ |
1101 | | Cdr& serialize( |
1102 | | const double double_t, |
1103 | | Endianness endianness); |
1104 | | |
1105 | | |
1106 | | /*! |
1107 | | * @brief This function serializes a long double. |
1108 | | * @param ldouble_t The value of the long double that will be serialized in the buffer. |
1109 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1110 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1111 | | * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible. |
1112 | | */ |
1113 | | Cdr& serialize( |
1114 | | const long double ldouble_t); |
1115 | | |
1116 | | /*! |
1117 | | * @brief This function serializes a long double with a different endianness. |
1118 | | * @param ldouble_t The value of the long double that will be serialized in the buffer. |
1119 | | * @param endianness Endianness that will be used in the serialization of this value. |
1120 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1121 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1122 | | * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible. |
1123 | | */ |
1124 | | Cdr& serialize( |
1125 | | const long double ldouble_t, |
1126 | | Endianness endianness); |
1127 | | |
1128 | | /*! |
1129 | | * @brief This function serializes a boolean. |
1130 | | * @param bool_t The value of the boolean that will be serialized in the buffer. |
1131 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1132 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1133 | | */ |
1134 | | Cdr& serialize( |
1135 | | const bool bool_t); |
1136 | | |
1137 | | /*! |
1138 | | * @brief This function serializes a boolean with a different endianness. |
1139 | | * @param bool_t The value of the boolean that will be serialized in the buffer. |
1140 | | * @param endianness Endianness that will be used in the serialization of this value. |
1141 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1142 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1143 | | */ |
1144 | | inline |
1145 | | Cdr& serialize( |
1146 | | const bool bool_t, |
1147 | | Endianness endianness) |
1148 | 0 | { |
1149 | 0 | (void) endianness; |
1150 | 0 | return serialize(bool_t); |
1151 | 0 | } |
1152 | | |
1153 | | /*! |
1154 | | * @brief This function serializes a string. |
1155 | | * @param string_t The pointer to the string that will be serialized in the buffer. |
1156 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1157 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1158 | | */ |
1159 | | inline Cdr& serialize( |
1160 | | char* string_t) |
1161 | 0 | { |
1162 | 0 | return serialize(static_cast<const char*>(string_t)); |
1163 | 0 | } |
1164 | | |
1165 | | /*! |
1166 | | * @brief This function serializes a string. |
1167 | | * @param string_t The pointer to the string that will be serialized in the buffer. |
1168 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1169 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1170 | | */ |
1171 | | Cdr& serialize( |
1172 | | const char* string_t); |
1173 | | |
1174 | | /*! |
1175 | | * @brief This function serializes a wstring. |
1176 | | * @param string_t The pointer to the wstring that will be serialized in the buffer. |
1177 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1178 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1179 | | */ |
1180 | | Cdr& serialize( |
1181 | | const wchar_t* string_t); |
1182 | | |
1183 | | /*! |
1184 | | * @brief This function serializes a string with a different endianness. |
1185 | | * @param string_t The pointer to the string that will be serialized in the buffer. |
1186 | | * @param endianness Endianness that will be used in the serialization of this value. |
1187 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1188 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1189 | | */ |
1190 | | Cdr& serialize( |
1191 | | const char* string_t, |
1192 | | Endianness endianness); |
1193 | | |
1194 | | /*! |
1195 | | * @brief This function serializes a wstring with a different endianness. |
1196 | | * @param string_t The pointer to the wstring that will be serialized in the buffer. |
1197 | | * @param endianness Endianness that will be used in the serialization of this value. |
1198 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1199 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1200 | | */ |
1201 | | Cdr& serialize( |
1202 | | const wchar_t* string_t, |
1203 | | Endianness endianness); |
1204 | | |
1205 | | /*! |
1206 | | * @brief This function serializes a std::string. |
1207 | | * @param string_t The string that will be serialized in the buffer. |
1208 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1209 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1210 | | */ |
1211 | | inline |
1212 | | Cdr& serialize( |
1213 | | const std::string& string_t) |
1214 | 0 | { |
1215 | 0 | return serialize(string_t.c_str()); |
1216 | 0 | } |
1217 | | |
1218 | | /*! |
1219 | | * @brief This function serializes a std::wstring. |
1220 | | * @param string_t The wstring that will be serialized in the buffer. |
1221 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1222 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1223 | | */ |
1224 | | inline |
1225 | | Cdr& serialize( |
1226 | | const std::wstring& string_t) |
1227 | 0 | { |
1228 | 0 | return serialize(string_t.c_str()); |
1229 | 0 | } |
1230 | | |
1231 | | /*! |
1232 | | * @brief This function serializes a std::string with a different endianness. |
1233 | | * @param string_t The string that will be serialized in the buffer. |
1234 | | * @param endianness Endianness that will be used in the serialization of this value. |
1235 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1236 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1237 | | */ |
1238 | | inline |
1239 | | Cdr& serialize( |
1240 | | const std::string& string_t, |
1241 | | Endianness endianness) |
1242 | 0 | { |
1243 | 0 | return serialize(string_t.c_str(), endianness); |
1244 | 0 | } |
1245 | | |
1246 | | #if HAVE_CXX0X |
1247 | | /*! |
1248 | | * @brief This function template serializes an array. |
1249 | | * @param array_t The array that will be serialized in the buffer. |
1250 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1251 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1252 | | */ |
1253 | | template<class _T, size_t _Size> |
1254 | | inline Cdr& serialize( |
1255 | | const std::array<_T, _Size>& array_t) |
1256 | | { |
1257 | | return serializeArray(array_t.data(), array_t.size()); |
1258 | | } |
1259 | | |
1260 | | /*! |
1261 | | * @brief This function template serializes an array with a different endianness. |
1262 | | * @param array_t The array that will be serialized in the buffer. |
1263 | | * @param endianness Endianness that will be used in the serialization of this value. |
1264 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1265 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1266 | | */ |
1267 | | template<class _T, size_t _Size> |
1268 | | inline Cdr& serialize( |
1269 | | const std::array<_T, _Size>& array_t, |
1270 | | Endianness endianness) |
1271 | | { |
1272 | | return serializeArray(array_t.data(), array_t.size(), endianness); |
1273 | | } |
1274 | | |
1275 | | #endif // if HAVE_CXX0X |
1276 | | |
1277 | | #if !defined(_MSC_VER) && HAVE_CXX0X |
1278 | | /*! |
1279 | | * @brief This function template serializes a sequence of booleans. |
1280 | | * @param vector_t The sequence that will be serialized in the buffer. |
1281 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1282 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1283 | | */ |
1284 | | template<class _T = bool> |
1285 | | Cdr& serialize( |
1286 | | const std::vector<bool>& vector_t) |
1287 | | { |
1288 | | return serializeBoolSequence(vector_t); |
1289 | | } |
1290 | | |
1291 | | #endif // if !defined(_MSC_VER) && HAVE_CXX0X |
1292 | | |
1293 | | /*! |
1294 | | * @brief This function template serializes a sequence. |
1295 | | * @param vector_t The sequence that will be serialized in the buffer. |
1296 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1297 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1298 | | */ |
1299 | | template<class _T> |
1300 | | Cdr& serialize( |
1301 | | const std::vector<_T>& vector_t) |
1302 | | { |
1303 | | state state_before_error(*this); |
1304 | | |
1305 | | *this << static_cast<int32_t>(vector_t.size()); |
1306 | | |
1307 | | try |
1308 | | { |
1309 | | return serializeArray(vector_t.data(), vector_t.size()); |
1310 | | } |
1311 | | catch (eprosima::fastcdr::exception::Exception& ex) |
1312 | | { |
1313 | | setState(state_before_error); |
1314 | | ex.raise(); |
1315 | | } |
1316 | | |
1317 | | return *this; |
1318 | | } |
1319 | | |
1320 | | /*! |
1321 | | * @brief This function template serializes a map. |
1322 | | * @param map_t The map that will be serialized in the buffer. |
1323 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1324 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1325 | | */ |
1326 | | template<class _K, class _T> |
1327 | | Cdr& serialize( |
1328 | | const std::map<_K, _T>& map_t) |
1329 | | { |
1330 | | state state_(*this); |
1331 | | |
1332 | | *this << static_cast<int32_t>(map_t.size()); |
1333 | | |
1334 | | try |
1335 | | { |
1336 | | for (auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair) |
1337 | | { |
1338 | | *this << it_pair->first; |
1339 | | *this << it_pair->second; |
1340 | | } |
1341 | | //return serializeArray(map_t.data(), map_t.size()); |
1342 | | } |
1343 | | catch (eprosima::fastcdr::exception::Exception& ex) |
1344 | | { |
1345 | | setState(state_); |
1346 | | ex.raise(); |
1347 | | } |
1348 | | |
1349 | | return *this; |
1350 | | } |
1351 | | |
1352 | | #ifdef _MSC_VER |
1353 | | /*! |
1354 | | * @brief This function template serializes a sequence of booleans. |
1355 | | * @param vector_t The sequence that will be serialized in the buffer. |
1356 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1357 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1358 | | */ |
1359 | | template<> |
1360 | | Cdr& serialize<bool>( |
1361 | | const std::vector<bool>& vector_t) |
1362 | | { |
1363 | | return serializeBoolSequence(vector_t); |
1364 | | } |
1365 | | |
1366 | | #endif // ifdef _MSC_VER |
1367 | | |
1368 | | /*! |
1369 | | * @brief This function template serializes a sequence with a different endianness. |
1370 | | * @param vector_t The sequence that will be serialized in the buffer. |
1371 | | * @param endianness Endianness that will be used in the serialization of this value. |
1372 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1373 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1374 | | */ |
1375 | | template<class _T> |
1376 | | Cdr& serialize( |
1377 | | const std::vector<_T>& vector_t, |
1378 | | Endianness endianness) |
1379 | | { |
1380 | | bool auxSwap = m_swapBytes; |
1381 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
1382 | | |
1383 | | try |
1384 | | { |
1385 | | serialize(vector_t); |
1386 | | m_swapBytes = auxSwap; |
1387 | | } |
1388 | | catch (eprosima::fastcdr::exception::Exception& ex) |
1389 | | { |
1390 | | m_swapBytes = auxSwap; |
1391 | | ex.raise(); |
1392 | | } |
1393 | | |
1394 | | return *this; |
1395 | | } |
1396 | | |
1397 | | /*! |
1398 | | * @brief This function template serializes a non-basic object. |
1399 | | * @param type_t The object that will be serialized in the buffer. |
1400 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1401 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1402 | | */ |
1403 | | template<class _T> |
1404 | | inline Cdr& serialize( |
1405 | | const _T& type_t) |
1406 | | { |
1407 | | type_t.serialize(*this); |
1408 | | return *this; |
1409 | | } |
1410 | | |
1411 | | /*! |
1412 | | * @brief This function serializes an array of octets. |
1413 | | * @param octet_t The sequence of octets that will be serialized in the buffer. |
1414 | | * @param numElements Number of the elements in the array. |
1415 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1416 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1417 | | */ |
1418 | | inline |
1419 | | Cdr& serializeArray( |
1420 | | const uint8_t* octet_t, |
1421 | | size_t numElements) |
1422 | 0 | { |
1423 | 0 | return serializeArray(reinterpret_cast<const char*>(octet_t), numElements); |
1424 | 0 | } |
1425 | | |
1426 | | /*! |
1427 | | * @brief This function serializes an array of octets with a different endianness. |
1428 | | * @param octet_t The array of octets that will be serialized in the buffer. |
1429 | | * @param numElements Number of the elements in the array. |
1430 | | * @param endianness Endianness that will be used in the serialization of this value. |
1431 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1432 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1433 | | */ |
1434 | | inline |
1435 | | Cdr& serializeArray( |
1436 | | const uint8_t* octet_t, |
1437 | | size_t numElements, |
1438 | | Endianness endianness) |
1439 | 0 | { |
1440 | 0 | (void) endianness; |
1441 | 0 | return serializeArray(reinterpret_cast<const char*>(octet_t), numElements); |
1442 | 0 | } |
1443 | | |
1444 | | /*! |
1445 | | * @brief This function serializes an array of characters. |
1446 | | * @param char_t The array of characters that will be serialized in the buffer. |
1447 | | * @param numElements Number of the elements in the array. |
1448 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1449 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1450 | | */ |
1451 | | Cdr& serializeArray( |
1452 | | const char* char_t, |
1453 | | size_t numElements); |
1454 | | |
1455 | | /*! |
1456 | | * @brief This function serializes an array of characters with a different endianness. |
1457 | | * @param char_t The array of characters that will be serialized in the buffer. |
1458 | | * @param numElements Number of the elements in the array. |
1459 | | * @param endianness Endianness that will be used in the serialization of this value. |
1460 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1461 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1462 | | */ |
1463 | | inline |
1464 | | Cdr& serializeArray( |
1465 | | const char* char_t, |
1466 | | size_t numElements, |
1467 | | Endianness endianness) |
1468 | 0 | { |
1469 | 0 | (void) endianness; |
1470 | 0 | return serializeArray(char_t, numElements); |
1471 | 0 | } |
1472 | | |
1473 | | /*! |
1474 | | * @brief This function serializes an array of int8_t. |
1475 | | * @param int8 The sequence of int8_t that will be serialized in the buffer. |
1476 | | * @param numElements Number of the elements in the array. |
1477 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1478 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1479 | | */ |
1480 | | inline |
1481 | | Cdr& serializeArray( |
1482 | | const int8_t* int8, |
1483 | | size_t numElements) |
1484 | 0 | { |
1485 | 0 | return serializeArray(reinterpret_cast<const char*>(int8), numElements); |
1486 | 0 | } |
1487 | | |
1488 | | /*! |
1489 | | * @brief This function serializes an array of int8_t with a different endianness. |
1490 | | * @param int8 The array of int8_t that will be serialized in the buffer. |
1491 | | * @param numElements Number of the elements in the array. |
1492 | | * @param endianness Endianness that will be used in the serialization of this value. |
1493 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1494 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1495 | | */ |
1496 | | inline |
1497 | | Cdr& serializeArray( |
1498 | | const int8_t* int8, |
1499 | | size_t numElements, |
1500 | | Endianness endianness) |
1501 | 0 | { |
1502 | 0 | (void) endianness; |
1503 | 0 | return serializeArray(reinterpret_cast<const char*>(int8), numElements); |
1504 | 0 | } |
1505 | | |
1506 | | /*! |
1507 | | * @brief This function serializes an array of unsigned shorts. |
1508 | | * @param ushort_t The array of unsigned shorts that will be serialized in the buffer. |
1509 | | * @param numElements Number of the elements in the array. |
1510 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1511 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1512 | | */ |
1513 | | inline |
1514 | | Cdr& serializeArray( |
1515 | | const uint16_t* ushort_t, |
1516 | | size_t numElements) |
1517 | 0 | { |
1518 | 0 | return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements); |
1519 | 0 | } |
1520 | | |
1521 | | /*! |
1522 | | * @brief This function serializes an array of unsigned shorts with a different endianness. |
1523 | | * @param ushort_t The array of unsigned shorts that will be serialized in the buffer. |
1524 | | * @param numElements Number of the elements in the array. |
1525 | | * @param endianness Endianness that will be used in the serialization of this value. |
1526 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1527 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1528 | | */ |
1529 | | inline |
1530 | | Cdr& serializeArray( |
1531 | | const uint16_t* ushort_t, |
1532 | | size_t numElements, |
1533 | | Endianness endianness) |
1534 | 0 | { |
1535 | 0 | return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements, endianness); |
1536 | 0 | } |
1537 | | |
1538 | | /*! |
1539 | | * @brief This function serializes an array of shorts. |
1540 | | * @param short_t The array of shorts that will be serialized in the buffer. |
1541 | | * @param numElements Number of the elements in the array. |
1542 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1543 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1544 | | */ |
1545 | | Cdr& serializeArray( |
1546 | | const int16_t* short_t, |
1547 | | size_t numElements); |
1548 | | |
1549 | | /*! |
1550 | | * @brief This function serializes an array of shorts with a different endianness. |
1551 | | * @param short_t The array of shorts that will be serialized in the buffer. |
1552 | | * @param numElements Number of the elements in the array. |
1553 | | * @param endianness Endianness that will be used in the serialization of this value. |
1554 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1555 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1556 | | */ |
1557 | | Cdr& serializeArray( |
1558 | | const int16_t* short_t, |
1559 | | size_t numElements, |
1560 | | Endianness endianness); |
1561 | | |
1562 | | /*! |
1563 | | * @brief This function serializes an array of unsigned longs. |
1564 | | * @param ulong_t The array of unsigned longs that will be serialized in the buffer. |
1565 | | * @param numElements Number of the elements in the array. |
1566 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1567 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1568 | | */ |
1569 | | inline |
1570 | | Cdr& serializeArray( |
1571 | | const uint32_t* ulong_t, |
1572 | | size_t numElements) |
1573 | 0 | { |
1574 | 0 | return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements); |
1575 | 0 | } |
1576 | | |
1577 | | /*! |
1578 | | * @brief This function serializes an array of unsigned longs with a different endianness. |
1579 | | * @param ulong_t The array of unsigned longs that will be serialized in the buffer. |
1580 | | * @param numElements Number of the elements in the array. |
1581 | | * @param endianness Endianness that will be used in the serialization of this value. |
1582 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1583 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1584 | | */ |
1585 | | inline |
1586 | | Cdr& serializeArray( |
1587 | | const uint32_t* ulong_t, |
1588 | | size_t numElements, |
1589 | | Endianness endianness) |
1590 | 0 | { |
1591 | 0 | return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements, endianness); |
1592 | 0 | } |
1593 | | |
1594 | | /*! |
1595 | | * @brief This function serializes an array of longs. |
1596 | | * @param long_t The array of longs that will be serialized in the buffer. |
1597 | | * @param numElements Number of the elements in the array. |
1598 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1599 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1600 | | */ |
1601 | | Cdr& serializeArray( |
1602 | | const int32_t* long_t, |
1603 | | size_t numElements); |
1604 | | |
1605 | | /*! |
1606 | | * @brief This function serializes an array of longs with a different endianness. |
1607 | | * @param long_t The array of longs that will be serialized in the buffer. |
1608 | | * @param numElements Number of the elements in the array. |
1609 | | * @param endianness Endianness that will be used in the serialization of this value. |
1610 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1611 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1612 | | */ |
1613 | | Cdr& serializeArray( |
1614 | | const int32_t* long_t, |
1615 | | size_t numElements, |
1616 | | Endianness endianness); |
1617 | | |
1618 | | /*! |
1619 | | * @brief This function serializes an array of wide-chars. |
1620 | | * @param wchar The array of wide-chars that will be serialized in the buffer. |
1621 | | * @param numElements Number of the elements in the array. |
1622 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1623 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1624 | | */ |
1625 | | Cdr& serializeArray( |
1626 | | const wchar_t* wchar, |
1627 | | size_t numElements); |
1628 | | |
1629 | | /*! |
1630 | | * @brief This function serializes an array of wide-chars with a different endianness. |
1631 | | * @param wchar The array of longs that will be serialized in the buffer. |
1632 | | * @param numElements Number of the elements in the array. |
1633 | | * @param endianness Endianness that will be used in the serialization of this value. |
1634 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1635 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1636 | | */ |
1637 | | Cdr& serializeArray( |
1638 | | const wchar_t* wchar, |
1639 | | size_t numElements, |
1640 | | Endianness endianness); |
1641 | | |
1642 | | /*! |
1643 | | * @brief This function serializes an array of unsigned long longs. |
1644 | | * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer. |
1645 | | * @param numElements Number of the elements in the array. |
1646 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1647 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1648 | | */ |
1649 | | inline |
1650 | | Cdr& serializeArray( |
1651 | | const uint64_t* ulonglong_t, |
1652 | | size_t numElements) |
1653 | 0 | { |
1654 | 0 | return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements); |
1655 | 0 | } |
1656 | | |
1657 | | /*! |
1658 | | * @brief This function serializes an array of unsigned long longs with a different endianness. |
1659 | | * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer. |
1660 | | * @param numElements Number of the elements in the array. |
1661 | | * @param endianness Endianness that will be used in the serialization of this value. |
1662 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1663 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1664 | | */ |
1665 | | inline |
1666 | | Cdr& serializeArray( |
1667 | | const uint64_t* ulonglong_t, |
1668 | | size_t numElements, |
1669 | | Endianness endianness) |
1670 | 0 | { |
1671 | 0 | return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements, endianness); |
1672 | 0 | } |
1673 | | |
1674 | | /*! |
1675 | | * @brief This function serializes an array of long longs. |
1676 | | * @param longlong_t The array of long longs that will be serialized in the buffer. |
1677 | | * @param numElements Number of the elements in the array. |
1678 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1679 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1680 | | */ |
1681 | | Cdr& serializeArray( |
1682 | | const int64_t* longlong_t, |
1683 | | size_t numElements); |
1684 | | |
1685 | | /*! |
1686 | | * @brief This function serializes an array of long longs with a different endianness. |
1687 | | * @param longlong_t The array of long longs that will be serialized in the buffer. |
1688 | | * @param numElements Number of the elements in the array. |
1689 | | * @param endianness Endianness that will be used in the serialization of this value. |
1690 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1691 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1692 | | */ |
1693 | | Cdr& serializeArray( |
1694 | | const int64_t* longlong_t, |
1695 | | size_t numElements, |
1696 | | Endianness endianness); |
1697 | | |
1698 | | /*! |
1699 | | * @brief This function serializes an array of floats. |
1700 | | * @param float_t The array of floats that will be serialized in the buffer. |
1701 | | * @param numElements Number of the elements in the array. |
1702 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1703 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1704 | | */ |
1705 | | Cdr& serializeArray( |
1706 | | const float* float_t, |
1707 | | size_t numElements); |
1708 | | |
1709 | | /*! |
1710 | | * @brief This function serializes an array of floats with a different endianness. |
1711 | | * @param float_t The array of floats that will be serialized in the buffer. |
1712 | | * @param numElements Number of the elements in the array. |
1713 | | * @param endianness Endianness that will be used in the serialization of this value. |
1714 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1715 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1716 | | */ |
1717 | | Cdr& serializeArray( |
1718 | | const float* float_t, |
1719 | | size_t numElements, |
1720 | | Endianness endianness); |
1721 | | |
1722 | | /*! |
1723 | | * @brief This function serializes an array of doubles. |
1724 | | * @param double_t The array of doubles that will be serialized in the buffer. |
1725 | | * @param numElements Number of the elements in the array. |
1726 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1727 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1728 | | */ |
1729 | | Cdr& serializeArray( |
1730 | | const double* double_t, |
1731 | | size_t numElements); |
1732 | | |
1733 | | /*! |
1734 | | * @brief This function serializes an array of doubles with a different endianness. |
1735 | | * @param double_t The array of doubles that will be serialized in the buffer. |
1736 | | * @param numElements Number of the elements in the array. |
1737 | | * @param endianness Endianness that will be used in the serialization of this value. |
1738 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1739 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1740 | | */ |
1741 | | Cdr& serializeArray( |
1742 | | const double* double_t, |
1743 | | size_t numElements, |
1744 | | Endianness endianness); |
1745 | | |
1746 | | /*! |
1747 | | * @brief This function serializes an array of long doubles. |
1748 | | * @param ldouble_t The array of long doubles that will be serialized in the buffer. |
1749 | | * @param numElements Number of the elements in the array. |
1750 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1751 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1752 | | */ |
1753 | | Cdr& serializeArray( |
1754 | | const long double* ldouble_t, |
1755 | | size_t numElements); |
1756 | | |
1757 | | /*! |
1758 | | * @brief This function serializes an array of long doubles with a different endianness. |
1759 | | * @param ldouble_t The array of long doubles that will be serialized in the buffer. |
1760 | | * @param numElements Number of the elements in the array. |
1761 | | * @param endianness Endianness that will be used in the serialization of this value. |
1762 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1763 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1764 | | */ |
1765 | | Cdr& serializeArray( |
1766 | | const long double* ldouble_t, |
1767 | | size_t numElements, |
1768 | | Endianness endianness); |
1769 | | |
1770 | | /*! |
1771 | | * @brief This function serializes an array of booleans. |
1772 | | * @param bool_t The array of booleans that will be serialized in the buffer. |
1773 | | * @param numElements Number of the elements in the array. |
1774 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1775 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1776 | | */ |
1777 | | Cdr& serializeArray( |
1778 | | const bool* bool_t, |
1779 | | size_t numElements); |
1780 | | |
1781 | | /*! |
1782 | | * @brief This function serializes an array of booleans with a different endianness. |
1783 | | * @param bool_t The array of booleans that will be serialized in the buffer. |
1784 | | * @param numElements Number of the elements in the array. |
1785 | | * @param endianness Endianness that will be used in the serialization of this value. |
1786 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1787 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1788 | | */ |
1789 | | inline |
1790 | | Cdr& serializeArray( |
1791 | | const bool* bool_t, |
1792 | | size_t numElements, |
1793 | | Endianness endianness) |
1794 | 0 | { |
1795 | 0 | (void) endianness; |
1796 | 0 | return serializeArray(bool_t, numElements); |
1797 | 0 | } |
1798 | | |
1799 | | /*! |
1800 | | * @brief This function serializes an array of strings. |
1801 | | * @param string_t The array of strings that will be serialized in the buffer. |
1802 | | * @param numElements Number of the elements in the array. |
1803 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1804 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1805 | | */ |
1806 | | inline |
1807 | | Cdr& serializeArray( |
1808 | | const std::string* string_t, |
1809 | | size_t numElements) |
1810 | 0 | { |
1811 | 0 | for (size_t count = 0; count < numElements; ++count) |
1812 | 0 | { |
1813 | 0 | serialize(string_t[count].c_str()); |
1814 | 0 | } |
1815 | 0 | return *this; |
1816 | 0 | } |
1817 | | |
1818 | | /*! |
1819 | | * @brief This function serializes an array of wide-strings. |
1820 | | * @param string_t The array of wide-strings that will be serialized in the buffer. |
1821 | | * @param numElements Number of the elements in the array. |
1822 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1823 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1824 | | */ |
1825 | | inline |
1826 | | Cdr& serializeArray( |
1827 | | const std::wstring* string_t, |
1828 | | size_t numElements) |
1829 | 0 | { |
1830 | 0 | for (size_t count = 0; count < numElements; ++count) |
1831 | 0 | { |
1832 | 0 | serialize(string_t[count].c_str()); |
1833 | 0 | } |
1834 | 0 | return *this; |
1835 | 0 | } |
1836 | | |
1837 | | /*! |
1838 | | * @brief This function serializes an array of strings with a different endianness. |
1839 | | * @param string_t The array of strings that will be serialized in the buffer. |
1840 | | * @param numElements Number of the elements in the array. |
1841 | | * @param endianness Endianness that will be used in the serialization of this value. |
1842 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1843 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1844 | | */ |
1845 | | inline |
1846 | | Cdr& serializeArray( |
1847 | | const std::string* string_t, |
1848 | | size_t numElements, |
1849 | | Endianness endianness) |
1850 | 0 | { |
1851 | 0 | bool auxSwap = m_swapBytes; |
1852 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
1853 | 0 |
|
1854 | 0 | try |
1855 | 0 | { |
1856 | 0 | serializeArray(string_t, numElements); |
1857 | 0 | m_swapBytes = auxSwap; |
1858 | 0 | } |
1859 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
1860 | 0 | { |
1861 | 0 | m_swapBytes = auxSwap; |
1862 | 0 | ex.raise(); |
1863 | 0 | } |
1864 | 0 |
|
1865 | 0 | return *this; |
1866 | 0 | } |
1867 | | |
1868 | | /*! |
1869 | | * @brief This function serializes an array of wide-strings with a different endianness. |
1870 | | * @param string_t The array of wide-strings that will be serialized in the buffer. |
1871 | | * @param numElements Number of the elements in the array. |
1872 | | * @param endianness Endianness that will be used in the serialization of this value. |
1873 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1874 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1875 | | */ |
1876 | | inline |
1877 | | Cdr& serializeArray( |
1878 | | const std::wstring* string_t, |
1879 | | size_t numElements, |
1880 | | Endianness endianness) |
1881 | 0 | { |
1882 | 0 | bool auxSwap = m_swapBytes; |
1883 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
1884 | 0 |
|
1885 | 0 | try |
1886 | 0 | { |
1887 | 0 | serializeArray(string_t, numElements); |
1888 | 0 | m_swapBytes = auxSwap; |
1889 | 0 | } |
1890 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
1891 | 0 | { |
1892 | 0 | m_swapBytes = auxSwap; |
1893 | 0 | ex.raise(); |
1894 | 0 | } |
1895 | 0 |
|
1896 | 0 | return *this; |
1897 | 0 | } |
1898 | | |
1899 | | /*! |
1900 | | * @brief This function template serializes an array of sequences of objects. |
1901 | | * @param vector_t The array of sequences of objects that will be serialized in the buffer. |
1902 | | * @param numElements Number of the elements in the array. |
1903 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1904 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1905 | | */ |
1906 | | template<class _T> |
1907 | | Cdr& serializeArray( |
1908 | | const std::vector<_T>* vector_t, |
1909 | | size_t numElements) |
1910 | | { |
1911 | | for (size_t count = 0; count < numElements; ++count) |
1912 | | { |
1913 | | serialize(vector_t[count]); |
1914 | | } |
1915 | | return *this; |
1916 | | } |
1917 | | |
1918 | | /*! |
1919 | | * @brief This function template serializes an array of non-basic objects. |
1920 | | * @param type_t The array of objects that will be serialized in the buffer. |
1921 | | * @param numElements Number of the elements in the array. |
1922 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1923 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1924 | | */ |
1925 | | template<class _T> |
1926 | | Cdr& serializeArray( |
1927 | | const _T* type_t, |
1928 | | size_t numElements) |
1929 | | { |
1930 | | for (size_t count = 0; count < numElements; ++count) |
1931 | | { |
1932 | | type_t[count].serialize(*this); |
1933 | | } |
1934 | | return *this; |
1935 | | } |
1936 | | |
1937 | | /*! |
1938 | | * @brief This function template serializes an array of non-basic objects with a different endianness. |
1939 | | * @param type_t The array of objects that will be serialized in the buffer. |
1940 | | * @param numElements Number of the elements in the array. |
1941 | | * @param endianness Endianness that will be used in the serialization of this value. |
1942 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1943 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1944 | | */ |
1945 | | template<class _T> |
1946 | | Cdr& serializeArray( |
1947 | | const _T* type_t, |
1948 | | size_t numElements, |
1949 | | Endianness endianness) |
1950 | | { |
1951 | | bool auxSwap = m_swapBytes; |
1952 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
1953 | | |
1954 | | try |
1955 | | { |
1956 | | serializeArray(type_t, numElements); |
1957 | | m_swapBytes = auxSwap; |
1958 | | } |
1959 | | catch (eprosima::fastcdr::exception::Exception& ex) |
1960 | | { |
1961 | | m_swapBytes = auxSwap; |
1962 | | ex.raise(); |
1963 | | } |
1964 | | |
1965 | | return *this; |
1966 | | } |
1967 | | |
1968 | | /*! |
1969 | | * @brief This function template serializes a raw sequence. |
1970 | | * @param sequence_t Pointer to the sequence that will be serialized in the buffer. |
1971 | | * @param numElements The number of elements contained in the sequence. |
1972 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
1973 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
1974 | | */ |
1975 | | template<class _T> |
1976 | | Cdr& serializeSequence( |
1977 | | const _T* sequence_t, |
1978 | | size_t numElements) |
1979 | | { |
1980 | | state state_before_error(*this); |
1981 | | |
1982 | | serialize(static_cast<int32_t>(numElements)); |
1983 | | |
1984 | | try |
1985 | | { |
1986 | | return serializeArray(sequence_t, numElements); |
1987 | | } |
1988 | | catch (eprosima::fastcdr::exception::Exception& ex) |
1989 | | { |
1990 | | setState(state_before_error); |
1991 | | ex.raise(); |
1992 | | } |
1993 | | |
1994 | | return *this; |
1995 | | } |
1996 | | |
1997 | | /*! |
1998 | | * @brief This function template serializes a raw sequence with a different endianness. |
1999 | | * @param sequence_t Pointer to the sequence that will be serialized in the buffer. |
2000 | | * @param numElements The number of elements contained in the sequence. |
2001 | | * @param endianness Endianness that will be used in the serialization of this value. |
2002 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2003 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
2004 | | */ |
2005 | | template<class _T> |
2006 | | Cdr& serializeSequence( |
2007 | | const _T* sequence_t, |
2008 | | size_t numElements, |
2009 | | Endianness endianness) |
2010 | | { |
2011 | | bool auxSwap = m_swapBytes; |
2012 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
2013 | | |
2014 | | try |
2015 | | { |
2016 | | serializeSequence(sequence_t, numElements); |
2017 | | m_swapBytes = auxSwap; |
2018 | | } |
2019 | | catch (eprosima::fastcdr::exception::Exception& ex) |
2020 | | { |
2021 | | m_swapBytes = auxSwap; |
2022 | | ex.raise(); |
2023 | | } |
2024 | | |
2025 | | return *this; |
2026 | | } |
2027 | | |
2028 | | /*! |
2029 | | * @brief This function deserializes an octet. |
2030 | | * @param octet_t The variable that will store the octet read from the buffer. |
2031 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2032 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2033 | | */ |
2034 | | inline |
2035 | | Cdr& deserialize( |
2036 | | uint8_t& octet_t) |
2037 | 0 | { |
2038 | 0 | return deserialize(reinterpret_cast<char&>(octet_t)); |
2039 | 0 | } |
2040 | | |
2041 | | /*! |
2042 | | * @brief This function deserializes an octet with a different endianness. |
2043 | | * @param octet_t The variable that will store the octet read from the buffer. |
2044 | | * @param endianness Endianness that will be used in the serialization of this value. |
2045 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2046 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2047 | | */ |
2048 | | inline |
2049 | | Cdr& deserialize( |
2050 | | uint8_t& octet_t, |
2051 | | Endianness endianness) |
2052 | 0 | { |
2053 | 0 | return deserialize(reinterpret_cast<char&>(octet_t), endianness); |
2054 | 0 | } |
2055 | | |
2056 | | /*! |
2057 | | * @brief This function deserializes a character. |
2058 | | * @param char_t The variable that will store the character read from the buffer. |
2059 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2060 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2061 | | */ |
2062 | | Cdr& deserialize( |
2063 | | char& char_t); |
2064 | | |
2065 | | /*! |
2066 | | * @brief This function deserializes a character with a different endianness. |
2067 | | * @param char_t The variable that will store the character read from the buffer. |
2068 | | * @param endianness Endianness that will be used in the serialization of this value. |
2069 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2070 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2071 | | */ |
2072 | | inline |
2073 | | Cdr& deserialize( |
2074 | | char& char_t, |
2075 | | Endianness endianness) |
2076 | 0 | { |
2077 | 0 | (void) endianness; |
2078 | 0 | return deserialize(char_t); |
2079 | 0 | } |
2080 | | |
2081 | | /*! |
2082 | | * @brief This function deserializes an int8_t. |
2083 | | * @param int8 The variable that will store the int8_t read from the buffer. |
2084 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2085 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2086 | | */ |
2087 | | inline |
2088 | | Cdr& deserialize( |
2089 | | int8_t& int8) |
2090 | 0 | { |
2091 | 0 | return deserialize(reinterpret_cast<char&>(int8)); |
2092 | 0 | } |
2093 | | |
2094 | | /*! |
2095 | | * @brief This function deserializes an int8_t with a different endianness. |
2096 | | * @param int8 The variable that will store the int8_t read from the buffer. |
2097 | | * @param endianness Endianness that will be used in the serialization of this value. |
2098 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2099 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2100 | | */ |
2101 | | inline |
2102 | | Cdr& deserialize( |
2103 | | int8_t& int8, |
2104 | | Endianness endianness) |
2105 | 0 | { |
2106 | 0 | return deserialize(reinterpret_cast<char&>(int8), endianness); |
2107 | 0 | } |
2108 | | |
2109 | | /*! |
2110 | | * @brief This function deserializes an unsigned short. |
2111 | | * @param ushort_t The variable that will store the unsigned short read from the buffer. |
2112 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2113 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2114 | | */ |
2115 | | inline |
2116 | | Cdr& deserialize( |
2117 | | uint16_t& ushort_t) |
2118 | 0 | { |
2119 | 0 | return deserialize(reinterpret_cast<int16_t&>(ushort_t)); |
2120 | 0 | } |
2121 | | |
2122 | | /*! |
2123 | | * @brief This function deserializes an unsigned short with a different endianness. |
2124 | | * @param ushort_t The variable that will store the unsigned short read from the buffer. |
2125 | | * @param endianness Endianness that will be used in the serialization of this value. |
2126 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2127 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2128 | | */ |
2129 | | inline |
2130 | | Cdr& deserialize( |
2131 | | uint16_t& ushort_t, |
2132 | | Endianness endianness) |
2133 | 0 | { |
2134 | 0 | return deserialize(reinterpret_cast<int16_t&>(ushort_t), endianness); |
2135 | 0 | } |
2136 | | |
2137 | | /*! |
2138 | | * @brief This function deserializes a short. |
2139 | | * @param short_t The variable that will store the short read from the buffer. |
2140 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2141 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2142 | | */ |
2143 | | Cdr& deserialize( |
2144 | | int16_t& short_t); |
2145 | | |
2146 | | /*! |
2147 | | * @brief This function deserializes a short with a different endianness. |
2148 | | * @param short_t The variable that will store the short read from the buffer. |
2149 | | * @param endianness Endianness that will be used in the serialization of this value. |
2150 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2151 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2152 | | */ |
2153 | | Cdr& deserialize( |
2154 | | int16_t& short_t, |
2155 | | Endianness endianness); |
2156 | | |
2157 | | /*! |
2158 | | * @brief This function deserializes an unsigned long. |
2159 | | * @param ulong_t The variable that will store the unsigned long read from the buffer. |
2160 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2161 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2162 | | */ |
2163 | | inline |
2164 | | Cdr& deserialize( |
2165 | | uint32_t& ulong_t) |
2166 | 0 | { |
2167 | 0 | return deserialize(reinterpret_cast<int32_t&>(ulong_t)); |
2168 | 0 | } |
2169 | | |
2170 | | /*! |
2171 | | * @brief This function deserializes an unsigned long with a different endianness. |
2172 | | * @param ulong_t The variable that will store the unsigned long read from the buffer.. |
2173 | | * @param endianness Endianness that will be used in the serialization of this value. |
2174 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2175 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2176 | | */ |
2177 | | inline |
2178 | | Cdr& deserialize( |
2179 | | uint32_t& ulong_t, |
2180 | | Endianness endianness) |
2181 | 0 | { |
2182 | 0 | return deserialize(reinterpret_cast<int32_t&>(ulong_t), endianness); |
2183 | 0 | } |
2184 | | |
2185 | | /*! |
2186 | | * @brief This function deserializes a long. |
2187 | | * @param long_t The variable that will store the long read from the buffer. |
2188 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2189 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2190 | | */ |
2191 | | Cdr& deserialize( |
2192 | | int32_t& long_t); |
2193 | | |
2194 | | /*! |
2195 | | * @brief This function deserializes a long with a different endianness. |
2196 | | * @param long_t The variable that will store the long read from the buffer. |
2197 | | * @param endianness Endianness that will be used in the serialization of this value. |
2198 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2199 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2200 | | */ |
2201 | | Cdr& deserialize( |
2202 | | int32_t& long_t, |
2203 | | Endianness endianness); |
2204 | | |
2205 | | /*! |
2206 | | * @brief This function deserializes a wide-char. |
2207 | | * @param wchar The variable that will store the wide-char read from the buffer. |
2208 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2209 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2210 | | */ |
2211 | | inline |
2212 | | Cdr& deserialize( |
2213 | | wchar_t& wchar) |
2214 | 0 | { |
2215 | 0 | uint32_t ret; |
2216 | 0 | deserialize(ret); |
2217 | 0 | wchar = static_cast<wchar_t>(ret); |
2218 | 0 | return *this; |
2219 | 0 | } |
2220 | | |
2221 | | /*! |
2222 | | * @brief This function deserializes a wide-char with a different endianness. |
2223 | | * @param wchar The variable that will store the wide-char read from the buffer. |
2224 | | * @param endianness Endianness that will be used in the serialization of this value. |
2225 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2226 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2227 | | */ |
2228 | | inline |
2229 | | Cdr& deserialize( |
2230 | | wchar_t& wchar, |
2231 | | Endianness endianness) |
2232 | 0 | { |
2233 | 0 | uint32_t ret; |
2234 | 0 | deserialize(ret, endianness); |
2235 | 0 | wchar = static_cast<wchar_t>(ret); |
2236 | 0 | return *this; |
2237 | 0 | } |
2238 | | |
2239 | | /*! |
2240 | | * @brief This function deserializes an unsigned long long. |
2241 | | * @param ulonglong_t The variable that will store the unsigned long long read from the buffer. |
2242 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2243 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2244 | | */ |
2245 | | inline |
2246 | | Cdr& deserialize( |
2247 | | uint64_t& ulonglong_t) |
2248 | 0 | { |
2249 | 0 | return deserialize(reinterpret_cast<int64_t&>(ulonglong_t)); |
2250 | 0 | } |
2251 | | |
2252 | | /*! |
2253 | | * @brief This function deserializes an unsigned long long with a different endianness. |
2254 | | * @param ulonglong_t The variable that will store the unsigned long long read from the buffer. |
2255 | | * @param endianness Endianness that will be used in the serialization of this value. |
2256 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2257 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2258 | | */ |
2259 | | inline |
2260 | | Cdr& deserialize( |
2261 | | uint64_t& ulonglong_t, |
2262 | | Endianness endianness) |
2263 | 0 | { |
2264 | 0 | return deserialize(reinterpret_cast<int64_t&>(ulonglong_t), endianness); |
2265 | 0 | } |
2266 | | |
2267 | | /*! |
2268 | | * @brief This function deserializes a long long. |
2269 | | * @param longlong_t The variable that will store the long long read from the buffer. |
2270 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2271 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2272 | | */ |
2273 | | Cdr& deserialize( |
2274 | | int64_t& longlong_t); |
2275 | | |
2276 | | /*! |
2277 | | * @brief This function deserializes a long long with a different endianness. |
2278 | | * @param longlong_t The variable that will store the long long read from the buffer. |
2279 | | * @param endianness Endianness that will be used in the serialization of this value. |
2280 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2281 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2282 | | */ |
2283 | | Cdr& deserialize( |
2284 | | int64_t& longlong_t, |
2285 | | Endianness endianness); |
2286 | | |
2287 | | /*! |
2288 | | * @brief This function deserializes a float. |
2289 | | * @param float_t The variable that will store the float read from the buffer. |
2290 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2291 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2292 | | */ |
2293 | | Cdr& deserialize( |
2294 | | float& float_t); |
2295 | | |
2296 | | /*! |
2297 | | * @brief This function deserializes a float with a different endianness. |
2298 | | * @param float_t The variable that will store the float read from the buffer. |
2299 | | * @param endianness Endianness that will be used in the serialization of this value. |
2300 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2301 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2302 | | */ |
2303 | | Cdr& deserialize( |
2304 | | float& float_t, |
2305 | | Endianness endianness); |
2306 | | |
2307 | | /*! |
2308 | | * @brief This function deserializes a double. |
2309 | | * @param double_t The variable that will store the double read from the buffer. |
2310 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2311 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2312 | | */ |
2313 | | Cdr& deserialize( |
2314 | | double& double_t); |
2315 | | |
2316 | | /*! |
2317 | | * @brief This function deserializes a double with a different endianness. |
2318 | | * @param double_t The variable that will store the double read from the buffer. |
2319 | | * @param endianness Endianness that will be used in the serialization of this value. |
2320 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2321 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2322 | | */ |
2323 | | Cdr& deserialize( |
2324 | | double& double_t, |
2325 | | Endianness endianness); |
2326 | | |
2327 | | /*! |
2328 | | * @brief This function deserializes a long double. |
2329 | | * @param ldouble_t The variable that will store the long double read from the buffer. |
2330 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2331 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2332 | | * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible. |
2333 | | */ |
2334 | | Cdr& deserialize( |
2335 | | long double& ldouble_t); |
2336 | | |
2337 | | /*! |
2338 | | * @brief This function deserializes a long double with a different endianness. |
2339 | | * @param ldouble_t The variable that will store the long double read from the buffer. |
2340 | | * @param endianness Endianness that will be used in the serialization of this value. |
2341 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2342 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2343 | | * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible. |
2344 | | */ |
2345 | | Cdr& deserialize( |
2346 | | long double& ldouble_t, |
2347 | | Endianness endianness); |
2348 | | |
2349 | | /*! |
2350 | | * @brief This function deserializes a boolean. |
2351 | | * @param bool_t The variable that will store the boolean read from the buffer. |
2352 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2353 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2354 | | * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value. |
2355 | | */ |
2356 | | Cdr& deserialize( |
2357 | | bool& bool_t); |
2358 | | |
2359 | | /*! |
2360 | | * @brief This function deserializes a boolean with a different endianness. |
2361 | | * @param bool_t The variable that will store the boolean read from the buffer. |
2362 | | * @param endianness Endianness that will be used in the serialization of this value. |
2363 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2364 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2365 | | * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value. |
2366 | | */ |
2367 | | inline |
2368 | | Cdr& deserialize( |
2369 | | bool& bool_t, |
2370 | | Endianness endianness) |
2371 | 0 | { |
2372 | 0 | (void) endianness; |
2373 | 0 | return deserialize(bool_t); |
2374 | 0 | } |
2375 | | |
2376 | | /*! |
2377 | | * @brief This function deserializes a string. |
2378 | | * This function allocates memory to store the string. The user pointer will be set to point this allocated memory. |
2379 | | * The user will have to free this allocated memory using free() |
2380 | | * @param string_t The pointer that will point to the string read from the buffer. |
2381 | | * The user will have to free the allocated memory using free() |
2382 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2383 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2384 | | */ |
2385 | | Cdr& deserialize( |
2386 | | char*& string_t); |
2387 | | |
2388 | | /*! |
2389 | | * @brief This function deserializes a wide string. |
2390 | | * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory. |
2391 | | * The user will have to free this allocated memory using free() |
2392 | | * @param string_t The pointer that will point to the wide string read from the buffer. |
2393 | | * The user will have to free the allocated memory using free() |
2394 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2395 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2396 | | */ |
2397 | | Cdr& deserialize( |
2398 | | wchar_t*& string_t); |
2399 | | |
2400 | | /*! |
2401 | | * @brief This function deserializes a string with a different endianness. |
2402 | | * This function allocates memory to store the string. The user pointer will be set to point this allocated memory. |
2403 | | * The user will have to free this allocated memory using free() |
2404 | | * @param string_t The pointer that will point to the string read from the buffer. |
2405 | | * @param endianness Endianness that will be used in the deserialization of this value. |
2406 | | * The user will have to free the allocated memory using free() |
2407 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2408 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2409 | | */ |
2410 | | Cdr& deserialize( |
2411 | | char*& string_t, |
2412 | | Endianness endianness); |
2413 | | |
2414 | | /*! |
2415 | | * @brief This function deserializes a wide string with a different endianness. |
2416 | | * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory. |
2417 | | * The user will have to free this allocated memory using free() |
2418 | | * @param string_t The pointer that will point to the wide string read from the buffer. |
2419 | | * @param endianness Endianness that will be used in the deserialization of this value. |
2420 | | * The user will have to free the allocated memory using free() |
2421 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2422 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2423 | | */ |
2424 | | Cdr& deserialize( |
2425 | | wchar_t*& string_t, |
2426 | | Endianness endianness); |
2427 | | |
2428 | | /*! |
2429 | | * @brief This function deserializes a std::string. |
2430 | | * @param string_t The variable that will store the string read from the buffer. |
2431 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2432 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2433 | | */ |
2434 | | inline |
2435 | | Cdr& deserialize( |
2436 | | std::string& string_t) |
2437 | 0 | { |
2438 | 0 | uint32_t length = 0; |
2439 | 0 | const char* str = readString(length); |
2440 | 0 | string_t = std::string(str, length); |
2441 | 0 | return *this; |
2442 | 0 | } |
2443 | | |
2444 | | /*! |
2445 | | * @brief This function deserializes a std::string. |
2446 | | * @param string_t The variable that will store the string read from the buffer. |
2447 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2448 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2449 | | */ |
2450 | | inline |
2451 | | Cdr& deserialize( |
2452 | | std::wstring& string_t) |
2453 | 0 | { |
2454 | 0 | uint32_t length = 0; |
2455 | 0 | string_t = readWString(length); |
2456 | 0 | return *this; |
2457 | 0 | } |
2458 | | |
2459 | | /*! |
2460 | | * @brief This function deserializes a string with a different endianness. |
2461 | | * @param string_t The variable that will store the string read from the buffer. |
2462 | | * @param endianness Endianness that will be used in the serialization of this value. |
2463 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2464 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2465 | | */ |
2466 | | inline |
2467 | | Cdr& deserialize( |
2468 | | std::string& string_t, |
2469 | | Endianness endianness) |
2470 | 0 | { |
2471 | 0 | bool auxSwap = m_swapBytes; |
2472 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
2473 | 0 |
|
2474 | 0 | try |
2475 | 0 | { |
2476 | 0 | deserialize(string_t); |
2477 | 0 | m_swapBytes = auxSwap; |
2478 | 0 | } |
2479 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
2480 | 0 | { |
2481 | 0 | m_swapBytes = auxSwap; |
2482 | 0 | ex.raise(); |
2483 | 0 | } |
2484 | 0 |
|
2485 | 0 | return *this; |
2486 | 0 | } |
2487 | | |
2488 | | /*! |
2489 | | * @brief This function deserializes a string with a different endianness. |
2490 | | * @param string_t The variable that will store the string read from the buffer. |
2491 | | * @param endianness Endianness that will be used in the serialization of this value. |
2492 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2493 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2494 | | */ |
2495 | | inline |
2496 | | Cdr& deserialize( |
2497 | | std::wstring& string_t, |
2498 | | Endianness endianness) |
2499 | 0 | { |
2500 | 0 | bool auxSwap = m_swapBytes; |
2501 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
2502 | 0 |
|
2503 | 0 | try |
2504 | 0 | { |
2505 | 0 | deserialize(string_t); |
2506 | 0 | m_swapBytes = auxSwap; |
2507 | 0 | } |
2508 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
2509 | 0 | { |
2510 | 0 | m_swapBytes = auxSwap; |
2511 | 0 | ex.raise(); |
2512 | 0 | } |
2513 | 0 |
|
2514 | 0 | return *this; |
2515 | 0 | } |
2516 | | |
2517 | | #if HAVE_CXX0X |
2518 | | /*! |
2519 | | * @brief This function template deserializes an array. |
2520 | | * @param array_t The variable that will store the array read from the buffer. |
2521 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2522 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2523 | | */ |
2524 | | template<class _T, size_t _Size> |
2525 | | inline Cdr& deserialize( |
2526 | | std::array<_T, _Size>& array_t) |
2527 | | { |
2528 | | return deserializeArray(array_t.data(), array_t.size()); |
2529 | | } |
2530 | | |
2531 | | /*! |
2532 | | * @brief This function template deserializes an array with a different endianness. |
2533 | | * @param array_t The variable that will store the array read from the buffer. |
2534 | | * @param endianness Endianness that will be used in the serialization of this value. |
2535 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2536 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2537 | | */ |
2538 | | template<class _T, size_t _Size> |
2539 | | inline Cdr& deserialize( |
2540 | | std::array<_T, _Size>& array_t, |
2541 | | Endianness endianness) |
2542 | | { |
2543 | | return deserializeArray(array_t.data(), array_t.size(), endianness); |
2544 | | } |
2545 | | |
2546 | | #endif // if HAVE_CXX0X |
2547 | | |
2548 | | #if !defined(_MSC_VER) && HAVE_CXX0X |
2549 | | /*! |
2550 | | * @brief This function template deserializes a sequence. |
2551 | | * @param vector_t The variable that will store the sequence read from the buffer. |
2552 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2553 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2554 | | */ |
2555 | | template<class _T = bool> |
2556 | | Cdr& deserialize( |
2557 | | std::vector<bool>& vector_t) |
2558 | | { |
2559 | | return deserializeBoolSequence(vector_t); |
2560 | | } |
2561 | | |
2562 | | #endif // if !defined(_MSC_VER) && HAVE_CXX0X |
2563 | | |
2564 | | /*! |
2565 | | * @brief This function template deserializes a sequence. |
2566 | | * @param vector_t The variable that will store the sequence read from the buffer. |
2567 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2568 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2569 | | */ |
2570 | | template<class _T> |
2571 | | Cdr& deserialize( |
2572 | | std::vector<_T>& vector_t) |
2573 | | { |
2574 | | uint32_t seqLength = 0; |
2575 | | state state_before_error(*this); |
2576 | | |
2577 | | *this >> seqLength; |
2578 | | |
2579 | | if (seqLength == 0) |
2580 | | { |
2581 | | vector_t.clear(); |
2582 | | return *this; |
2583 | | } |
2584 | | |
2585 | | if ((m_lastPosition - m_currentPosition) < seqLength) |
2586 | | { |
2587 | | setState(state_before_error); |
2588 | | throw eprosima::fastcdr::exception::NotEnoughMemoryException( |
2589 | | eprosima::fastcdr::exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); |
2590 | | } |
2591 | | |
2592 | | try |
2593 | | { |
2594 | | vector_t.resize(seqLength); |
2595 | | return deserializeArray(vector_t.data(), vector_t.size()); |
2596 | | } |
2597 | | catch (eprosima::fastcdr::exception::Exception& ex) |
2598 | | { |
2599 | | setState(state_before_error); |
2600 | | ex.raise(); |
2601 | | } |
2602 | | |
2603 | | return *this; |
2604 | | } |
2605 | | |
2606 | | /*! |
2607 | | * @brief This function template deserializes a map. |
2608 | | * @param map_t The variable that will store the map read from the buffer. |
2609 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2610 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2611 | | */ |
2612 | | template<class _K, class _T> |
2613 | | Cdr& deserialize( |
2614 | | std::map<_K, _T>& map_t) |
2615 | | { |
2616 | | uint32_t seqLength = 0; |
2617 | | state state_(*this); |
2618 | | |
2619 | | *this >> seqLength; |
2620 | | |
2621 | | try |
2622 | | { |
2623 | | for (uint32_t i = 0; i < seqLength; ++i) |
2624 | | { |
2625 | | _K key; |
2626 | | _T value; |
2627 | | *this >> key; |
2628 | | *this >> value; |
2629 | | map_t.emplace(std::pair<_K, _T>(std::move(key), std::move(value))); |
2630 | | } |
2631 | | } |
2632 | | catch (eprosima::fastcdr::exception::Exception& ex) |
2633 | | { |
2634 | | setState(state_); |
2635 | | ex.raise(); |
2636 | | } |
2637 | | |
2638 | | return *this; |
2639 | | } |
2640 | | |
2641 | | #ifdef _MSC_VER |
2642 | | /*! |
2643 | | * @brief This function template deserializes a sequence. |
2644 | | * @param vector_t The variable that will store the sequence read from the buffer. |
2645 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2646 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2647 | | */ |
2648 | | template<> |
2649 | | Cdr& deserialize<bool>( |
2650 | | std::vector<bool>& vector_t) |
2651 | | { |
2652 | | return deserializeBoolSequence(vector_t); |
2653 | | } |
2654 | | |
2655 | | #endif // ifdef _MSC_VER |
2656 | | |
2657 | | /*! |
2658 | | * @brief This function template deserializes a sequence with a different endianness. |
2659 | | * @param vector_t The variable that will store the sequence read from the buffer. |
2660 | | * @param endianness Endianness that will be used in the serialization of this value. |
2661 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2662 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2663 | | */ |
2664 | | template<class _T> |
2665 | | Cdr& deserialize( |
2666 | | std::vector<_T>& vector_t, |
2667 | | Endianness endianness) |
2668 | | { |
2669 | | bool auxSwap = m_swapBytes; |
2670 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
2671 | | |
2672 | | try |
2673 | | { |
2674 | | deserialize(vector_t); |
2675 | | m_swapBytes = auxSwap; |
2676 | | } |
2677 | | catch (exception::Exception& ex) |
2678 | | { |
2679 | | m_swapBytes = auxSwap; |
2680 | | ex.raise(); |
2681 | | } |
2682 | | |
2683 | | return *this; |
2684 | | } |
2685 | | |
2686 | | /*! |
2687 | | * @brief This function template deserializes a non-basic object. |
2688 | | * @param type_t The variable that will store the object read from the buffer. |
2689 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2690 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2691 | | */ |
2692 | | template<class _T> |
2693 | | inline Cdr& deserialize( |
2694 | | _T& type_t) |
2695 | | { |
2696 | | type_t.deserialize(*this); |
2697 | | return *this; |
2698 | | } |
2699 | | |
2700 | | /*! |
2701 | | * @brief This function deserializes an array of octets. |
2702 | | * @param octet_t The variable that will store the array of octets read from the buffer. |
2703 | | * @param numElements Number of the elements in the array. |
2704 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2705 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2706 | | */ |
2707 | | inline |
2708 | | Cdr& deserializeArray( |
2709 | | uint8_t* octet_t, |
2710 | | size_t numElements) |
2711 | 0 | { |
2712 | 0 | return deserializeArray(reinterpret_cast<char*>(octet_t), numElements); |
2713 | 0 | } |
2714 | | |
2715 | | /*! |
2716 | | * @brief This function deserializes an array of octets with a different endianness. |
2717 | | * @param octet_t The variable that will store the array of octets read from the buffer. |
2718 | | * @param numElements Number of the elements in the array. |
2719 | | * @param endianness Endianness that will be used in the serialization of this value. |
2720 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2721 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2722 | | */ |
2723 | | inline |
2724 | | Cdr& deserializeArray( |
2725 | | uint8_t* octet_t, |
2726 | | size_t numElements, |
2727 | | Endianness endianness) |
2728 | 0 | { |
2729 | 0 | return deserializeArray(reinterpret_cast<char*>(octet_t), numElements, endianness); |
2730 | 0 | } |
2731 | | |
2732 | | /*! |
2733 | | * @brief This function deserializes an array of characters. |
2734 | | * @param char_t The variable that will store the array of characters read from the buffer. |
2735 | | * @param numElements Number of the elements in the array. |
2736 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2737 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2738 | | */ |
2739 | | Cdr& deserializeArray( |
2740 | | char* char_t, |
2741 | | size_t numElements); |
2742 | | |
2743 | | /*! |
2744 | | * @brief This function deserializes an array of characters with a different endianness. |
2745 | | * @param char_t The variable that will store the array of characters read from the buffer. |
2746 | | * @param numElements Number of the elements in the array. |
2747 | | * @param endianness Endianness that will be used in the serialization of this value. |
2748 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2749 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2750 | | */ |
2751 | | inline |
2752 | | Cdr& deserializeArray( |
2753 | | char* char_t, |
2754 | | size_t numElements, |
2755 | | Endianness endianness) |
2756 | 0 | { |
2757 | 0 | (void) endianness; |
2758 | 0 | return deserializeArray(char_t, numElements); |
2759 | 0 | } |
2760 | | |
2761 | | /*! |
2762 | | * @brief This function deserializes an array of int8_t. |
2763 | | * @param int8 The variable that will store the array of int8_t read from the buffer. |
2764 | | * @param numElements Number of the elements in the array. |
2765 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2766 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2767 | | */ |
2768 | | inline |
2769 | | Cdr& deserializeArray( |
2770 | | int8_t* int8, |
2771 | | size_t numElements) |
2772 | 0 | { |
2773 | 0 | return deserializeArray(reinterpret_cast<char*>(int8), numElements); |
2774 | 0 | } |
2775 | | |
2776 | | /*! |
2777 | | * @brief This function deserializes an array of int8_t with a different endianness. |
2778 | | * @param int8 The variable that will store the array of int8_t read from the buffer. |
2779 | | * @param numElements Number of the elements in the array. |
2780 | | * @param endianness Endianness that will be used in the serialization of this value. |
2781 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2782 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2783 | | */ |
2784 | | inline |
2785 | | Cdr& deserializeArray( |
2786 | | int8_t* int8, |
2787 | | size_t numElements, |
2788 | | Endianness endianness) |
2789 | 0 | { |
2790 | 0 | return deserializeArray(reinterpret_cast<char*>(int8), numElements, endianness); |
2791 | 0 | } |
2792 | | |
2793 | | /*! |
2794 | | * @brief This function deserializes an array of unsigned shorts. |
2795 | | * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer. |
2796 | | * @param numElements Number of the elements in the array. |
2797 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2798 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2799 | | */ |
2800 | | inline |
2801 | | Cdr& deserializeArray( |
2802 | | uint16_t* ushort_t, |
2803 | | size_t numElements) |
2804 | 0 | { |
2805 | 0 | return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements); |
2806 | 0 | } |
2807 | | |
2808 | | /*! |
2809 | | * @brief This function deserializes an array of unsigned shorts with a different endianness. |
2810 | | * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer. |
2811 | | * @param numElements Number of the elements in the array. |
2812 | | * @param endianness Endianness that will be used in the serialization of this value. |
2813 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2814 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2815 | | */ |
2816 | | inline |
2817 | | Cdr& deserializeArray( |
2818 | | uint16_t* ushort_t, |
2819 | | size_t numElements, |
2820 | | Endianness endianness) |
2821 | 0 | { |
2822 | 0 | return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements, endianness); |
2823 | 0 | } |
2824 | | |
2825 | | /*! |
2826 | | * @brief This function deserializes an array of shorts. |
2827 | | * @param short_t The variable that will store the array of shorts read from the buffer. |
2828 | | * @param numElements Number of the elements in the array. |
2829 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2830 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2831 | | */ |
2832 | | Cdr& deserializeArray( |
2833 | | int16_t* short_t, |
2834 | | size_t numElements); |
2835 | | |
2836 | | /*! |
2837 | | * @brief This function deserializes an array of shorts with a different endianness. |
2838 | | * @param short_t The variable that will store the array of shorts read from the buffer. |
2839 | | * @param numElements Number of the elements in the array. |
2840 | | * @param endianness Endianness that will be used in the serialization of this value. |
2841 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2842 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2843 | | */ |
2844 | | Cdr& deserializeArray( |
2845 | | int16_t* short_t, |
2846 | | size_t numElements, |
2847 | | Endianness endianness); |
2848 | | |
2849 | | /*! |
2850 | | * @brief This function deserializes an array of unsigned longs. |
2851 | | * @param ulong_t The variable that will store the array of unsigned longs read from the buffer. |
2852 | | * @param numElements Number of the elements in the array. |
2853 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2854 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2855 | | */ |
2856 | | inline |
2857 | | Cdr& deserializeArray( |
2858 | | uint32_t* ulong_t, |
2859 | | size_t numElements) |
2860 | 0 | { |
2861 | 0 | return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements); |
2862 | 0 | } |
2863 | | |
2864 | | /*! |
2865 | | * @brief This function deserializes an array of unsigned longs with a different endianness. |
2866 | | * @param ulong_t The variable that will store the array of unsigned longs read from the buffer. |
2867 | | * @param numElements Number of the elements in the array. |
2868 | | * @param endianness Endianness that will be used in the serialization of this value. |
2869 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2870 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2871 | | */ |
2872 | | inline |
2873 | | Cdr& deserializeArray( |
2874 | | uint32_t* ulong_t, |
2875 | | size_t numElements, |
2876 | | Endianness endianness) |
2877 | 0 | { |
2878 | 0 | return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements, endianness); |
2879 | 0 | } |
2880 | | |
2881 | | /*! |
2882 | | * @brief This function deserializes an array of longs. |
2883 | | * @param long_t The variable that will store the array of longs read from the buffer. |
2884 | | * @param numElements Number of the elements in the array. |
2885 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2886 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2887 | | */ |
2888 | | Cdr& deserializeArray( |
2889 | | int32_t* long_t, |
2890 | | size_t numElements); |
2891 | | |
2892 | | /*! |
2893 | | * @brief This function deserializes an array of longs with a different endianness. |
2894 | | * @param long_t The variable that will store the array of longs read from the buffer. |
2895 | | * @param numElements Number of the elements in the array. |
2896 | | * @param endianness Endianness that will be used in the serialization of this value. |
2897 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2898 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2899 | | */ |
2900 | | Cdr& deserializeArray( |
2901 | | int32_t* long_t, |
2902 | | size_t numElements, |
2903 | | Endianness endianness); |
2904 | | |
2905 | | /*! |
2906 | | * @brief This function deserializes an array of wide-chars. |
2907 | | * @param wchar The variable that will store the array of wide-chars read from the buffer. |
2908 | | * @param numElements Number of the elements in the array. |
2909 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2910 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2911 | | */ |
2912 | | Cdr& deserializeArray( |
2913 | | wchar_t* wchar, |
2914 | | size_t numElements); |
2915 | | |
2916 | | /*! |
2917 | | * @brief This function deserializes an array of wide-chars with a different endianness. |
2918 | | * @param wchar The variable that will store the array of wide-chars read from the buffer. |
2919 | | * @param numElements Number of the elements in the array. |
2920 | | * @param endianness Endianness that will be used in the serialization of this value. |
2921 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2922 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2923 | | */ |
2924 | | Cdr& deserializeArray( |
2925 | | wchar_t* wchar, |
2926 | | size_t numElements, |
2927 | | Endianness endianness); |
2928 | | |
2929 | | /*! |
2930 | | * @brief This function deserializes an array of unsigned long longs. |
2931 | | * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer. |
2932 | | * @param numElements Number of the elements in the array. |
2933 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2934 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2935 | | */ |
2936 | | inline |
2937 | | Cdr& deserializeArray( |
2938 | | uint64_t* ulonglong_t, |
2939 | | size_t numElements) |
2940 | 0 | { |
2941 | 0 | return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements); |
2942 | 0 | } |
2943 | | |
2944 | | /*! |
2945 | | * @brief This function deserializes an array of unsigned long longs with a different endianness. |
2946 | | * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer. |
2947 | | * @param numElements Number of the elements in the array. |
2948 | | * @param endianness Endianness that will be used in the serialization of this value. |
2949 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2950 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2951 | | */ |
2952 | | inline |
2953 | | Cdr& deserializeArray( |
2954 | | uint64_t* ulonglong_t, |
2955 | | size_t numElements, |
2956 | | Endianness endianness) |
2957 | 0 | { |
2958 | 0 | return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements, endianness); |
2959 | 0 | } |
2960 | | |
2961 | | /*! |
2962 | | * @brief This function deserializes an array of long longs. |
2963 | | * @param longlong_t The variable that will store the array of long longs read from the buffer. |
2964 | | * @param numElements Number of the elements in the array. |
2965 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2966 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2967 | | */ |
2968 | | Cdr& deserializeArray( |
2969 | | int64_t* longlong_t, |
2970 | | size_t numElements); |
2971 | | |
2972 | | /*! |
2973 | | * @brief This function deserializes an array of long longs with a different endianness. |
2974 | | * @param longlong_t The variable that will store the array of long longs read from the buffer. |
2975 | | * @param numElements Number of the elements in the array. |
2976 | | * @param endianness Endianness that will be used in the serialization of this value. |
2977 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2978 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2979 | | */ |
2980 | | Cdr& deserializeArray( |
2981 | | int64_t* longlong_t, |
2982 | | size_t numElements, |
2983 | | Endianness endianness); |
2984 | | |
2985 | | /*! |
2986 | | * @brief This function deserializes an array of floats. |
2987 | | * @param float_t The variable that will store the array of floats read from the buffer. |
2988 | | * @param numElements Number of the elements in the array. |
2989 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
2990 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
2991 | | */ |
2992 | | Cdr& deserializeArray( |
2993 | | float* float_t, |
2994 | | size_t numElements); |
2995 | | |
2996 | | /*! |
2997 | | * @brief This function deserializes an array of floats with a different endianness. |
2998 | | * @param float_t The variable that will store the array of floats read from the buffer. |
2999 | | * @param numElements Number of the elements in the array. |
3000 | | * @param endianness Endianness that will be used in the serialization of this value. |
3001 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3002 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3003 | | */ |
3004 | | Cdr& deserializeArray( |
3005 | | float* float_t, |
3006 | | size_t numElements, |
3007 | | Endianness endianness); |
3008 | | |
3009 | | /*! |
3010 | | * @brief This function deserializes an array of doubles. |
3011 | | * @param double_t The variable that will store the array of doubles read from the buffer. |
3012 | | * @param numElements Number of the elements in the array. |
3013 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3014 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3015 | | */ |
3016 | | Cdr& deserializeArray( |
3017 | | double* double_t, |
3018 | | size_t numElements); |
3019 | | |
3020 | | /*! |
3021 | | * @brief This function deserializes an array of doubles with a different endianness. |
3022 | | * @param double_t The variable that will store the array of doubles read from the buffer. |
3023 | | * @param numElements Number of the elements in the array. |
3024 | | * @param endianness Endianness that will be used in the serialization of this value. |
3025 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3026 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3027 | | */ |
3028 | | Cdr& deserializeArray( |
3029 | | double* double_t, |
3030 | | size_t numElements, |
3031 | | Endianness endianness); |
3032 | | |
3033 | | /*! |
3034 | | * @brief This function deserializes an array of long doubles. |
3035 | | * @param ldouble_t The variable that will store the array of long doubles read from the buffer. |
3036 | | * @param numElements Number of the elements in the array. |
3037 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3038 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3039 | | */ |
3040 | | Cdr& deserializeArray( |
3041 | | long double* ldouble_t, |
3042 | | size_t numElements); |
3043 | | |
3044 | | /*! |
3045 | | * @brief This function deserializes an array of long doubles with a different endianness. |
3046 | | * @param ldouble_t The variable that will store the array of long doubles read from the buffer. |
3047 | | * @param numElements Number of the elements in the array. |
3048 | | * @param endianness Endianness that will be used in the serialization of this value. |
3049 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3050 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3051 | | */ |
3052 | | Cdr& deserializeArray( |
3053 | | long double* ldouble_t, |
3054 | | size_t numElements, |
3055 | | Endianness endianness); |
3056 | | |
3057 | | /*! |
3058 | | * @brief This function deserializes an array of booleans. |
3059 | | * @param bool_t The variable that will store the array of booleans read from the buffer. |
3060 | | * @param numElements Number of the elements in the array. |
3061 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3062 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3063 | | */ |
3064 | | Cdr& deserializeArray( |
3065 | | bool* bool_t, |
3066 | | size_t numElements); |
3067 | | |
3068 | | /*! |
3069 | | * @brief This function deserializes an array of booleans with a different endianness. |
3070 | | * @param bool_t The variable that will store the array of booleans read from the buffer. |
3071 | | * @param numElements Number of the elements in the array. |
3072 | | * @param endianness Endianness that will be used in the serialization of this value. |
3073 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3074 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3075 | | */ |
3076 | | inline |
3077 | | Cdr& deserializeArray( |
3078 | | bool* bool_t, |
3079 | | size_t numElements, |
3080 | | Endianness endianness) |
3081 | 0 | { |
3082 | 0 | (void) endianness; |
3083 | 0 | return deserializeArray(bool_t, numElements); |
3084 | 0 | } |
3085 | | |
3086 | | /*! |
3087 | | * @brief This function deserializes an array of strings. |
3088 | | * @param string_t The variable that will store the array of strings read from the buffer. |
3089 | | * @param numElements Number of the elements in the array. |
3090 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3091 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3092 | | */ |
3093 | | inline |
3094 | | Cdr& deserializeArray( |
3095 | | std::string* string_t, |
3096 | | size_t numElements) |
3097 | 0 | { |
3098 | 0 | for (size_t count = 0; count < numElements; ++count) |
3099 | 0 | { |
3100 | 0 | deserialize(string_t[count]); |
3101 | 0 | } |
3102 | 0 | return *this; |
3103 | 0 | } |
3104 | | |
3105 | | /*! |
3106 | | * @brief This function deserializes an array of wide-strings. |
3107 | | * @param string_t The variable that will store the array of wide-strings read from the buffer. |
3108 | | * @param numElements Number of the elements in the array. |
3109 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3110 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3111 | | */ |
3112 | | inline |
3113 | | Cdr& deserializeArray( |
3114 | | std::wstring* string_t, |
3115 | | size_t numElements) |
3116 | 0 | { |
3117 | 0 | for (size_t count = 0; count < numElements; ++count) |
3118 | 0 | { |
3119 | 0 | deserialize(string_t[count]); |
3120 | 0 | } |
3121 | 0 | return *this; |
3122 | 0 | } |
3123 | | |
3124 | | /*! |
3125 | | * @brief This function deserializes an array of strings with a different endianness. |
3126 | | * @param string_t The variable that will store the array of strings read from the buffer. |
3127 | | * @param numElements Number of the elements in the array. |
3128 | | * @param endianness Endianness that will be used in the serialization of this value. |
3129 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3130 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3131 | | */ |
3132 | | inline |
3133 | | Cdr& deserializeArray( |
3134 | | std::string* string_t, |
3135 | | size_t numElements, |
3136 | | Endianness endianness) |
3137 | 0 | { |
3138 | 0 | bool auxSwap = m_swapBytes; |
3139 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
3140 | 0 |
|
3141 | 0 | try |
3142 | 0 | { |
3143 | 0 | deserializeArray(string_t, numElements); |
3144 | 0 | m_swapBytes = auxSwap; |
3145 | 0 | } |
3146 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
3147 | 0 | { |
3148 | 0 | m_swapBytes = auxSwap; |
3149 | 0 | ex.raise(); |
3150 | 0 | } |
3151 | 0 |
|
3152 | 0 | return *this; |
3153 | 0 | } |
3154 | | |
3155 | | /*! |
3156 | | * @brief This function deserializes an array of wide-strings with a different endianness. |
3157 | | * @param string_t The variable that will store the array of wide-strings read from the buffer. |
3158 | | * @param numElements Number of the elements in the array. |
3159 | | * @param endianness Endianness that will be used in the serialization of this value. |
3160 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3161 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3162 | | */ |
3163 | | inline |
3164 | | Cdr& deserializeArray( |
3165 | | std::wstring* string_t, |
3166 | | size_t numElements, |
3167 | | Endianness endianness) |
3168 | 0 | { |
3169 | 0 | bool auxSwap = m_swapBytes; |
3170 | 0 | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
3171 | 0 |
|
3172 | 0 | try |
3173 | 0 | { |
3174 | 0 | deserializeArray(string_t, numElements); |
3175 | 0 | m_swapBytes = auxSwap; |
3176 | 0 | } |
3177 | 0 | catch (eprosima::fastcdr::exception::Exception& ex) |
3178 | 0 | { |
3179 | 0 | m_swapBytes = auxSwap; |
3180 | 0 | ex.raise(); |
3181 | 0 | } |
3182 | 0 |
|
3183 | 0 | return *this; |
3184 | 0 | } |
3185 | | |
3186 | | /*! |
3187 | | * @brief This function deserializes an array of sequences of objects. |
3188 | | * @param vector_t The variable that will store the array of sequences of objects read from the buffer. |
3189 | | * @param numElements Number of the elements in the array. |
3190 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3191 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3192 | | */ |
3193 | | template<class _T> |
3194 | | Cdr& deserializeArray( |
3195 | | std::vector<_T>* vector_t, |
3196 | | size_t numElements) |
3197 | | { |
3198 | | for (size_t count = 0; count < numElements; ++count) |
3199 | | { |
3200 | | deserialize(vector_t[count]); |
3201 | | } |
3202 | | return *this; |
3203 | | } |
3204 | | |
3205 | | /*! |
3206 | | * @brief This function template deserializes an array of non-basic objects. |
3207 | | * @param type_t The variable that will store the array of objects read from the buffer. |
3208 | | * @param numElements Number of the elements in the array. |
3209 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3210 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3211 | | */ |
3212 | | template<class _T> |
3213 | | Cdr& deserializeArray( |
3214 | | _T* type_t, |
3215 | | size_t numElements) |
3216 | | { |
3217 | | for (size_t count = 0; count < numElements; ++count) |
3218 | | { |
3219 | | type_t[count].deserialize(*this); |
3220 | | } |
3221 | | return *this; |
3222 | | } |
3223 | | |
3224 | | /*! |
3225 | | * @brief This function template deserializes an array of non-basic objects with a different endianness. |
3226 | | * @param type_t The variable that will store the array of objects read from the buffer. |
3227 | | * @param numElements Number of the elements in the array. |
3228 | | * @param endianness Endianness that will be used in the serialization of this value. |
3229 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3230 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3231 | | */ |
3232 | | template<class _T> |
3233 | | Cdr& deserializeArray( |
3234 | | _T* type_t, |
3235 | | size_t numElements, |
3236 | | Endianness endianness) |
3237 | | { |
3238 | | bool auxSwap = m_swapBytes; |
3239 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
3240 | | |
3241 | | try |
3242 | | { |
3243 | | deserializeArray(type_t, numElements); |
3244 | | m_swapBytes = auxSwap; |
3245 | | } |
3246 | | catch (eprosima::fastcdr::exception::Exception& ex) |
3247 | | { |
3248 | | m_swapBytes = auxSwap; |
3249 | | ex.raise(); |
3250 | | } |
3251 | | |
3252 | | return *this; |
3253 | | } |
3254 | | |
3255 | | #if !defined(_MSC_VER) && HAVE_CXX0X |
3256 | | /*! |
3257 | | * @brief This function template deserializes a string sequence. |
3258 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3259 | | * The user will have to free this allocated memory using free() |
3260 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3261 | | * @param numElements This variable return the number of elements of the sequence. |
3262 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3263 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3264 | | */ |
3265 | | template<class _T = std::string> |
3266 | | Cdr& deserializeSequence( |
3267 | | std::string*& sequence_t, |
3268 | | size_t& numElements) |
3269 | | { |
3270 | | return deserializeStringSequence(sequence_t, numElements); |
3271 | | } |
3272 | | |
3273 | | /*! |
3274 | | * @brief This function template deserializes a wide-string sequence. |
3275 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3276 | | * The user will have to free this allocated memory using free() |
3277 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3278 | | * @param numElements This variable return the number of elements of the sequence. |
3279 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3280 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3281 | | */ |
3282 | | template<class _T = std::wstring> |
3283 | | Cdr& deserializeSequence( |
3284 | | std::wstring*& sequence_t, |
3285 | | size_t& numElements) |
3286 | | { |
3287 | | return deserializeWStringSequence(sequence_t, numElements); |
3288 | | } |
3289 | | |
3290 | | #endif // if !defined(_MSC_VER) && HAVE_CXX0X |
3291 | | |
3292 | | /*! |
3293 | | * @brief This function template deserializes a raw sequence. |
3294 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3295 | | * The user will have to free this allocated memory using free() |
3296 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3297 | | * @param numElements This variable return the number of elements of the sequence. |
3298 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3299 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3300 | | */ |
3301 | | template<class _T> |
3302 | | Cdr& deserializeSequence( |
3303 | | _T*& sequence_t, |
3304 | | size_t& numElements) |
3305 | | { |
3306 | | uint32_t seqLength = 0; |
3307 | | state state_before_error(*this); |
3308 | | |
3309 | | deserialize(seqLength); |
3310 | | |
3311 | | try |
3312 | | { |
3313 | | sequence_t = reinterpret_cast<_T*>(calloc(seqLength, sizeof(_T))); |
3314 | | deserializeArray(sequence_t, seqLength); |
3315 | | } |
3316 | | catch (eprosima::fastcdr::exception::Exception& ex) |
3317 | | { |
3318 | | free(sequence_t); |
3319 | | sequence_t = NULL; |
3320 | | setState(state_before_error); |
3321 | | ex.raise(); |
3322 | | } |
3323 | | |
3324 | | numElements = seqLength; |
3325 | | return *this; |
3326 | | } |
3327 | | |
3328 | | #ifdef _MSC_VER |
3329 | | /*! |
3330 | | * @brief This function template deserializes a string sequence. |
3331 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3332 | | * The user will have to free this allocated memory using free() |
3333 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3334 | | * @param numElements This variable return the number of elements of the sequence. |
3335 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3336 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3337 | | */ |
3338 | | template<> |
3339 | | Cdr& deserializeSequence<std::string>( |
3340 | | std::string*& sequence_t, |
3341 | | size_t& numElements) |
3342 | | { |
3343 | | return deserializeStringSequence(sequence_t, numElements); |
3344 | | } |
3345 | | |
3346 | | /*! |
3347 | | * @brief This function template deserializes a wide-string sequence. |
3348 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3349 | | * The user will have to free this allocated memory using free() |
3350 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3351 | | * @param numElements This variable return the number of elements of the sequence. |
3352 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3353 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3354 | | */ |
3355 | | template<> |
3356 | | Cdr& deserializeSequence<std::wstring>( |
3357 | | std::wstring*& sequence_t, |
3358 | | size_t& numElements) |
3359 | | { |
3360 | | return deserializeWStringSequence(sequence_t, numElements); |
3361 | | } |
3362 | | |
3363 | | #endif // ifdef _MSC_VER |
3364 | | |
3365 | | /*! |
3366 | | * @brief This function template deserializes a raw sequence with a different endianness. |
3367 | | * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory. |
3368 | | * The user will have to free this allocated memory using free() |
3369 | | * @param sequence_t The pointer that will store the sequence read from the buffer. |
3370 | | * @param numElements This variable return the number of elements of the sequence. |
3371 | | * @param endianness Endianness that will be used in the deserialization of this value. |
3372 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3373 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3374 | | */ |
3375 | | template<class _T> |
3376 | | Cdr& deserializeSequence( |
3377 | | _T*& sequence_t, |
3378 | | size_t& numElements, |
3379 | | Endianness endianness) |
3380 | | { |
3381 | | bool auxSwap = m_swapBytes; |
3382 | | m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness)); |
3383 | | |
3384 | | try |
3385 | | { |
3386 | | deserializeSequence(sequence_t, numElements); |
3387 | | m_swapBytes = auxSwap; |
3388 | | } |
3389 | | catch (eprosima::fastcdr::exception::Exception& ex) |
3390 | | { |
3391 | | m_swapBytes = auxSwap; |
3392 | | ex.raise(); |
3393 | | } |
3394 | | |
3395 | | return *this; |
3396 | | } |
3397 | | |
3398 | | private: |
3399 | | |
3400 | | Cdr( |
3401 | | const Cdr&) = delete; |
3402 | | |
3403 | | Cdr& operator =( |
3404 | | const Cdr&) = delete; |
3405 | | |
3406 | | Cdr& serializeBoolSequence( |
3407 | | const std::vector<bool>& vector_t); |
3408 | | |
3409 | | Cdr& deserializeBoolSequence( |
3410 | | std::vector<bool>& vector_t); |
3411 | | |
3412 | | Cdr& deserializeStringSequence( |
3413 | | std::string*& sequence_t, |
3414 | | size_t& numElements); |
3415 | | |
3416 | | Cdr& deserializeWStringSequence( |
3417 | | std::wstring*& sequence_t, |
3418 | | size_t& numElements); |
3419 | | |
3420 | | #if HAVE_CXX0X |
3421 | | /*! |
3422 | | * @brief This function template detects the content type of the STD container array and serializes the array. |
3423 | | * @param array_t The array that will be serialized in the buffer. |
3424 | | * @param numElements Number of the elements in the array. |
3425 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3426 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
3427 | | */ |
3428 | | template<class _T, size_t _Size> |
3429 | | Cdr& serializeArray( |
3430 | | const std::array<_T, _Size>* array_t, |
3431 | | size_t numElements) |
3432 | | { |
3433 | | return serializeArray(array_t->data(), numElements * array_t->size()); |
3434 | | } |
3435 | | |
3436 | | /*! |
3437 | | * @brief This function template detects the content type of the STD container array and serializes the array with a different endianness. |
3438 | | * @param array_t The array that will be serialized in the buffer. |
3439 | | * @param numElements Number of the elements in the array. |
3440 | | * @param endianness Endianness that will be used in the serialization of this value. |
3441 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3442 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. |
3443 | | */ |
3444 | | template<class _T, size_t _Size> |
3445 | | Cdr& serializeArray( |
3446 | | const std::array<_T, _Size>* array_t, |
3447 | | size_t numElements, |
3448 | | Endianness endianness) |
3449 | | { |
3450 | | return serializeArray(array_t->data(), numElements * array_t->size(), endianness); |
3451 | | } |
3452 | | |
3453 | | /*! |
3454 | | * @brief This function template detects the content type of the STD container array and deserializes the array. |
3455 | | * @param array_t The variable that will store the array read from the buffer. |
3456 | | * @param numElements Number of the elements in the array. |
3457 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3458 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3459 | | */ |
3460 | | template<class _T, size_t _Size> |
3461 | | Cdr& deserializeArray( |
3462 | | std::array<_T, _Size>* array_t, |
3463 | | size_t numElements) |
3464 | | { |
3465 | | return deserializeArray(array_t->data(), numElements * array_t->size()); |
3466 | | } |
3467 | | |
3468 | | /*! |
3469 | | * @brief This function template detects the content type of STD container array and deserializes the array with a different endianness. |
3470 | | * @param array_t The variable that will store the array read from the buffer. |
3471 | | * @param numElements Number of the elements in the array. |
3472 | | * @param endianness Endianness that will be used in the serialization of this value. |
3473 | | * @return Reference to the eprosima::fastcdr::Cdr object. |
3474 | | * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. |
3475 | | */ |
3476 | | template<class _T, size_t _Size> |
3477 | | Cdr& deserializeArray( |
3478 | | std::array<_T, _Size>* array_t, |
3479 | | size_t numElements, |
3480 | | Endianness endianness) |
3481 | | { |
3482 | | return deserializeArray(array_t->data(), numElements * array_t->size(), endianness); |
3483 | | } |
3484 | | |
3485 | | #endif // if HAVE_CXX0X |
3486 | | |
3487 | | /*! |
3488 | | * @brief This function returns the extra bytes regarding the allignment. |
3489 | | * @param dataSize The size of the data that will be serialized. |
3490 | | * @return The size needed for the aligment. |
3491 | | */ |
3492 | | inline size_t alignment( |
3493 | | size_t dataSize) const |
3494 | 0 | { |
3495 | 0 | return dataSize > |
3496 | 0 | m_lastDataSize ? (dataSize - ((m_currentPosition - m_alignPosition) % dataSize)) & |
3497 | 0 | (dataSize - 1) : 0; |
3498 | 0 | } |
3499 | | |
3500 | | /*! |
3501 | | * @brief This function jumps the number of bytes of the alignment. These bytes should be calculated with the function eprosima::fastcdr::Cdr::alignment. |
3502 | | * @param align The number of bytes to be skipped. |
3503 | | */ |
3504 | | inline void makeAlign( |
3505 | | size_t align) |
3506 | 0 | { |
3507 | 0 | m_currentPosition += align; |
3508 | 0 | } |
3509 | | |
3510 | | /*! |
3511 | | * @brief This function resizes the internal buffer. It only applies if the FastBuffer object was created with the default constructor. |
3512 | | * @param minSizeInc Minimun size increase for the internal buffer |
3513 | | * @return True if the resize was succesful, false if it was not |
3514 | | */ |
3515 | | bool resize( |
3516 | | size_t minSizeInc); |
3517 | | |
3518 | | //TODO |
3519 | | const char* readString( |
3520 | | uint32_t& length); |
3521 | | const std::wstring readWString( |
3522 | | uint32_t& length); |
3523 | | |
3524 | | //! @brief Reference to the buffer that will be serialized/deserialized. |
3525 | | FastBuffer& m_cdrBuffer; |
3526 | | |
3527 | | //! @brief The type of CDR that will be use in serialization/deserialization. |
3528 | | CdrType m_cdrType; |
3529 | | |
3530 | | //! @brief Using DDS_CDR type, this attribute stores if the stream buffer contains a parameter list or not. |
3531 | | DDSCdrPlFlag m_plFlag; |
3532 | | |
3533 | | //! @brief This attribute stores the option flags when the CDR type is DDS_CDR; |
3534 | | uint16_t m_options; |
3535 | | |
3536 | | //! @brief The endianness that will be applied over the buffer. |
3537 | | uint8_t m_endianness; |
3538 | | |
3539 | | //! @brief This attribute specifies if it is needed to swap the bytes. |
3540 | | bool m_swapBytes; |
3541 | | |
3542 | | //! @brief Stores the last datasize serialized/deserialized. It's used to optimize. |
3543 | | size_t m_lastDataSize; |
3544 | | |
3545 | | //! @brief The current position in the serialization/deserialization process. |
3546 | | FastBuffer::iterator m_currentPosition; |
3547 | | |
3548 | | //! @brief The position from where the aligment is calculated. |
3549 | | FastBuffer::iterator m_alignPosition; |
3550 | | |
3551 | | //! @brief The last position in the buffer; |
3552 | | FastBuffer::iterator m_lastPosition; |
3553 | | }; |
3554 | | } //namespace fastcdr |
3555 | | } //namespace eprosima |
3556 | | |
3557 | | #endif // _CDR_CDR_H_ |