Changeset 6273 in orxonox.OLD for branches/network/src/lib/network/converter.cc
- Timestamp:
- Dec 23, 2005, 5:30:22 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/converter.cc
r6229 r6273 92 92 return -1; 93 93 } 94 94 95 95 const int mod = 256; // = 2^8 96 96 … … 405 405 return FLOATSIZE; 406 406 } 407 408 /** 409 * copies a strint to a byte array 410 * @param s: string to copy 411 * @param a: byte array 412 * @param length: string length 413 * @return: the used number of bytes in byte array 414 */ 415 int Converter::stringToByteArray( const char * s, byte * a, int length, int maxLength ) 416 { 417 if ( length+INTSIZE > maxLength ) 418 { 419 PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, length+INTSIZE); 420 return -1; 421 } 422 423 int n = Converter::intToByteArray( length, a, maxLength ); 424 425 memcpy( a+INTSIZE, s, length ); 426 427 return length + INTSIZE; 428 } 429 430 /** 431 * reads a string out of a byte array 432 * @param a: byte array 433 * @param s: string 434 * @param maxLength: max bytes to copy 435 * @return: the number of read bytes in byte array 436 */ 437 int Converter::byteArrayToString( const byte * a, char * s, int maxLength ) 438 { 439 int length; 440 441 int n = Converter::byteArrayToInt( a, &length ); 442 443 if ( length+1 > maxLength ) 444 { 445 PRINTF(1)("There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1 ); 446 return -1; 447 } 448 449 memcpy( s, a+n, length ); 450 s[length] = '\0'; 451 452 return n+length; 453 }
Note: See TracChangeset
for help on using the changeset viewer.