public static byte[][] ConvertToLargePackageBytes(Package package, int segmentByteLength) { var packageID = package.ID; var packageUUID = GetUUID(); var bytes = package.Serialize(); var segmentCount = (int)Math.Ceiling(bytes.Length / (double)segmentByteLength); var wait_return_bytes = new List <byte[]>(); for (int i = 0; i < segmentCount; i++) { var currentSegment_b = (i + 1) * segmentByteLength; if (bytes.Length < currentSegment_b) { var currentSegment_a = i * segmentByteLength; var sub_bytes = new byte[bytes.Length - currentSegment_a]; Array.Copy(bytes, i * segmentByteLength, sub_bytes, 0, sub_bytes.Length); var largePackage = new LargePackage(package.HeadBytes); largePackage.ConcretePackageID = packageID; largePackage.ConcretePackageUUID = packageUUID; largePackage.SegmentID = segmentCount - 1; largePackage.SegmentTotalCount = segmentCount; largePackage.BytesList = new List <byte>(sub_bytes); wait_return_bytes.Add(largePackage.Serialize()); } else { var sub_bytes = new byte[segmentByteLength]; Array.Copy(bytes, i * segmentByteLength, sub_bytes, 0, sub_bytes.Length); var largePackage = new LargePackage(package.HeadBytes); largePackage.ConcretePackageID = packageID; largePackage.ConcretePackageUUID = packageUUID; largePackage.SegmentID = i; largePackage.SegmentTotalCount = segmentCount; largePackage.BytesList = new List <byte>(sub_bytes); wait_return_bytes.Add(largePackage.Serialize()); } } return(wait_return_bytes.ToArray()); }
public LargePackageHandler(byte[] packageHead) { mTemplate = new LargePackage(packageHead); mLargePackageInfoList = new List <LargePackageInfo>(4); }