Changeset 5735 in orxonox.OLD for branches/network
- Timestamp:
- Nov 23, 2005, 3:13:01 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_protocol.cc
r5617 r5735 27 27 #include "netdefs.h" 28 28 29 /* include this file for debugging */ 30 #include "debug.h" 31 29 32 /* using namespace std is default, this needs to be here */ 30 33 using namespace std; 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 34 51 35 … … 66 50 67 51 /** 52 * creates a new packet header from the function arguments 53 * 54 * @arg data: the binary data without header -> return the data in this binary array 55 * @arg length: the data length without header 56 * @arg bufferLength: the length of the internal buffer 57 * @arg source: reference to the source Synchronizeable object 58 * @arg remoteID: id number of the remote Synchronizeable object 59 * @return: the new data length with header (the header data is included into byte* data) 60 * -1 if there isn't enough space in the buffer for the header 61 */ 62 NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID) 63 { 64 //If there isn't enough space for the header return -1 65 if (length + headerLength > bufferLength) 66 return -1; 67 68 //Create space for the header 69 for (unsigned int i = length - 1; i >= 0; i--) 70 data[i + headerLength] = data[i]; 71 72 //Include header 73 data[0] = 255; 74 } 68 75 76 /** 77 * extracts the header from the binary data stream 78 * @arg data: the binary data with the header 79 * @arg length: the length of the binary data (including header) 80 * @return: a Header struct with the header information and the binary data 69 81 */ 70 void NetworkProtocol::writeDataField( /* Attribute: Any*/)82 Header NetworkProtocol::ExtractHeader(byte* data, int length) 71 83 { 84 //Test if received data can contain a header 85 if (length < headerLength) 86 { 87 PRINTF(0)("Received data is to short; it can't contain a header!"); 88 Header h; 89 h.protocol = -1; 90 return h; 91 } 92 93 //Extract header 94 Header h; 95 h.protocol = data[0]; 96 97 h.length = length - headerLength; 98 h.data = data; 99 100 //Remove header 101 for (int i = headerLength; i < length; i++) 102 data[i - headerLength] = data[i]; 103 104 return h; 72 105 } -
branches/network/src/lib/network/network_protocol.h
r5617 r5735 8 8 #include "base_object.h" 9 9 10 11 typedef struct Header 12 { 13 byte protocol; 14 byte version; 15 byte senderID; 16 byte receiverID; 17 byte length; 18 byte* data; 19 }; 20 10 21 /*! 11 22 … … 16 27 NetworkProtocol(); 17 28 ~NetworkProtocol(); 18 void writeDataField( /* Attribute: Any*/ ); 29 30 int createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID); 31 Header ExtractHeader(byte* data, int length); 19 32 20 33 private: 21 34 const unsigned int headerLength = 1; //The Length of the Header in bytes 35 dataFields dFields; 22 36 23 37 };
Note: See TracChangeset
for help on using the changeset viewer.