public void WriteToBuffer(Brunet.Util.ICopyable p) {
int plength = p.CopyTo(_buffer, _written + 2);
if( plength > Int16.MaxValue ) {
throw new EdgeException(true,
String.Format("Packet too long: {0}",plength));
}
//
//The length at the beginning:
Brunet.Util.NumberSerializer.WriteShort((short)plength, _buffer, _written);
//Also write the length at the end so we can detect a bad packet
//as we have seen on planetlab:
Brunet.Util.NumberSerializer.WriteShort((short)plength, _buffer, _written + 2 + plength);
//If the buffer did not fill up, we have not yet thrown an exception:
_written += (plength + 4);
}