Handles messages between workers. Can contain either a TCP/UDP packet or an EPICS message
Inheritance: ICloneable
 /// <summary>
 /// Skips a given size from the data block
 /// </summary>
 /// <param name="size"></param>
 public DataPacket SkipSize(UInt32 size, bool reuse = false)
 {
     if (reuse)
     {
         DataPacket p = new DataPacket();
         p.Sender = this.Sender;
         p.Destination = this.Destination;
         p.Kind = this.Kind;
         p.Chain = this.Chain;
         p.bufferSize = BufferSize - (int)size;
         p.Offset = Offset + (int)size;
         p.Data = Data;
         return p;
     }
     else
     {
         DataPacket p = DataPacket.Create(BufferSize - (int)size);
         p.Sender = this.Sender;
         p.Destination = this.Destination;
         p.Kind = this.Kind;
         p.Chain = this.Chain;
         Buffer.BlockCopy(this.Data, (int)size, p.Data, 0, this.BufferSize - (int)size);
         return p;
     }
 }
 /// <summary>
 /// Merges 2 packets together
 /// </summary>
 /// <param name="remaining"></param>
 /// <param name="newPacket"></param>
 public static DataPacket Create(DataPacket remaining, DataPacket newPacket)
 {
     DataPacket p = Create(remaining.BufferSize + newPacket.BufferSize);
     p.Sender = remaining.Sender;
     p.Destination = remaining.Destination;
     p.Chain = remaining.Chain;
     p.Kind = remaining.Kind;
     Buffer.BlockCopy(remaining.Data, remaining.Offset, p.Data, 0, remaining.BufferSize);
     Buffer.BlockCopy(newPacket.Data, newPacket.Offset, p.Data, remaining.BufferSize, newPacket.BufferSize);
     return p;
 }
 /// <summary>
 /// Creates a new message based on the byte buffer however use only the first "size" byte for it.
 /// </summary>
 /// <param name="buff"></param>
 /// <param name="size"></param>
 /// <param name="chain"> </param>
 /// <param name="reuseBuffer"></param>
 public static DataPacket Create(byte[] buff, int size, WorkerChain chain, bool reuseBuffer = false)
 {
     if (reuseBuffer)
     {
         DataPacket p = new DataPacket();
         p.Data = buff;
         p.Chain = chain;
         p.bufferSize = size;
         return p;
     }
     else
     {
         DataPacket p = Create(size);
         p.Chain = chain;
         Buffer.BlockCopy(buff, 0, p.Data, 0, size);
         return p;
     }
 }
 /*/// <summary>
 /// Creates a new message based on the byte buffer however use only the first "size" byte for it.
 /// </summary>
 /// <param name="buff"></param>
 /// <param name="size"></param>
 /// <param name="chain"> </param>
 public static DataPacket Create(byte[] buff, int size, WorkerChain chain)
 {
     DataPacket p = Create(size);
     p.Chain = chain;
     Buffer.BlockCopy(buff, 0, p.Data, 0, size);
     return p;
 }*/
 /// <summary>
 /// Creates a new message based on an existing packed and use the "size" to extract only the first part.
 /// </summary>
 /// <param name="packet"></param>
 /// <param name="size"></param>
 public static DataPacket Create(DataPacket packet, UInt32 size, bool reuse=false)
 {
     if (reuse)
     {
         DataPacket p = new DataPacket();
         p.Kind = packet.Kind;
         p.Chain = packet.Chain;
         p.Sender = packet.Sender;
         p.Destination = packet.Destination;
         p.Offset = packet.Offset;
         p.bufferSize = (int)size;
         p.Data = packet.Data;
         return p;
     }
     else
     {
         DataPacket p = Create((int)size);
         p.Kind = packet.Kind;
         p.Chain = packet.Chain;
         p.Sender = packet.Sender;
         p.Destination = packet.Destination;
         if (size > packet.BufferSize)
             Buffer.BlockCopy(packet.Data, packet.Offset, p.Data, 0, packet.BufferSize);
         else
             Buffer.BlockCopy(packet.Data, packet.Offset, p.Data, 0, (int)size);
         return p;
     }
 }
        public static DataPacket Create(int size)
        {
            DataPacket p;
            /*if (size < 200)
            {
                lock (storedPackets)
                {
                    if (storedPackets.ContainsKey(size))
                    {
                        if (storedPackets[size].Count > 0)
                        {
                            p = storedPackets[size].Pop();
                            p.disposedBy = null;
                            DiagnosticServer.NbPooledPacket--;
                            return p;
                        }
                    }
                }
            }*/

            DiagnosticServer.NbNewData++;
            p = new DataPacket();
            p.Data = new byte[size];
            return p;
        }