#include <common.h>
Public Member Functions | |
Packet () | |
Packet (int buffer_length) | |
int | fillPayload (int size, char *inputstream) |
char * | getPayload () |
void | setPayloadSize (int size) |
int | getBufferSize () |
int | getPayloadSize () |
int | getHeaderSize () |
PacketHdr * | accessHeader () |
void | extractHeader (char *streambuf) |
int | makePacket (char *streambuf) |
Static Public Attributes | |
static const int | DEFAULT_PAYLOAD_SIZE = 512 |
Protected Attributes | |
int | size_ |
Packet length in Bytes. | |
int | length_ |
Maximum allocated Size of Payload buffer. it is no less than the size_. | |
char * | payload_ |
Payload Pointer. | |
PacketHdr * | header_ |
Header Pointer;. |
Packet is an entity which contains a set of ordered information bits. This packet object only carries a pointer to payload information, not any socket address information.
Definition at line 89 of file common.h.
|
Alternate Packet Constructor: Specify a large buffer.... This is useful to define a packet receiving buffer. Definition at line 73 of file common.cpp. References header_, length_, payload_, and size_. 00074 { 00075 size_ = 0; 00076 length_ = buffer_length; 00077 payload_ = new char[buffer_length]; 00078 header_ = new PacketHdr(); 00079 }
|
|
Get the packet header Definition at line 119 of file common.h. References header_. 00119 { return header_;}
|
|
Extract packet header from the incoming stream Definition at line 131 of file common.cpp. References PacketHdr::accessInfo(), header_, and PacketHdr::setHeaderSize(). Referenced by ReceivingPort::receivePacket(). 00132 { 00133 char* p= streambuf; 00134 int a = *(p++); 00135 header_->setHeaderSize(a); 00136 memcpy( header_->accessInfo(), p ,a); 00137 }
|
|
A function to fill payload. user can specify the content of payload for applications like audio/video playback... Definition at line 105 of file common.cpp. References payload_, and setPayloadSize(). Referenced by ReceivingPort::receivePacket(). 00106 { 00107 setPayloadSize(size); 00108 if (memcpy((char *)payload_, (char *)inputstream, size) == NULL) { 00109 throw "Fill payload Failed"; 00110 } 00111 return 0; 00112 }
|
|
get the size of packet buffer where payload is stored. Definition at line 107 of file common.h. References length_. 00107 {return length_;}
|
|
get the size of the packet header Definition at line 115 of file common.h. References PacketHdr::getSize(), and header_. Referenced by ReceivingPort::receivePacket().
|
|
get a pointer to the payload
Definition at line 102 of file common.h. References payload_. 00102 { return payload_;}
|
|
get the size of the packet Definition at line 111 of file common.h. References size_. 00111 { return size_;}
|
|
Assemble header and payload and headersize in a single stream Definition at line 118 of file common.cpp. References PacketHdr::accessInfo(), PacketHdr::getSize(), header_, payload_, and size_. Referenced by SendingPort::sendPacket(). 00119 { 00120 streambuf[0]= ( header_->getSize() ) & 0xff; 00121 streambuf[1]= 0x00; 00122 memcpy(streambuf+1, header_->accessInfo(), header_->getSize()); 00123 memcpy(streambuf+1+header_->getSize(), payload_, size_); 00124 00125 return 1+size_+ header_->getSize(); 00126 }
|
|
set packet size. As packet already has a default buffer, there are two ways to determine the payload
Definition at line 91 of file common.cpp. References length_, payload_, and size_. Referenced by fillPayload(). 00092 { 00093 size_ = size; 00094 if (size > length_) { 00095 if (payload_ != NULL) delete [] payload_; 00096 length_ = (int)(1.5 * size); 00097 payload_ = new char[length_]; 00098 } 00099 }
|
|
Default payload size is 512 Bytes Definition at line 95 of file common.h. Referenced by Packet(). |