Changeset 7230 in orxonox.OLD for trunk/src/lib/network/converter.cc
- Timestamp:
- Mar 21, 2006, 3:20:36 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/converter.cc
r6959 r7230 159 159 if ( length< INTSIZE ) 160 160 { 161 PRINTF(1)("Byte Array to small \n");161 PRINTF(1)("Byte Array to small : %d\n", length); 162 162 return 0; 163 163 } … … 457 457 * @return: the used number of bytes in byte array 458 458 */ 459 int Converter::stringToByteArray( const char * s, byte * a, int length, int maxLength )460 { 461 if ( length+INTSIZE > maxLength )462 { 463 PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, length+INTSIZE);459 int Converter::stringToByteArray( const std::string & s, byte * a, int maxLength ) 460 { 461 if ( s.length()+INTSIZE > maxLength ) 462 { 463 PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, s.length()+INTSIZE); 464 464 return -1; 465 465 } 466 466 467 int n = Converter::intToByteArray( length, a, maxLength );468 469 memcpy( a+INTSIZE, s , length);470 471 return length+ INTSIZE;467 int n = Converter::intToByteArray( s.length(), a, maxLength ); 468 469 memcpy( a+INTSIZE, s.c_str(), s.length() ); 470 471 return s.length() + INTSIZE; 472 472 } 473 473 … … 479 479 * @return: the number of read bytes in byte array 480 480 */ 481 int Converter::byteArrayToString( const byte * a, char *s, int maxLength )481 int Converter::byteArrayToString( const byte * a, std::string&s, int maxLength ) 482 482 { 483 483 int length; … … 488 488 if ( length+1 > maxLength ) 489 489 { 490 PRINTF(1)(" There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1);491 s trncpy(s,"",maxLength);490 PRINTF(1)("something went wrong length > remaining bytes in buffer\n" ); 491 s = ""; 492 492 return -1; 493 493 } 494 494 495 memcpy( s, a+n, length );496 s [length] = '\0';495 s[0] = '\0'; 496 s.append( (char*)a+n, length ); 497 497 498 498 return n+length; 499 499 } 500 500 501 #if 0 501 502 /** 502 503 * reads a string out of a byte array and allocates memory for string … … 525 526 return n+length; 526 527 } 527 528 #endif 528 529 529 530
Note: See TracChangeset
for help on using the changeset viewer.