示例#1
0
 protected void CheckIndex0(int index, int fieldLength)
 {
     if (MathUtil.IsOutOfBounds(index, fieldLength, this.Capacity))
     {
         ThrowHelper.ThrowIndexOutOfRangeException($"index: {index}, length: {fieldLength} (expected: range(0, {this.Capacity}))");
     }
 }
示例#2
0
 IByteBuffer CheckIndex(int index)
 {
     if ((uint)index > 0u) // != 0
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
     return(this);
 }
示例#3
0
 protected void CheckDstIndex(int index, int length, int dstIndex, int dstCapacity)
 {
     this.CheckIndex(index, length);
     if (MathUtil.IsOutOfBounds(dstIndex, length, dstCapacity))
     {
         ThrowHelper.ThrowIndexOutOfRangeException($"dstIndex: {dstIndex}, length: {length} (expected: range(0, {dstCapacity}))");
     }
 }
示例#4
0
 void CheckLength0(int length)
 {
     if ((uint)length > SharedConstants.TooBigOrNegative)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(length, ExceptionArgument.length);
     }
     if ((uint)length > 0u)
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
 }
示例#5
0
 void CheckLength0(int length)
 {
     if (length < 0)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(length, ExceptionArgument.length);
     }
     if (length > 0)
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
 }
示例#6
0
 void CheckIndex0(int index, int length)
 {
     if (length < 0)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(length, ExceptionArgument.length);
     }
     if ((uint)index > 0u || length > 0)
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
 }
示例#7
0
        public IByteBuffer EnsureWritable(int minWritableBytes)
        {
            if ((uint)minWritableBytes > SharedConstants.TooBigOrNegative)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(minWritableBytes, ExceptionArgument.minWritableBytes);
            }

            if (minWritableBytes != 0)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }
            return(this);
        }
示例#8
0
        public IByteBuffer EnsureWritable(int minWritableBytes)
        {
            if (minWritableBytes < 0)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(minWritableBytes, ExceptionArgument.minWritableBytes);
            }

            if (minWritableBytes != 0)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }
            return(this);
        }
示例#9
0
        internal void Reallocate(PooledByteBuffer <T> buf, int newCapacity, bool freeOldMemory)
        {
            if (/*newCapacity < 0 || */ (uint)newCapacity > (uint)buf.MaxCapacity)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            int oldCapacity = buf.Length;

            if (oldCapacity == newCapacity)
            {
                return;
            }

            PoolChunk <T> oldChunk     = buf.Chunk;
            long          oldHandle    = buf.Handle;
            T             oldMemory    = buf.Memory;
            int           oldOffset    = buf.Offset;
            int           oldMaxLength = buf.MaxLength;

            // This does not touch buf's reader/writer indices
            Allocate(Parent.ThreadCache <T>(), buf, newCapacity);
            int bytesToCopy;

            if (newCapacity > oldCapacity)
            {
                bytesToCopy = oldCapacity;
            }
            else
            {
                buf.TrimIndicesToCapacity(newCapacity);
                bytesToCopy = newCapacity;
            }
            MemoryCopy(oldMemory, oldOffset, buf.Memory, buf.Offset, bytesToCopy);

            if (freeOldMemory)
            {
                Free(oldChunk, oldHandle, oldMaxLength, buf.Cache);
            }
        }