/// <summary>Implementation of chunked calculation specifically on byte arrays.</summary> /// <remarks> /// Implementation of chunked calculation specifically on byte arrays. This /// is to avoid the copy when dealing with ByteBuffers that have array backing. /// </remarks> public virtual void CalculateChunkedSums(byte[] data, int dataOffset, int dataLength , byte[] sums, int sumsOffset) { if (type.size == 0) { return; } if (NativeCrc32.IsAvailable()) { NativeCrc32.CalculateChunkedSumsByteArray(bytesPerChecksum, type.id, sums, sumsOffset , data, dataOffset, dataLength); return; } int remaining = dataLength; while (remaining > 0) { int n = Math.Min(remaining, bytesPerChecksum); summer.Reset(); summer.Update(data, dataOffset, n); dataOffset += n; remaining -= n; long calculated = summer.GetValue(); sums[sumsOffset++] = unchecked ((byte)(calculated >> 24)); sums[sumsOffset++] = unchecked ((byte)(calculated >> 16)); sums[sumsOffset++] = unchecked ((byte)(calculated >> 8)); sums[sumsOffset++] = unchecked ((byte)(calculated)); } }
public virtual void TestCalculateChunkedSumsByteArrayFail() { AllocateArrayByteBuffers(); FillDataAndInvalidChecksums(); NativeCrc32.CalculateChunkedSumsByteArray(bytesPerChecksum, checksumType.id, ((byte [])checksums.Array()), checksums.Position(), ((byte[])data.Array()), data.Position (), data.Remaining()); }