public void StartReading(TimeSpan receiveTimeout, Action connectionDequeuedCallback) { this.decoder = new ServerModeDecoder(); this.receiveTimeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(receiveTimeout); base.ConnectionDequeuedCallback = connectionDequeuedCallback; bool flag = false; Exception exception = null; try { flag = this.ContinueReading(); } catch (Exception exception2) { Exception exception1 = exception2; if (Fx.IsFatal(exception1)) { throw; } flag = true; exception = exception1; } if (flag) { this.Complete(exception); } }
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); }