Changeset 6341 in orxonox.OLD for trunk/src/lib/network/network_protocol.cc
- Timestamp:
- Dec 30, 2005, 1:57:12 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_protocol.cc
r6139 r6341 30 30 #include "debug.h" 31 31 32 #include "converter.h" 33 32 34 /* using namespace std is default, this needs to be here */ 33 35 using namespace std; … … 41 43 /* set the class id for the base object */ 42 44 this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol"); 43 this->headerLength = sizeof(Header);45 this->headerLength = INTSIZE+FLOATSIZE; 44 46 } 45 47 … … 64 66 PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength); 65 67 //If there isn't enough space for the header return -1 66 if (length + this->headerLength> bufferLength)68 if (length + 2*INTSIZE > bufferLength) 67 69 return -1; 68 70 … … 70 72 // FIXME: without move Create space for the header 71 73 for( int i = length - 1; i >= 0; i--) 72 data[i + this->headerLength] = data[i];74 data[i + INTSIZE+INTSIZE] = data[i]; 73 75 74 76 //Now create the header 75 77 /* sender ID: FIXME: there will be a better ID (for example unique:D)*/ 76 data[0] = (byte)(source.getUniqueID()); 78 //data[0] = (byte)(source.getUniqueID()); 79 int res = Converter::intToByteArray( source.getUniqueID(), data, bufferLength ); 80 77 81 /* data length*/ 78 data[1] = length; 82 //data[1] = length; 83 res += Converter::intToByteArray( length, data+res, bufferLength-res ); 79 84 80 85 81 return length + this->headerLength;86 return length + res; 82 87 } 83 88 … … 92 97 PRINTF(5)("extract Header\n"); 93 98 //Test if received data can contain a header 94 if (length < headerLength)99 if (length < 2*INTSIZE) 95 100 { 96 101 PRINTF(1)("Received data is to short; it can't contain a header!\n"); … … 105 110 106 111 /* unique ID */ 107 h.synchronizeableID = data[0]; 112 //h.synchronizeableID = data[0]; 113 int res = Converter::byteArrayToInt( data, &(h.synchronizeableID) ); 108 114 /* data length*/ 109 h.length = data[1]; 115 //h.length = data[1]; 116 Converter::byteArrayToInt( data+res, &(h.length) ); 110 117 111 118
Note: See TracChangeset
for help on using the changeset viewer.