Changeset 6285 in orxonox.OLD for branches/network/src
- Timestamp:
- Dec 25, 2005, 4:24:50 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/converter.cc
r6275 r6285 453 453 return n+length; 454 454 } 455 456 /** 457 * reads a string out of a byte array and allocates memory for string 458 * @param a: byte array 459 * @param s: string 460 * @param maxLength: max bytes to copy 461 * @return: the number of read bytes in byte array 462 */ 463 int Converter::byteArrayToStringM( const byte * a, char * & s ) 464 { 465 int length; 466 467 int n = Converter::byteArrayToInt( a, &length ); 468 469 s = new char[n+1]; 470 471 if ( !s ) 472 { 473 PRINTF(1)("Could not allocate memory!\n" ); 474 return -1; 475 } 476 477 memcpy( s, a+n, length ); 478 s[length] = '\0'; 479 480 return n+length; 481 } 482 -
branches/network/src/lib/network/converter.h
r6273 r6285 35 35 static int stringToByteArray(const char* s, byte* a, int length, int maxLength); 36 36 static int byteArrayToString(const byte* a, char* s, int maxLength); 37 static int byteArrayToStringM(const byte* a, char*& s ); 37 38 38 39 //Test -
branches/network/src/lib/network/synchronizeable.h
r6277 r6285 29 29 * with the same argument names! 30 30 * 31 * SYNCHELP_WRITE_BEGIN() 32 * SYNCHELP_WRITE_INT(i) 33 * SYNCHELP_WRITE_FLOAT(f) 34 * SYNCHELP_WRITE_BYTE(b) 35 * SYNCHELP_WRITE_STRING(s) 36 * SYNCHELP_WRITE_N 37 * 38 * SYNCHELP_READ_BEGIN() 39 * SYNCHELP_READ_INT(i) 40 * SYNCHELP_READ_FLOAT(f) 41 * SYNCHELP_READ_STRING(s,l) l = size of buffer s 42 * SYNCHELP_READ_STRINGM(s) allocates memory for string! you have to free this after 43 * SYNCHELP_READ_BYTE(b) 44 * 45 * 31 46 * 32 47 * Example 1: … … 44 59 #define SYNCHELP_WRITE_BEGIN() int __synchelp_write_i = 0; \ 45 60 int __synchelp_write_n 46 #define SYNCHELP_WRITE_RESET() { __synchelp_write_i = 0; __synchelp_write_err = false; }47 61 #define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = \ 48 62 Converter::intToByteArray( i, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ … … 112 126 __synchelp_read_i += __synchelp_read_n; \ 113 127 } 128 #define SYNCHELP_READ_STRINGM(s) { \ 129 __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s ); \ 130 if ( __synchelp_read_n <0 ) \ 131 { \ 132 PRINTF(1)("There is not enough data to read string\n"); \ 133 return; \ 134 } \ 135 __synchelp_read_i += __synchelp_read_n; \ 136 } 114 137 #define SYNCHELP_READ_BYTE(b) { \ 115 138 if ( length-__synchelp_read_i < 1 ) \
Note: See TracChangeset
for help on using the changeset viewer.