Exemple #1
0
 private static void Validate(int bufferSize, int dataSize)
 {
     if (bufferSize < dataSize)
     {
         throw new AmqpException(AmqpError.DecodeError, SRAmqp.AmqpInsufficientBufferSize(dataSize, bufferSize));
     }
 }
 public void Decode(ByteBuffer buffer)
 {
     if (buffer.Length < this.EncodeSize)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInsufficientBufferSize(this.EncodeSize, buffer.Length));
     }
     if (AmqpBitConverter.ReadUInt(buffer) != 1095586128)
     {
         throw AmqpEncoding.GetEncodingException("ProtocolName");
     }
     this.protocolId = (Microsoft.ServiceBus.Messaging.Amqp.ProtocolId)AmqpBitConverter.ReadUByte(buffer);
     this.version    = new AmqpVersion(AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer));
 }
Exemple #3
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)));
            }
        }