Cdr.h 172 KB

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