* @param p the instance to be seralized
* @param dataOut the output stream
* @throws IOException thrown if an error occurs
*/
public void writePacket(Packet p, DataOutput dataOut) throws IOException {
AbstractPacket packet = (AbstractPacket)p;
dataOut.writeShort(packet.getId());
BitArray ba = packet.getBitArray();
ba.set(AbstractPacket.RECEIPT_REQUIRED_INDEX, packet.isReceiptRequired());
Object[] visited = packet.getBrokersVisited();
boolean writeVisited = visited != null && visited.length > 0;
ba.set(AbstractPacket.BROKERS_VISITED_INDEX,writeVisited);
ba.writeToStream(dataOut);
if (writeVisited){
dataOut.writeShort(visited.length);