public void writeToTarget(IByteTarget _target, IByteBuffer fb) { const int seg = 4096000; int gcd = (int)(fb.Size / seg); int gcf = (int)(fb.Size % seg); if (gcd == 0) { _target.Write(fb.Data, 0, fb.Size); } else { for (int i = 0; i < gcd; i++) { var rgBuffer = fb.GetByteRange(i * seg, seg); _target.Write(rgBuffer, 0, seg); rgBuffer = null; } if (gcf > 0) { var rgBuffer = fb.GetByteRange(gcd * seg, gcf); _target.Write(rgBuffer, 0, (uint)gcf); rgBuffer = null; } } }
private static async Task WriteBufferAsync(IByteTarget target, IByteBuffer buffer, uint largeObjectSize) { var offset = 0; var remainingSize = buffer.Size; while (remainingSize > largeObjectSize) { var range = buffer.GetByteRange(offset, (int)largeObjectSize); await target.WriteAsync(range, 0, largeObjectSize).ConfigureAwait(false); offset += (int)largeObjectSize; remainingSize -= largeObjectSize; } target.Write(buffer.GetByteRange(offset, (int)remainingSize), 0, remainingSize); }
private static void WriteBuffer(IByteTarget target, IByteBuffer buffer, uint largeObjectSize) { var offset = 0; var remainingSize = buffer.Size; while (remainingSize > largeObjectSize) { var range = buffer.GetByteRange(offset, (int)largeObjectSize); target.Write(range, 0, largeObjectSize); offset += (int)largeObjectSize; remainingSize -= largeObjectSize; } target.Write(buffer.GetByteRange(offset, (int)remainingSize), 0, remainingSize); }
public static T Get <T>(IByteBuffer buffer, int n) { int size = Marshal.SizeOf <T>(); var values = new T[1]; if (buffer.IsMemory) { System.Buffer.BlockCopy(buffer.Data, size * n, values, 0, size); } else { byte[] temp = ArrayPool <byte> .Shared.Rent(size); try { buffer.GetByteRange(size * n, size, temp); System.Buffer.BlockCopy(temp, 0, values, 0, size); } finally { ArrayPool <byte> .Shared.Return(temp); } } return(values[0]); }
public static T Get <T>(IByteBuffer buffer, int n) { int size = Marshal.SizeOf(typeof(T)); T[] values = new T[1]; if (buffer.IsMemory) { System.Buffer.BlockCopy(buffer.Data, size * n, values, 0, size); } else { byte[] temp = buffer.GetByteRange(size * n, size); System.Buffer.BlockCopy(temp, 0, values, 0, size); } return(values[0]); }
private static byte[] GetBufferRange(IByteBuffer buffer, uint offset, int count) { byte[] range = null; if (buffer is CompositeByteBuffer) { var cbuf = buffer as CompositeByteBuffer; range = cbuf.GetByteRange(offset, count); } else { if (offset > ((uint)int.MaxValue))//other buffers only accept ints { string bufName = nameof(buffer); throw new System.ArgumentOutOfRangeException("Offset greater than " + bufName + " buffer allows"); } range = buffer.GetByteRange((int)offset, count); } return(range); }