Ejemplo n.º 1
0
 public void ExtractFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
 {
     if (this.currentFrameBuffer != null)
     {
         int num = Math.Min(this.currentFrameBuffer.Size, buffer.Length);
         AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, num);
         buffer.Complete(num);
         if (this.currentFrameBuffer.Size == 0)
         {
             ByteBuffer byteBuffer = this.currentFrameBuffer;
             this.currentFrameBuffer = null;
             bufferHandler.DoWork(byteBuffer);
         }
     }
     while (buffer.Length >= AmqpCodec.MinimumFrameDecodeSize)
     {
         int frameSize = AmqpCodec.GetFrameSize(buffer);
         if (frameSize < AmqpCodec.MinimumFrameDecodeSize || frameSize > this.maxFrameSize)
         {
             throw new AmqpException(AmqpError.FramingError, SRClient.InvalidFrameSize(frameSize, this.maxFrameSize));
         }
         int num1 = Math.Min(frameSize, buffer.Length);
         this.currentFrameBuffer = new ByteBuffer(frameSize, false);
         AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, num1);
         buffer.Complete(num1);
         if (frameSize != num1)
         {
             break;
         }
         ByteBuffer byteBuffer1 = this.currentFrameBuffer;
         this.currentFrameBuffer = null;
         bufferHandler.DoWork(byteBuffer1);
     }
 }
Ejemplo n.º 2
0
        public void ExtractFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
        {
            if (this.currentFrameBuffer != null)
            {
                int sizeToWrite = Math.Min(this.currentFrameBuffer.Size, buffer.Length);

                this.currentFrameBuffer.WriteBytes(buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (this.currentFrameBuffer.Size == 0)
                {
                    bufferHandler.DoWork(this.currentFrameBuffer);
                    this.currentFrameBuffer = null;
                }
            }

            while (buffer.Length >= AmqpCodec.MinimumFrameDecodeSize)
            {
                int frameSize = AmqpCodec.GetFrameSize(buffer);
                if (frameSize < AmqpCodec.MinimumFrameDecodeSize || frameSize > this.maxFrameSize)
                {
                    throw new AmqpException(AmqpError.FramingError, SRClient.InvalidFrameSize(frameSize, this.maxFrameSize));
                }

                int sizeToWrite = Math.Min(frameSize, buffer.Length);
                this.currentFrameBuffer = ByteBuffer.Wrap(new byte[frameSize], 0, 0, frameSize);
                this.currentFrameBuffer.WriteBytes(buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (frameSize == sizeToWrite)
                {
                    bufferHandler.DoWork(this.currentFrameBuffer);
                    this.currentFrameBuffer = null;
                }
                else
                {
                    break;
                }
            }
        }