private static void CheckRangeBounds(ExceptionArgument indexName, int index, int fieldLength, int capacity) { if (MathUtil.IsOutOfBounds(index, fieldLength, capacity)) { ThrowHelper.ThrowIndexOutOfRangeException_Index(indexName, index, fieldLength, capacity); } }
protected void CheckIndex0(int index, int fieldLength) { if (MathUtil.IsOutOfBounds(index, fieldLength, this.Capacity)) { ThrowHelper.ThrowIndexOutOfRangeException_Index(index, fieldLength, this.Capacity); } }
/// <summary>Creates a new big-endian buffer which wraps the sub-region of the specified array. A /// modification on the specified array's content will be visible to the returned buffer.</summary> public static IByteBuffer WrappedBuffer(byte[] array, int offset, int length) { if (array is null || 0u >= (uint)length) { return(Empty); } if (MathUtil.IsOutOfBounds(offset, length, array.Length)) { ThrowHelper.ThrowIndexOutOfRangeException_Index(offset, length, array.Length); } if (0u >= (uint)offset) { return(PlatformDependent.DirectBufferPreferred ? ArrayPooledUnsafeDirectByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, length, array.Length) : (IByteBuffer)ArrayPooledHeapByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, length, array.Length)); } return(WrappedBuffer(array).Slice(offset, length)); }