예제 #1
0
        public int Decode(byte[] buffer, int offset, int size)
        {
            DecoderHelper.ValidateSize(size);
            if (this.isValueDecoded)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(Resources.FramingValueNotAvailable, new object[0])));
            }
            int num = 0;

            while (num < size)
            {
                int        num1       = buffer[offset];
                IntDecoder intDecoder = this;
                intDecoder.@value = intDecoder.@value | (num1 & 127) << (this.index * 7 & 31);
                num++;
                if (this.index == 4 && (num1 & 248) != 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.FramingSizeTooLarge, new object[0])));
                }
                IntDecoder intDecoder1 = this;
                intDecoder1.index = (short)(intDecoder1.index + 1);
                if ((num1 & 128) != 0)
                {
                    offset++;
                }
                else
                {
                    this.isValueDecoded = true;
                    break;
                }
            }
            return(num);
        }
예제 #2
0
        public int Decode(byte[] buffer, int offset, int size)
        {
            int num;

            DecoderHelper.ValidateSize(size);
            switch (this.currentState)
            {
            case StringDecoder.State.ReadingSize:
            {
                num = this.sizeDecoder.Decode(buffer, offset, size);
                if (!this.sizeDecoder.IsValueDecoded)
                {
                    break;
                }
                this.encodedSize = this.sizeDecoder.Value;
                if (this.encodedSize > this.sizeQuota)
                {
                    Exception exception = this.OnSizeQuotaExceeded(this.encodedSize);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
                }
                if (this.encodedBytes == null || (int)this.encodedBytes.Length < this.encodedSize)
                {
                    this.encodedBytes = DiagnosticUtility.Utility.AllocateByteArray(this.encodedSize);
                    this.@value       = null;
                }
                this.currentState = StringDecoder.State.ReadingBytes;
                this.bytesNeeded  = this.encodedSize;
                break;
            }

            case StringDecoder.State.ReadingBytes:
            {
                if (this.@value == null || this.valueLengthInBytes != this.encodedSize || this.bytesNeeded != this.encodedSize || size < this.encodedSize || !StringDecoder.CompareBuffers(this.encodedBytes, buffer, offset))
                {
                    num = this.bytesNeeded;
                    if (size < this.bytesNeeded)
                    {
                        num = size;
                    }
                    Buffer.BlockCopy(buffer, offset, this.encodedBytes, this.encodedSize - this.bytesNeeded, num);
                    StringDecoder stringDecoder = this;
                    stringDecoder.bytesNeeded = stringDecoder.bytesNeeded - num;
                    if (this.bytesNeeded != 0)
                    {
                        break;
                    }
                    this.@value             = Encoding.UTF8.GetString(this.encodedBytes, 0, this.encodedSize);
                    this.valueLengthInBytes = this.encodedSize;
                    this.OnComplete(this.@value);
                    break;
                }
                else
                {
                    num = this.bytesNeeded;
                    this.OnComplete(this.@value);
                    break;
                }
            }

            default:
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.InvalidDecoderStateMachine, new object[0])));
            }
            }
            return(num);
        }
예제 #3
0
        public int Decode(byte[] bytes, int offset, int size)
        {
            int num;
            int num1;

            DecoderHelper.ValidateSize(size);
            try
            {
                switch (this.currentState)
                {
                case ServerModeDecoder.State.ReadingVersionRecord:
                {
                    base.ValidateRecordType(FramingRecordType.Version, (FramingRecordType)bytes[offset]);
                    this.currentState = ServerModeDecoder.State.ReadingMajorVersion;
                    num = 1;
                    break;
                }

                case ServerModeDecoder.State.ReadingMajorVersion:
                {
                    this.majorVersion = bytes[offset];
                    base.ValidateMajorVersion(this.majorVersion);
                    this.currentState = ServerModeDecoder.State.ReadingMinorVersion;
                    num = 1;
                    break;
                }

                case ServerModeDecoder.State.ReadingMinorVersion:
                {
                    this.minorVersion = bytes[offset];
                    this.currentState = ServerModeDecoder.State.ReadingModeRecord;
                    num = 1;
                    break;
                }

                case ServerModeDecoder.State.ReadingModeRecord:
                {
                    base.ValidateRecordType(FramingRecordType.Mode, (FramingRecordType)bytes[offset]);
                    this.currentState = ServerModeDecoder.State.ReadingModeValue;
                    num = 1;
                    break;
                }

                case ServerModeDecoder.State.ReadingModeValue:
                {
                    this.mode = (FramingMode)bytes[offset];
                    base.ValidateFramingMode(this.mode);
                    this.currentState = ServerModeDecoder.State.Done;
                    num = 1;
                    break;
                }

                default:
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.InvalidDecoderStateMachine, new object[0]))));
                }
                }
                ServerModeDecoder streamPosition = this;
                streamPosition.StreamPosition = streamPosition.StreamPosition + (long)num;
                num1 = num;
            }
            catch (InvalidDataException invalidDataException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(invalidDataException));
            }
            return(num1);
        }
        public int Decode(byte[] bytes, int offset, int size)
        {
            int num;
            FramingRecordType framingRecordType;
            int num1;

            DecoderHelper.ValidateSize(size);
            try
            {
                switch (this.currentState)
                {
                case ServerSingletonDecoder.State.ReadingViaRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    base.ValidateRecordType(FramingRecordType.Via, framingRecordType);
                    num = 1;
                    this.viaDecoder.Reset();
                    this.currentState = ServerSingletonDecoder.State.ReadingViaString;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingViaString:
                {
                    num = this.viaDecoder.Decode(bytes, offset, size);
                    if (!this.viaDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    this.currentState = ServerSingletonDecoder.State.ReadingContentTypeRecord;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingContentTypeRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    if (framingRecordType != FramingRecordType.KnownEncoding)
                    {
                        base.ValidateRecordType(FramingRecordType.ExtensibleEncoding, framingRecordType);
                        num = 1;
                        this.contentTypeDecoder.Reset();
                        this.currentState = ServerSingletonDecoder.State.ReadingContentTypeString;
                        break;
                    }
                    else
                    {
                        num = 1;
                        this.currentState = ServerSingletonDecoder.State.ReadingContentTypeByte;
                        break;
                    }
                }

                case ServerSingletonDecoder.State.ReadingContentTypeString:
                {
                    num = this.contentTypeDecoder.Decode(bytes, offset, size);
                    if (!this.contentTypeDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    this.currentState = ServerSingletonDecoder.State.PreUpgradeStart;
                    this.contentType  = this.contentTypeDecoder.Value;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingContentTypeByte:
                {
                    this.contentType = ContentTypeStringDecoder.GetString((FramingEncodingType)bytes[offset]);
                    num = 1;
                    this.currentState = ServerSingletonDecoder.State.PreUpgradeStart;
                    break;
                }

                case ServerSingletonDecoder.State.PreUpgradeStart:
                {
                    num = 0;
                    this.currentState = ServerSingletonDecoder.State.ReadingUpgradeRecord;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingUpgradeRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    if (framingRecordType != FramingRecordType.UpgradeRequest)
                    {
                        num = 0;
                        this.currentState = ServerSingletonDecoder.State.ReadingPreambleEndRecord;
                        break;
                    }
                    else
                    {
                        num = 1;
                        this.contentTypeDecoder.Reset();
                        this.currentState = ServerSingletonDecoder.State.ReadingUpgradeString;
                        break;
                    }
                }

                case ServerSingletonDecoder.State.ReadingUpgradeString:
                {
                    num = this.contentTypeDecoder.Decode(bytes, offset, size);
                    if (!this.contentTypeDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    this.currentState = ServerSingletonDecoder.State.UpgradeRequest;
                    this.upgrade      = this.contentTypeDecoder.Value;
                    break;
                }

                case ServerSingletonDecoder.State.UpgradeRequest:
                {
                    num = 0;
                    this.currentState = ServerSingletonDecoder.State.ReadingUpgradeRecord;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingPreambleEndRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    base.ValidateRecordType(FramingRecordType.PreambleEnd, framingRecordType);
                    num = 1;
                    this.currentState = ServerSingletonDecoder.State.Start;
                    break;
                }

                case ServerSingletonDecoder.State.Start:
                {
                    num = 0;
                    this.currentState = ServerSingletonDecoder.State.ReadingEnvelopeRecord;
                    break;
                }

                case ServerSingletonDecoder.State.ReadingEnvelopeRecord:
                {
                    base.ValidateRecordType(FramingRecordType.UnsizedEnvelope, (FramingRecordType)bytes[offset]);
                    num = 1;
                    this.currentState = ServerSingletonDecoder.State.EnvelopeStart;
                    break;
                }

                case ServerSingletonDecoder.State.EnvelopeStart:
                {
                    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]))));
                }
                }
                ServerSingletonDecoder streamPosition = this;
                streamPosition.StreamPosition = streamPosition.StreamPosition + (long)num;
                num1 = num;
            }
            catch (InvalidDataException invalidDataException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(invalidDataException));
            }
            return(num1);
        }
예제 #5
0
        public override int Decode(byte[] bytes, int offset, int size)
        {
            int num;
            FramingRecordType framingRecordType;
            int num1;

            DecoderHelper.ValidateSize(size);
            try
            {
                switch (base.CurrentState)
                {
                case ClientFramingDecoderState.ReadingUpgradeRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    if (framingRecordType != FramingRecordType.UpgradeResponse)
                    {
                        num = 0;
                        base.CurrentState = ClientFramingDecoderState.ReadingAckRecord;
                        break;
                    }
                    else
                    {
                        num = 1;
                        base.CurrentState = ClientFramingDecoderState.UpgradeResponse;
                        break;
                    }
                }

                case ClientFramingDecoderState.ReadingUpgradeMode:
                case ClientFramingDecoderState.ReadingFault:
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(new InvalidDataException(Microsoft.ServiceBus.SR.GetString(Resources.InvalidDecoderStateMachine, new object[0]))));
                }

                case ClientFramingDecoderState.UpgradeResponse:
                {
                    num = 0;
                    base.CurrentState = ClientFramingDecoderState.ReadingUpgradeRecord;
                    break;
                }

                case ClientFramingDecoderState.ReadingAckRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    if (framingRecordType != FramingRecordType.Fault)
                    {
                        base.ValidatePreambleAck(framingRecordType);
                        num = 1;
                        base.CurrentState = ClientFramingDecoderState.Start;
                        break;
                    }
                    else
                    {
                        num = 1;
                        this.faultDecoder = new FaultStringDecoder();
                        base.CurrentState = ClientFramingDecoderState.ReadingFaultString;
                        break;
                    }
                }

                case ClientFramingDecoderState.Start:
                {
                    num = 0;
                    base.CurrentState = ClientFramingDecoderState.ReadingEnvelopeRecord;
                    break;
                }

                case ClientFramingDecoderState.ReadingFaultString:
                {
                    num = this.faultDecoder.Decode(bytes, offset, size);
                    if (!this.faultDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    base.CurrentState = ClientFramingDecoderState.Fault;
                    break;
                }

                case ClientFramingDecoderState.Fault:
                {
                    num = 0;
                    base.CurrentState = ClientFramingDecoderState.ReadingEndRecord;
                    break;
                }

                case ClientFramingDecoderState.ReadingEnvelopeRecord:
                {
                    framingRecordType = (FramingRecordType)bytes[offset];
                    if (framingRecordType == FramingRecordType.End)
                    {
                        num = 1;
                        base.CurrentState = ClientFramingDecoderState.End;
                        break;
                    }
                    else if (framingRecordType != FramingRecordType.Fault)
                    {
                        base.ValidateRecordType(FramingRecordType.SizedEnvelope, framingRecordType);
                        num = 1;
                        base.CurrentState = ClientFramingDecoderState.ReadingEnvelopeSize;
                        this.sizeDecoder.Reset();
                        break;
                    }
                    else
                    {
                        num = 1;
                        this.faultDecoder = new FaultStringDecoder();
                        base.CurrentState = ClientFramingDecoderState.ReadingFaultString;
                        break;
                    }
                }

                case ClientFramingDecoderState.ReadingEnvelopeSize:
                {
                    num = this.sizeDecoder.Decode(bytes, offset, size);
                    if (!this.sizeDecoder.IsValueDecoded)
                    {
                        break;
                    }
                    base.CurrentState        = ClientFramingDecoderState.EnvelopeStart;
                    this.envelopeSize        = this.sizeDecoder.Value;
                    this.envelopeBytesNeeded = this.envelopeSize;
                    break;
                }

                case ClientFramingDecoderState.EnvelopeStart:
                {
                    num = 0;
                    base.CurrentState = ClientFramingDecoderState.ReadingEnvelopeBytes;
                    break;
                }

                case ClientFramingDecoderState.ReadingEnvelopeBytes:
                {
                    num = size;
                    if (num > this.envelopeBytesNeeded)
                    {
                        num = this.envelopeBytesNeeded;
                    }
                    ClientDuplexDecoder clientDuplexDecoder = this;
                    clientDuplexDecoder.envelopeBytesNeeded = clientDuplexDecoder.envelopeBytesNeeded - num;
                    if (this.envelopeBytesNeeded != 0)
                    {
                        break;
                    }
                    base.CurrentState = ClientFramingDecoderState.EnvelopeEnd;
                    break;
                }

                case ClientFramingDecoderState.EnvelopeEnd:
                {
                    num = 0;
                    base.CurrentState = ClientFramingDecoderState.ReadingEnvelopeRecord;
                    break;
                }

                case ClientFramingDecoderState.ReadingEndRecord:
                {
                    base.ValidateRecordType(FramingRecordType.End, (FramingRecordType)bytes[offset]);
                    num = 1;
                    base.CurrentState = ClientFramingDecoderState.End;
                    break;
                }

                case ClientFramingDecoderState.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]))));
                }
                }
                ClientDuplexDecoder streamPosition = this;
                streamPosition.StreamPosition = streamPosition.StreamPosition + (long)num;
                num1 = num;
            }
            catch (InvalidDataException invalidDataException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateException(invalidDataException));
            }
            return(num1);
        }
        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);
        }