public void AddData(string address, byte[] data) { UDPPackage uDP = new UDPPackage(); var v = dic.GetOrAdd(address, uDP); v.AddData(data); }
public static UDPPackage Pack(byte[] data) { int num = data.Length / Size + data.Length % Size; int sessionid = 0; int index = 0; byte[] bytesNum = BitConverter.GetBytes(num); byte[] bytesSession = BitConverter.GetBytes(sessionid); SessionPackage[] tmp = new SessionPackage[num]; for (int i = 0; i < num; i++) { SessionPackage tp = null; if (index + Size > data.Length) { tp = new SessionPackage() { Data = new byte[Size + 12], SeqId = i, }; } else { tp = new SessionPackage() { Data = new byte[data.Length - index + 12], SeqId = i }; } Array.Copy(bytesNum, 0, tp.Data, 0, 4); Array.Copy(bytesSession, 0, tp.Data, 4, 4); Array.Copy(BitConverter.GetBytes(i), 0, tp.Data, 8, 4); Array.Copy(data, index, tp.Data, 12, tp.Data.Length); index += Size; tmp[i] = tp; } UDPPackage uDP = new UDPPackage(); uDP.AddData(tmp); return(uDP); }