Ejemplo n.º 1
0
 private static void CheckMinWritableBounds(int minWritableBytes, int writerIndex, int maxCapacity, AbstractByteBuffer buf)
 {
     if (minWritableBytes > maxCapacity - writerIndex)
     {
         ThrowHelper.ThrowIndexOutOfRangeException_WriterIndex(minWritableBytes, writerIndex, maxCapacity, buf);
     }
 }
        public virtual IByteBuffer SetWriterIndex(int index)
        {
            if (index < this.readerIndex || index > this.Capacity)
            {
                ThrowHelper.ThrowIndexOutOfRangeException_WriterIndex(index, this.readerIndex, this.Capacity);
            }

            this.SetWriterIndex0(index);
            return(this);
        }
        protected internal void EnsureWritable0(int minWritableBytes)
        {
            this.EnsureAccessible();
            if (minWritableBytes <= this.WritableBytes)
            {
                return;
            }

            if (minWritableBytes > this.MaxCapacity - this.writerIndex)
            {
                ThrowHelper.ThrowIndexOutOfRangeException_WriterIndex(minWritableBytes, this.writerIndex, this.MaxCapacity, this);
            }

            // Normalize the current capacity to the power of 2.
            int newCapacity = this.Allocator.CalculateNewCapacity(this.writerIndex + minWritableBytes, this.MaxCapacity);

            // Adjust to the new capacity.
            this.AdjustCapacity(newCapacity);
        }