Exemple #1
0
            private void DecodeSize(byte[] buffer, ref int offset, ref int size)
            {
                while (size > 0)
                {
                    int num = this.decoder.Decode(buffer, offset, size);
                    if (num > 0)
                    {
                        offset += num;
                        size   -= num;
                    }
                    SingletonMessageDecoder.State currentState = this.decoder.CurrentState;
                    if (currentState != SingletonMessageDecoder.State.ChunkStart)
                    {
                        if (currentState == SingletonMessageDecoder.State.End)
                        {
                            goto Label_0081;
                        }
                        continue;
                    }
                    this.chunkBytesRemaining = this.decoder.ChunkSize;
                    if ((size > 0) && !object.ReferenceEquals(buffer, this.chunkBuffer))
                    {
                        Buffer.BlockCopy(buffer, offset, this.chunkBuffer, 0, size);
                        this.chunkBufferOffset = 0;
                        this.chunkBufferSize   = size;
                    }
                    return;

Label_0081:
                    this.ProcessEof();
                    return;
                }
            }
 public SingletonMessageDecoder(long streamPosition) : base(streamPosition)
 {
     this.sizeDecoder  = new IntDecoder();
     this.currentState = SingletonMessageDecoder.State.ChunkStart;
 }
        public int Decode(byte[] bytes, int offset, int size)
        {
            int num;
            int num1;

            DecoderHelper.ValidateSize(size);
            try
            {
                switch (this.currentState)
                {
                case SingletonMessageDecoder.State.ReadingEnvelopeChunkSize:
                {
                    num = this.sizeDecoder.Decode(bytes, offset, size);
                    if (!this.sizeDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    this.chunkSize = this.sizeDecoder.Value;
                    this.sizeDecoder.Reset();
                    if (this.chunkSize != 0)
                    {
                        this.currentState     = SingletonMessageDecoder.State.ChunkStart;
                        this.chunkBytesNeeded = this.chunkSize;
                        break;
                    }
                    else
                    {
                        this.currentState = SingletonMessageDecoder.State.EnvelopeEnd;
                        break;
                    }
                }

                case SingletonMessageDecoder.State.ChunkStart:
                {
                    num = 0;
                    this.currentState = SingletonMessageDecoder.State.ReadingEnvelopeBytes;
                    break;
                }

                case SingletonMessageDecoder.State.ReadingEnvelopeBytes:
                {
                    num = size;
                    if (num > this.chunkBytesNeeded)
                    {
                        num = this.chunkBytesNeeded;
                    }
                    SingletonMessageDecoder singletonMessageDecoder = this;
                    singletonMessageDecoder.chunkBytesNeeded = singletonMessageDecoder.chunkBytesNeeded - num;
                    if (this.chunkBytesNeeded != 0)
                    {
                        break;
                    }
                    this.currentState = SingletonMessageDecoder.State.ChunkEnd;
                    break;
                }

                case SingletonMessageDecoder.State.ChunkEnd:
                {
                    num = 0;
                    this.currentState = SingletonMessageDecoder.State.ReadingEnvelopeChunkSize;
                    break;
                }

                case SingletonMessageDecoder.State.EnvelopeEnd:
                {
                    base.ValidateRecordType(FramingRecordType.End, (FramingRecordType)bytes[offset]);
                    num = 1;
                    this.currentState = SingletonMessageDecoder.State.End;
                    break;
                }

                case SingletonMessageDecoder.State.End:
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.FramingAtEnd, new object[0]))));
                }

                default:
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.InvalidDecoderStateMachine, new object[0]))));
                }
                }
                SingletonMessageDecoder streamPosition = this;
                streamPosition.StreamPosition = streamPosition.StreamPosition + (long)num;
                num1 = num;
            }
            catch (InvalidDataException invalidDataException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(invalidDataException));
            }
            return(num1);
        }
 public void Reset()
 {
     this.currentState = SingletonMessageDecoder.State.ChunkStart;
 }