Ejemplo n.º 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}))");
     }
 }
Ejemplo n.º 2
0
 IByteBuffer CheckIndex(int index)
 {
     if ((uint)index > 0u) // != 0
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
     return(this);
 }
Ejemplo n.º 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}))");
     }
 }
Ejemplo n.º 4
0
 void CheckLength0(int length)
 {
     if ((uint)length > SharedConstants.TooBigOrNegative)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(length, ExceptionArgument.length);
     }
     if ((uint)length > 0u)
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
 }
Ejemplo n.º 5
0
 void CheckLength0(int length)
 {
     if (length < 0)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(length, ExceptionArgument.length);
     }
     if (length > 0)
     {
         ThrowHelper.ThrowIndexOutOfRangeException();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
        public IByteBuffer EnsureWritable(int minWritableBytes)
        {
            if (minWritableBytes < 0)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(minWritableBytes, ExceptionArgument.minWritableBytes);
            }

            if (minWritableBytes != 0)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }
            return(this);
        }
Ejemplo n.º 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);
            }
        }