/// <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) { DataPacket p = Create((int)size); p.Sender = packet.Sender; p.Destination = packet.Destination; Buffer.BlockCopy(packet.Data, 0, p.Data, 0, (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.Data.Length + newPacket.Data.Length); p.Sender = remaining.Sender; p.Destination = remaining.Destination; remaining.Data.CopyTo(p.Data, 0); newPacket.Data.CopyTo(p.Data, remaining.Data.Length); return p; }
public static DataPacket Create(int size) { DataPacket p = new DataPacket(); p.Data = new byte[size]; p.SetUInt16(2, (ushort)(size - 16)); return p; }