Beispiel #1
0
        public void Validate(bool write, int dataSize)
        {
            ByteBuffer.ManagedBuffer managedBuffer;
            bool length = false;

            if (!write)
            {
                length = this.Length >= dataSize;
            }
            else
            {
                if (this.Size < dataSize && this.autoGrow)
                {
                    if (this.references != 1)
                    {
                        throw new InvalidOperationException("Cannot grow the current buffer because it has more than one references");
                    }
                    int num = Math.Max(this.Capacity * 2, this.Capacity + dataSize);
                    managedBuffer = (this.bufferManager == null ? new ByteBuffer.ManagedBuffer(new byte[num], null) : ByteBuffer.AllocateBuffer(num, this.bufferManager));
                    System.Buffer.BlockCopy(this.buffer, this.start, managedBuffer.Buffer, 0, this.Capacity);
                    int num1 = this.read - this.start;
                    int num2 = this.write - this.start;
                    this.start = 0;
                    this.read  = num1;
                    this.write = num2;
                    this.end   = num;
                    if (this.bufferManager != null)
                    {
                        this.bufferManager.ReturnBuffer(this.buffer);
                    }
                    this.buffer        = managedBuffer.Buffer;
                    this.bufferManager = managedBuffer.BufferManager;
                }
                length = this.Size >= dataSize;
            }
            if (!length)
            {
                throw new AmqpException(AmqpError.DecodeError, SRAmqp.AmqpInsufficientBufferSize(dataSize, (write ? this.Size : this.Length)));
            }
        }
Beispiel #2
0
 private static ByteBuffer.ManagedBuffer AllocateBufferFromPool(int size, bool isTransportBuffer)
 {
     return(ByteBuffer.AllocateBuffer(size, (isTransportBuffer ? ByteBuffer.TransportBufferManager : ByteBuffer.BufferManager)));
 }