| Directory: | ./ |
|---|---|
| File: | tmp_project/DataStream/src/data_stream_message.cpp |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 235 | 235 | 100.0% |
| Branches: | 7 | 11 | 63.6% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | |||
| 8 | #include "data_stream_message.h" | ||
| 9 | |||
| 10 | |||
| 11 | ///Read the bool in the message | ||
| 12 | /** @param[out] ds : message to be read | ||
| 13 | * @param[out] data : data to be set | ||
| 14 | * @return true on success, false otherwise | ||
| 15 | */ | ||
| 16 | 1 | bool DataStream<char*, DataStreamMode::READ, bool>::data_stream(char* & ds, bool & data){ | |
| 17 | 1 | char* srcByte = (char*)&data; | |
| 18 | 1 | memcpy(srcByte, ds, sizeof(bool)); | |
| 19 | 1 | ds += sizeof(bool); | |
| 20 | 1 | return true; | |
| 21 | } | ||
| 22 | |||
| 23 | ///Read the bool in the message | ||
| 24 | /** @param[out] ds : message to be read | ||
| 25 | * @param[out] data : data to be set | ||
| 26 | * @param nbElement : number of element of the data | ||
| 27 | * @return true on success, false otherwise | ||
| 28 | */ | ||
| 29 | 98 | bool DataStream<char*, DataStreamMode::READ, bool>::data_stream(char* & ds, bool * data, size_t nbElement){ | |
| 30 | 98 | char* srcByte = (char*)data; | |
| 31 | 98 | memcpy(srcByte, ds, sizeof(bool)*nbElement); | |
| 32 | 98 | ds += sizeof(bool)*nbElement; | |
| 33 | 98 | return true; | |
| 34 | } | ||
| 35 | |||
| 36 | ///Save the bool in the message | ||
| 37 | /** @param[out] ds : message to be written | ||
| 38 | * @param data : data to be saved in the message | ||
| 39 | * @return true on success, false otherwise | ||
| 40 | */ | ||
| 41 | 1 | bool DataStream<char*, DataStreamMode::WRITE, bool>::data_stream(char* & ds, bool & data){ | |
| 42 | 1 | const char* srcByte = (const char*)&data; | |
| 43 | 1 | memcpy(ds, srcByte, sizeof(bool)); | |
| 44 | 1 | ds += sizeof(bool); | |
| 45 | 1 | return true; | |
| 46 | } | ||
| 47 | |||
| 48 | ///Save the bool in the message | ||
| 49 | /** @param[out] ds : message to be written | ||
| 50 | * @param data : data to be saved in the message | ||
| 51 | * @param nbElement : number of element of the data | ||
| 52 | * @return true on success, false otherwise | ||
| 53 | */ | ||
| 54 | 98 | bool DataStream<char*, DataStreamMode::WRITE, bool>::data_stream(char* & ds, bool * data, size_t nbElement){ | |
| 55 | 98 | const char* srcByte = (const char*)data; | |
| 56 | 98 | memcpy(ds, srcByte, sizeof(bool)*nbElement); | |
| 57 | 98 | ds += sizeof(bool)*nbElement; | |
| 58 | 98 | return true; | |
| 59 | } | ||
| 60 | |||
| 61 | ///Read the char in the message | ||
| 62 | /** @param[out] ds : message to be read | ||
| 63 | * @param[out] data : data to be set | ||
| 64 | * @return true on success, false otherwise | ||
| 65 | */ | ||
| 66 | 61 | bool DataStream<char*, DataStreamMode::READ, char>::data_stream(char* & ds, char & data){ | |
| 67 | 61 | char* srcByte = (char*)&data; | |
| 68 | 61 | memcpy(srcByte, ds, sizeof(char)); | |
| 69 | 61 | ds += sizeof(char); | |
| 70 | 61 | return true; | |
| 71 | } | ||
| 72 | |||
| 73 | ///Read the char in the message | ||
| 74 | /** @param[out] ds : message to be read | ||
| 75 | * @param[out] data : data to be set | ||
| 76 | * @param nbElement : number of element of the data | ||
| 77 | * @return true on success, false otherwise | ||
| 78 | */ | ||
| 79 | 98 | bool DataStream<char*, DataStreamMode::READ, char>::data_stream(char* & ds, char * data, size_t nbElement){ | |
| 80 | 98 | char* srcByte = (char*)data; | |
| 81 | 98 | memcpy(srcByte, ds, sizeof(char)*nbElement); | |
| 82 | 98 | ds += sizeof(char)*nbElement; | |
| 83 | 98 | return true; | |
| 84 | } | ||
| 85 | |||
| 86 | ///Save the char in the message | ||
| 87 | /** @param[out] ds : message to be written | ||
| 88 | * @param data : data to be saved in the message | ||
| 89 | * @return true on success, false otherwise | ||
| 90 | */ | ||
| 91 | 60 | bool DataStream<char*, DataStreamMode::WRITE, char>::data_stream(char* & ds, char & data){ | |
| 92 | 60 | const char* srcByte = (const char*)&data; | |
| 93 | 60 | memcpy(ds, srcByte, sizeof(char)); | |
| 94 | 60 | ds += sizeof(char); | |
| 95 | 60 | return true; | |
| 96 | } | ||
| 97 | |||
| 98 | ///Save the char in the message | ||
| 99 | /** @param[out] ds : message to be written | ||
| 100 | * @param data : data to be saved in the message | ||
| 101 | * @param nbElement : number of element of the data | ||
| 102 | * @return true on success, false otherwise | ||
| 103 | */ | ||
| 104 | 98 | bool DataStream<char*, DataStreamMode::WRITE, char>::data_stream(char* & ds, char * data, size_t nbElement){ | |
| 105 | 98 | const char* srcByte = (const char*)data; | |
| 106 | 98 | memcpy(ds, srcByte, sizeof(char)*nbElement); | |
| 107 | 98 | ds += sizeof(char)*nbElement; | |
| 108 | 98 | return true; | |
| 109 | } | ||
| 110 | |||
| 111 | ///Read the short in the message | ||
| 112 | /** @param[out] ds : message to be read | ||
| 113 | * @param[out] data : data to be set | ||
| 114 | * @return true on success, false otherwise | ||
| 115 | */ | ||
| 116 | 61 | bool DataStream<char*, DataStreamMode::READ, short>::data_stream(char* & ds, short & data){ | |
| 117 | 61 | char* srcByte = (char*)&data; | |
| 118 | 61 | memcpy(srcByte, ds, sizeof(short)); | |
| 119 | 61 | ds += sizeof(short); | |
| 120 | 61 | return true; | |
| 121 | } | ||
| 122 | |||
| 123 | ///Read the short in the message | ||
| 124 | /** @param[out] ds : message to be read | ||
| 125 | * @param[out] data : data to be set | ||
| 126 | * @param nbElement : number of element of the data | ||
| 127 | * @return true on success, false otherwise | ||
| 128 | */ | ||
| 129 | 98 | bool DataStream<char*, DataStreamMode::READ, short>::data_stream(char* & ds, short * data, size_t nbElement){ | |
| 130 | 98 | char* srcByte = (char*)data; | |
| 131 | 98 | memcpy(srcByte, ds, sizeof(short)*nbElement); | |
| 132 | 98 | ds += sizeof(short)*nbElement; | |
| 133 | 98 | return true; | |
| 134 | } | ||
| 135 | |||
| 136 | ///Save the short in the message | ||
| 137 | /** @param[out] ds : message to be written | ||
| 138 | * @param data : data to be saved in the message | ||
| 139 | * @return true on success, false otherwise | ||
| 140 | */ | ||
| 141 | 60 | bool DataStream<char*, DataStreamMode::WRITE, short>::data_stream(char* & ds, short & data){ | |
| 142 | 60 | const char* srcByte = (const char*)&data; | |
| 143 | 60 | memcpy(ds, srcByte, sizeof(short)); | |
| 144 | 60 | ds += sizeof(short); | |
| 145 | 60 | return true; | |
| 146 | } | ||
| 147 | |||
| 148 | ///Save the short in the message | ||
| 149 | /** @param[out] ds : message to be written | ||
| 150 | * @param data : data to be saved in the message | ||
| 151 | * @param nbElement : number of element of the data | ||
| 152 | * @return true on success, false otherwise | ||
| 153 | */ | ||
| 154 | 98 | bool DataStream<char*, DataStreamMode::WRITE, short>::data_stream(char* & ds, short * data, size_t nbElement){ | |
| 155 | 98 | const char* srcByte = (const char*)data; | |
| 156 | 98 | memcpy(ds, srcByte, sizeof(short)*nbElement); | |
| 157 | 98 | ds += sizeof(short)*nbElement; | |
| 158 | 98 | return true; | |
| 159 | } | ||
| 160 | |||
| 161 | ///Read the int in the message | ||
| 162 | /** @param[out] ds : message to be read | ||
| 163 | * @param[out] data : data to be set | ||
| 164 | * @return true on success, false otherwise | ||
| 165 | */ | ||
| 166 | 62 | bool DataStream<char*, DataStreamMode::READ, int>::data_stream(char* & ds, int & data){ | |
| 167 | 62 | char* srcByte = (char*)&data; | |
| 168 | 62 | memcpy(srcByte, ds, sizeof(int)); | |
| 169 | 62 | ds += sizeof(int); | |
| 170 | 62 | return true; | |
| 171 | } | ||
| 172 | |||
| 173 | ///Read the int in the message | ||
| 174 | /** @param[out] ds : message to be read | ||
| 175 | * @param[out] data : data to be set | ||
| 176 | * @param nbElement : number of element of the data | ||
| 177 | * @return true on success, false otherwise | ||
| 178 | */ | ||
| 179 | 98 | bool DataStream<char*, DataStreamMode::READ, int>::data_stream(char* & ds, int * data, size_t nbElement){ | |
| 180 | 98 | char* srcByte = (char*)data; | |
| 181 | 98 | memcpy(srcByte, ds, sizeof(int)*nbElement); | |
| 182 | 98 | ds += sizeof(int)*nbElement; | |
| 183 | 98 | return true; | |
| 184 | } | ||
| 185 | |||
| 186 | ///Save the int in the message | ||
| 187 | /** @param[out] ds : message to be written | ||
| 188 | * @param data : data to be saved in the message | ||
| 189 | * @return true on success, false otherwise | ||
| 190 | */ | ||
| 191 | 84 | bool DataStream<char*, DataStreamMode::WRITE, int>::data_stream(char* & ds, int & data){ | |
| 192 | 84 | const char* srcByte = (const char*)&data; | |
| 193 | 84 | memcpy(ds, srcByte, sizeof(int)); | |
| 194 | 84 | ds += sizeof(int); | |
| 195 | 84 | return true; | |
| 196 | } | ||
| 197 | |||
| 198 | ///Save the int in the message | ||
| 199 | /** @param[out] ds : message to be written | ||
| 200 | * @param data : data to be saved in the message | ||
| 201 | * @param nbElement : number of element of the data | ||
| 202 | * @return true on success, false otherwise | ||
| 203 | */ | ||
| 204 | 98 | bool DataStream<char*, DataStreamMode::WRITE, int>::data_stream(char* & ds, int * data, size_t nbElement){ | |
| 205 | 98 | const char* srcByte = (const char*)data; | |
| 206 | 98 | memcpy(ds, srcByte, sizeof(int)*nbElement); | |
| 207 | 98 | ds += sizeof(int)*nbElement; | |
| 208 | 98 | return true; | |
| 209 | } | ||
| 210 | |||
| 211 | ///Read the long int in the message | ||
| 212 | /** @param[out] ds : message to be read | ||
| 213 | * @param[out] data : data to be set | ||
| 214 | * @return true on success, false otherwise | ||
| 215 | */ | ||
| 216 | 61 | bool DataStream<char*, DataStreamMode::READ, long int>::data_stream(char* & ds, long int & data){ | |
| 217 | 61 | char* srcByte = (char*)&data; | |
| 218 | 61 | memcpy(srcByte, ds, sizeof(long int)); | |
| 219 | 61 | ds += sizeof(long int); | |
| 220 | 61 | return true; | |
| 221 | } | ||
| 222 | |||
| 223 | ///Read the long int in the message | ||
| 224 | /** @param[out] ds : message to be read | ||
| 225 | * @param[out] data : data to be set | ||
| 226 | * @param nbElement : number of element of the data | ||
| 227 | * @return true on success, false otherwise | ||
| 228 | */ | ||
| 229 | 98 | bool DataStream<char*, DataStreamMode::READ, long int>::data_stream(char* & ds, long int * data, size_t nbElement){ | |
| 230 | 98 | char* srcByte = (char*)data; | |
| 231 | 98 | memcpy(srcByte, ds, sizeof(long int)*nbElement); | |
| 232 | 98 | ds += sizeof(long int)*nbElement; | |
| 233 | 98 | return true; | |
| 234 | } | ||
| 235 | |||
| 236 | ///Save the long int in the message | ||
| 237 | /** @param[out] ds : message to be written | ||
| 238 | * @param data : data to be saved in the message | ||
| 239 | * @return true on success, false otherwise | ||
| 240 | */ | ||
| 241 | 61 | bool DataStream<char*, DataStreamMode::WRITE, long int>::data_stream(char* & ds, long int & data){ | |
| 242 | 61 | const char* srcByte = (const char*)&data; | |
| 243 | 61 | memcpy(ds, srcByte, sizeof(long int)); | |
| 244 | 61 | ds += sizeof(long int); | |
| 245 | 61 | return true; | |
| 246 | } | ||
| 247 | |||
| 248 | ///Save the long int in the message | ||
| 249 | /** @param[out] ds : message to be written | ||
| 250 | * @param data : data to be saved in the message | ||
| 251 | * @param nbElement : number of element of the data | ||
| 252 | * @return true on success, false otherwise | ||
| 253 | */ | ||
| 254 | 98 | bool DataStream<char*, DataStreamMode::WRITE, long int>::data_stream(char* & ds, long int * data, size_t nbElement){ | |
| 255 | 98 | const char* srcByte = (const char*)data; | |
| 256 | 98 | memcpy(ds, srcByte, sizeof(long int)*nbElement); | |
| 257 | 98 | ds += sizeof(long int)*nbElement; | |
| 258 | 98 | return true; | |
| 259 | } | ||
| 260 | |||
| 261 | ///Read the unsigned char in the message | ||
| 262 | /** @param[out] ds : message to be read | ||
| 263 | * @param[out] data : data to be set | ||
| 264 | * @return true on success, false otherwise | ||
| 265 | */ | ||
| 266 | 61 | bool DataStream<char*, DataStreamMode::READ, unsigned char>::data_stream(char* & ds, unsigned char & data){ | |
| 267 | 61 | char* srcByte = (char*)&data; | |
| 268 | 61 | memcpy(srcByte, ds, sizeof(unsigned char)); | |
| 269 | 61 | ds += sizeof(unsigned char); | |
| 270 | 61 | return true; | |
| 271 | } | ||
| 272 | |||
| 273 | ///Read the unsigned char in the message | ||
| 274 | /** @param[out] ds : message to be read | ||
| 275 | * @param[out] data : data to be set | ||
| 276 | * @param nbElement : number of element of the data | ||
| 277 | * @return true on success, false otherwise | ||
| 278 | */ | ||
| 279 | 98 | bool DataStream<char*, DataStreamMode::READ, unsigned char>::data_stream(char* & ds, unsigned char * data, size_t nbElement){ | |
| 280 | 98 | char* srcByte = (char*)data; | |
| 281 | 98 | memcpy(srcByte, ds, sizeof(unsigned char)*nbElement); | |
| 282 | 98 | ds += sizeof(unsigned char)*nbElement; | |
| 283 | 98 | return true; | |
| 284 | } | ||
| 285 | |||
| 286 | ///Save the unsigned char in the message | ||
| 287 | /** @param[out] ds : message to be written | ||
| 288 | * @param data : data to be saved in the message | ||
| 289 | * @return true on success, false otherwise | ||
| 290 | */ | ||
| 291 | 60 | bool DataStream<char*, DataStreamMode::WRITE, unsigned char>::data_stream(char* & ds, unsigned char & data){ | |
| 292 | 60 | const char* srcByte = (const char*)&data; | |
| 293 | 60 | memcpy(ds, srcByte, sizeof(unsigned char)); | |
| 294 | 60 | ds += sizeof(unsigned char); | |
| 295 | 60 | return true; | |
| 296 | } | ||
| 297 | |||
| 298 | ///Save the unsigned char in the message | ||
| 299 | /** @param[out] ds : message to be written | ||
| 300 | * @param data : data to be saved in the message | ||
| 301 | * @param nbElement : number of element of the data | ||
| 302 | * @return true on success, false otherwise | ||
| 303 | */ | ||
| 304 | 98 | bool DataStream<char*, DataStreamMode::WRITE, unsigned char>::data_stream(char* & ds, unsigned char * data, size_t nbElement){ | |
| 305 | 98 | const char* srcByte = (const char*)data; | |
| 306 | 98 | memcpy(ds, srcByte, sizeof(unsigned char)*nbElement); | |
| 307 | 98 | ds += sizeof(unsigned char)*nbElement; | |
| 308 | 98 | return true; | |
| 309 | } | ||
| 310 | |||
| 311 | ///Read the unsigned short in the message | ||
| 312 | /** @param[out] ds : message to be read | ||
| 313 | * @param[out] data : data to be set | ||
| 314 | * @return true on success, false otherwise | ||
| 315 | */ | ||
| 316 | 61 | bool DataStream<char*, DataStreamMode::READ, unsigned short>::data_stream(char* & ds, unsigned short & data){ | |
| 317 | 61 | char* srcByte = (char*)&data; | |
| 318 | 61 | memcpy(srcByte, ds, sizeof(unsigned short)); | |
| 319 | 61 | ds += sizeof(unsigned short); | |
| 320 | 61 | return true; | |
| 321 | } | ||
| 322 | |||
| 323 | ///Read the unsigned short in the message | ||
| 324 | /** @param[out] ds : message to be read | ||
| 325 | * @param[out] data : data to be set | ||
| 326 | * @param nbElement : number of element of the data | ||
| 327 | * @return true on success, false otherwise | ||
| 328 | */ | ||
| 329 | 98 | bool DataStream<char*, DataStreamMode::READ, unsigned short>::data_stream(char* & ds, unsigned short * data, size_t nbElement){ | |
| 330 | 98 | char* srcByte = (char*)data; | |
| 331 | 98 | memcpy(srcByte, ds, sizeof(unsigned short)*nbElement); | |
| 332 | 98 | ds += sizeof(unsigned short)*nbElement; | |
| 333 | 98 | return true; | |
| 334 | } | ||
| 335 | |||
| 336 | ///Save the unsigned short in the message | ||
| 337 | /** @param[out] ds : message to be written | ||
| 338 | * @param data : data to be saved in the message | ||
| 339 | * @return true on success, false otherwise | ||
| 340 | */ | ||
| 341 | 60 | bool DataStream<char*, DataStreamMode::WRITE, unsigned short>::data_stream(char* & ds, unsigned short & data){ | |
| 342 | 60 | const char* srcByte = (const char*)&data; | |
| 343 | 60 | memcpy(ds, srcByte, sizeof(unsigned short)); | |
| 344 | 60 | ds += sizeof(unsigned short); | |
| 345 | 60 | return true; | |
| 346 | } | ||
| 347 | |||
| 348 | ///Save the unsigned short in the message | ||
| 349 | /** @param[out] ds : message to be written | ||
| 350 | * @param data : data to be saved in the message | ||
| 351 | * @param nbElement : number of element of the data | ||
| 352 | * @return true on success, false otherwise | ||
| 353 | */ | ||
| 354 | 98 | bool DataStream<char*, DataStreamMode::WRITE, unsigned short>::data_stream(char* & ds, unsigned short * data, size_t nbElement){ | |
| 355 | 98 | const char* srcByte = (const char*)data; | |
| 356 | 98 | memcpy(ds, srcByte, sizeof(unsigned short)*nbElement); | |
| 357 | 98 | ds += sizeof(unsigned short)*nbElement; | |
| 358 | 98 | return true; | |
| 359 | } | ||
| 360 | |||
| 361 | ///Read the unsigned int in the message | ||
| 362 | /** @param[out] ds : message to be read | ||
| 363 | * @param[out] data : data to be set | ||
| 364 | * @return true on success, false otherwise | ||
| 365 | */ | ||
| 366 | 61 | bool DataStream<char*, DataStreamMode::READ, unsigned int>::data_stream(char* & ds, unsigned int & data){ | |
| 367 | 61 | char* srcByte = (char*)&data; | |
| 368 | 61 | memcpy(srcByte, ds, sizeof(unsigned int)); | |
| 369 | 61 | ds += sizeof(unsigned int); | |
| 370 | 61 | return true; | |
| 371 | } | ||
| 372 | |||
| 373 | ///Read the unsigned int in the message | ||
| 374 | /** @param[out] ds : message to be read | ||
| 375 | * @param[out] data : data to be set | ||
| 376 | * @param nbElement : number of element of the data | ||
| 377 | * @return true on success, false otherwise | ||
| 378 | */ | ||
| 379 | 98 | bool DataStream<char*, DataStreamMode::READ, unsigned int>::data_stream(char* & ds, unsigned int * data, size_t nbElement){ | |
| 380 | 98 | char* srcByte = (char*)data; | |
| 381 | 98 | memcpy(srcByte, ds, sizeof(unsigned int)*nbElement); | |
| 382 | 98 | ds += sizeof(unsigned int)*nbElement; | |
| 383 | 98 | return true; | |
| 384 | } | ||
| 385 | |||
| 386 | ///Save the unsigned int in the message | ||
| 387 | /** @param[out] ds : message to be written | ||
| 388 | * @param data : data to be saved in the message | ||
| 389 | * @return true on success, false otherwise | ||
| 390 | */ | ||
| 391 | 63 | bool DataStream<char*, DataStreamMode::WRITE, unsigned int>::data_stream(char* & ds, unsigned int & data){ | |
| 392 | 63 | const char* srcByte = (const char*)&data; | |
| 393 | 63 | memcpy(ds, srcByte, sizeof(unsigned int)); | |
| 394 | 63 | ds += sizeof(unsigned int); | |
| 395 | 63 | return true; | |
| 396 | } | ||
| 397 | |||
| 398 | ///Save the unsigned int in the message | ||
| 399 | /** @param[out] ds : message to be written | ||
| 400 | * @param data : data to be saved in the message | ||
| 401 | * @param nbElement : number of element of the data | ||
| 402 | * @return true on success, false otherwise | ||
| 403 | */ | ||
| 404 | 98 | bool DataStream<char*, DataStreamMode::WRITE, unsigned int>::data_stream(char* & ds, unsigned int * data, size_t nbElement){ | |
| 405 | 98 | const char* srcByte = (const char*)data; | |
| 406 | 98 | memcpy(ds, srcByte, sizeof(unsigned int)*nbElement); | |
| 407 | 98 | ds += sizeof(unsigned int)*nbElement; | |
| 408 | 98 | return true; | |
| 409 | } | ||
| 410 | |||
| 411 | ///Read the long unsigned int in the message | ||
| 412 | /** @param[out] ds : message to be read | ||
| 413 | * @param[out] data : data to be set | ||
| 414 | * @return true on success, false otherwise | ||
| 415 | */ | ||
| 416 | 115 | bool DataStream<char*, DataStreamMode::READ, long unsigned int>::data_stream(char* & ds, long unsigned int & data){ | |
| 417 | 115 | char* srcByte = (char*)&data; | |
| 418 | 115 | memcpy(srcByte, ds, sizeof(long unsigned int)); | |
| 419 | 115 | ds += sizeof(long unsigned int); | |
| 420 | 115 | return true; | |
| 421 | } | ||
| 422 | |||
| 423 | ///Read the long unsigned int in the message | ||
| 424 | /** @param[out] ds : message to be read | ||
| 425 | * @param[out] data : data to be set | ||
| 426 | * @param nbElement : number of element of the data | ||
| 427 | * @return true on success, false otherwise | ||
| 428 | */ | ||
| 429 | 98 | bool DataStream<char*, DataStreamMode::READ, long unsigned int>::data_stream(char* & ds, long unsigned int * data, size_t nbElement){ | |
| 430 | 98 | char* srcByte = (char*)data; | |
| 431 | 98 | memcpy(srcByte, ds, sizeof(long unsigned int)*nbElement); | |
| 432 | 98 | ds += sizeof(long unsigned int)*nbElement; | |
| 433 | 98 | return true; | |
| 434 | } | ||
| 435 | |||
| 436 | ///Save the long unsigned int in the message | ||
| 437 | /** @param[out] ds : message to be written | ||
| 438 | * @param data : data to be saved in the message | ||
| 439 | * @return true on success, false otherwise | ||
| 440 | */ | ||
| 441 | 297 | bool DataStream<char*, DataStreamMode::WRITE, long unsigned int>::data_stream(char* & ds, long unsigned int & data){ | |
| 442 | 297 | const char* srcByte = (const char*)&data; | |
| 443 | 297 | memcpy(ds, srcByte, sizeof(long unsigned int)); | |
| 444 | 297 | ds += sizeof(long unsigned int); | |
| 445 | 297 | return true; | |
| 446 | } | ||
| 447 | |||
| 448 | ///Save the long unsigned int in the message | ||
| 449 | /** @param[out] ds : message to be written | ||
| 450 | * @param data : data to be saved in the message | ||
| 451 | * @param nbElement : number of element of the data | ||
| 452 | * @return true on success, false otherwise | ||
| 453 | */ | ||
| 454 | 98 | bool DataStream<char*, DataStreamMode::WRITE, long unsigned int>::data_stream(char* & ds, long unsigned int * data, size_t nbElement){ | |
| 455 | 98 | const char* srcByte = (const char*)data; | |
| 456 | 98 | memcpy(ds, srcByte, sizeof(long unsigned int)*nbElement); | |
| 457 | 98 | ds += sizeof(long unsigned int)*nbElement; | |
| 458 | 98 | return true; | |
| 459 | } | ||
| 460 | |||
| 461 | ///Read the float in the message | ||
| 462 | /** @param[out] ds : message to be read | ||
| 463 | * @param[out] data : data to be set | ||
| 464 | * @return true on success, false otherwise | ||
| 465 | */ | ||
| 466 | 1 | bool DataStream<char*, DataStreamMode::READ, float>::data_stream(char* & ds, float & data){ | |
| 467 | 1 | char* srcByte = (char*)&data; | |
| 468 | 1 | memcpy(srcByte, ds, sizeof(float)); | |
| 469 | 1 | ds += sizeof(float); | |
| 470 | 1 | return true; | |
| 471 | } | ||
| 472 | |||
| 473 | ///Read the float in the message | ||
| 474 | /** @param[out] ds : message to be read | ||
| 475 | * @param[out] data : data to be set | ||
| 476 | * @param nbElement : number of element of the data | ||
| 477 | * @return true on success, false otherwise | ||
| 478 | */ | ||
| 479 | 98 | bool DataStream<char*, DataStreamMode::READ, float>::data_stream(char* & ds, float * data, size_t nbElement){ | |
| 480 | 98 | char* srcByte = (char*)data; | |
| 481 | 98 | memcpy(srcByte, ds, sizeof(float)*nbElement); | |
| 482 | 98 | ds += sizeof(float)*nbElement; | |
| 483 | 98 | return true; | |
| 484 | } | ||
| 485 | |||
| 486 | ///Save the float in the message | ||
| 487 | /** @param[out] ds : message to be written | ||
| 488 | * @param data : data to be saved in the message | ||
| 489 | * @return true on success, false otherwise | ||
| 490 | */ | ||
| 491 | 1 | bool DataStream<char*, DataStreamMode::WRITE, float>::data_stream(char* & ds, float & data){ | |
| 492 | 1 | const char* srcByte = (const char*)&data; | |
| 493 | 1 | memcpy(ds, srcByte, sizeof(float)); | |
| 494 | 1 | ds += sizeof(float); | |
| 495 | 1 | return true; | |
| 496 | } | ||
| 497 | |||
| 498 | ///Save the float in the message | ||
| 499 | /** @param[out] ds : message to be written | ||
| 500 | * @param data : data to be saved in the message | ||
| 501 | * @param nbElement : number of element of the data | ||
| 502 | * @return true on success, false otherwise | ||
| 503 | */ | ||
| 504 | 98 | bool DataStream<char*, DataStreamMode::WRITE, float>::data_stream(char* & ds, float * data, size_t nbElement){ | |
| 505 | 98 | const char* srcByte = (const char*)data; | |
| 506 | 98 | memcpy(ds, srcByte, sizeof(float)*nbElement); | |
| 507 | 98 | ds += sizeof(float)*nbElement; | |
| 508 | 98 | return true; | |
| 509 | } | ||
| 510 | |||
| 511 | ///Read the double in the message | ||
| 512 | /** @param[out] ds : message to be read | ||
| 513 | * @param[out] data : data to be set | ||
| 514 | * @return true on success, false otherwise | ||
| 515 | */ | ||
| 516 | 1 | bool DataStream<char*, DataStreamMode::READ, double>::data_stream(char* & ds, double & data){ | |
| 517 | 1 | char* srcByte = (char*)&data; | |
| 518 | 1 | memcpy(srcByte, ds, sizeof(double)); | |
| 519 | 1 | ds += sizeof(double); | |
| 520 | 1 | return true; | |
| 521 | } | ||
| 522 | |||
| 523 | ///Read the double in the message | ||
| 524 | /** @param[out] ds : message to be read | ||
| 525 | * @param[out] data : data to be set | ||
| 526 | * @param nbElement : number of element of the data | ||
| 527 | * @return true on success, false otherwise | ||
| 528 | */ | ||
| 529 | 98 | bool DataStream<char*, DataStreamMode::READ, double>::data_stream(char* & ds, double * data, size_t nbElement){ | |
| 530 | 98 | char* srcByte = (char*)data; | |
| 531 | 98 | memcpy(srcByte, ds, sizeof(double)*nbElement); | |
| 532 | 98 | ds += sizeof(double)*nbElement; | |
| 533 | 98 | return true; | |
| 534 | } | ||
| 535 | |||
| 536 | ///Save the double in the message | ||
| 537 | /** @param[out] ds : message to be written | ||
| 538 | * @param data : data to be saved in the message | ||
| 539 | * @return true on success, false otherwise | ||
| 540 | */ | ||
| 541 | 1 | bool DataStream<char*, DataStreamMode::WRITE, double>::data_stream(char* & ds, double & data){ | |
| 542 | 1 | const char* srcByte = (const char*)&data; | |
| 543 | 1 | memcpy(ds, srcByte, sizeof(double)); | |
| 544 | 1 | ds += sizeof(double); | |
| 545 | 1 | return true; | |
| 546 | } | ||
| 547 | |||
| 548 | ///Save the double in the message | ||
| 549 | /** @param[out] ds : message to be written | ||
| 550 | * @param data : data to be saved in the message | ||
| 551 | * @param nbElement : number of element of the data | ||
| 552 | * @return true on success, false otherwise | ||
| 553 | */ | ||
| 554 | 98 | bool DataStream<char*, DataStreamMode::WRITE, double>::data_stream(char* & ds, double * data, size_t nbElement){ | |
| 555 | 98 | const char* srcByte = (const char*)data; | |
| 556 | 98 | memcpy(ds, srcByte, sizeof(double)*nbElement); | |
| 557 | 98 | ds += sizeof(double)*nbElement; | |
| 558 | 98 | return true; | |
| 559 | } | ||
| 560 | |||
| 561 | ///Load a std::string from a message | ||
| 562 | /** @param[out] ds : message iterator which contains std::string | ||
| 563 | * @param data : std::string to be loaded | ||
| 564 | * @return true on success, false otherwise | ||
| 565 | */ | ||
| 566 | 2 | bool DataStream<char*, DataStreamMode::READ, std::string>::data_stream(char* & ds, std::string & data){ | |
| 567 | 2 | size_t nbElement(0lu); | |
| 568 |
1/1✓ Branch 1 taken 2 times.
|
2 | bool b = DataStream<char*, DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
| 569 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if(nbElement == 0lu || !b){return b;} |
| 570 |
1/1✓ Branch 1 taken 2 times.
|
2 | data.resize(nbElement); |
| 571 | 2 | memcpy((char*)data.data(), ds, nbElement); | |
| 572 | 2 | ds += nbElement; | |
| 573 | 2 | return b; | |
| 574 | } | ||
| 575 | |||
| 576 | |||
| 577 | ///Save a std::string into a message | ||
| 578 | /** @param[out] ds : message iterator to be written | ||
| 579 | * @param data : std::string to be saved | ||
| 580 | * @return true on success, false otherwise | ||
| 581 | */ | ||
| 582 | 2 | bool DataStream<char*, DataStreamMode::WRITE, std::string>::data_stream(char* & ds, std::string & data){ | |
| 583 | 2 | size_t nbElement(data.size()); | |
| 584 |
1/1✓ Branch 1 taken 2 times.
|
2 | bool b = DataStream<char*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 585 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if(nbElement == 0lu || !b){return b;} |
| 586 | 2 | memcpy(ds, (const char*)data.data(), nbElement); | |
| 587 | 2 | ds += nbElement; | |
| 588 | 2 | return b; | |
| 589 | } | ||
| 590 | |||
| 591 | |||
| 592 |