/// <summary>子消息读取</summary> /// <param name="stream">数据流</param> /// <param name="context">上下文</param> /// <returns></returns> protected override Boolean OnRead(Stream stream, Object context) { SessionPresent = stream.ReadByte() > 0; ReturnCode = (ConnectReturnCode)stream.ReadByte(); return(true); }
public override void Decode(IByteBuffer buffer) { int remainingLength = RemaingLength; int ackData = buffer.ReadUnsignedShort(ref remainingLength); SessionPresent = ((ackData >> 8) & 0x1) != 0; ConnectReturnCode = (ConnectReturnCode)(ackData & 0xFF); FixedHeader.RemaingLength = remainingLength; }
public void TestConnAckMessage(bool sessionPresent, ConnectReturnCode returnCode) { var packet = new ConnAckPacket(); packet.SessionPresent = sessionPresent; packet.ReturnCode = returnCode; ConnAckPacket recoded = this.RecodePacket(packet, false, true); this.contextMock.Verify(x => x.FireChannelRead(It.IsAny <ConnAckPacket>()), Times.Once); Assert.Equal(packet.SessionPresent, recoded.SessionPresent); Assert.Equal(packet.ReturnCode, recoded.ReturnCode); }
public void ConnAckMessageTest(bool sessionPresent, ConnectReturnCode returnCode) { var packet = new ConnAckPacket(); packet.VariableHeader.SessionPresent = sessionPresent; packet.VariableHeader.ConnectReturnCode = returnCode; var recoded = RecodePacket(packet, false, false); contextMock.Verify(x => x.FireChannelRead(It.IsAny <ConnAckPacket>()), Times.Once); Assert.Equal(packet.VariableHeader.SessionPresent, recoded.VariableHeader.SessionPresent); Assert.Equal(packet.VariableHeader.ConnectReturnCode, recoded.VariableHeader.ConnectReturnCode); }
private int ReadVariableHeader() { // Variable header could potentially be read by more than one thread but we're OK with that. // Just trying to guard against multiple threads reading in the variables at the same time. lock (_msg.SyncLock) { int pos; _msg.ReadRemainingLength(out pos); byte b1 = _msg.MsgBuffer[pos++]; // Skip past reserved header byte byte b2 = _msg.MsgBuffer[pos++]; if (b2 < (byte)ConnectReturnCode.Unknown) { _connectReturnCode = (ConnectReturnCode)b2; } else { _connectReturnCode = ConnectReturnCode.Unknown; } _msg.VariableHeaderRead = true; return(pos); } }
public MqttConnectResult(ConnectReturnCode connectReturn) { ConnectReturn = connectReturn; }
/// <summary> /// Instantiate a new <see cref="ConnectResult"/> where the client got connected. /// <see cref="ConnectError"/> will be <see cref="ConnectError.Ok"/>. /// </summary> /// <param name="sessionState">The session state.</param> /// <param name="connectReturnCode">The connection return code.</param> public ConnectResult(SessionState sessionState, ConnectReturnCode connectReturnCode) { ConnectError = ConnectError.Ok; SessionState = sessionState; ConnectReturnCode = connectReturnCode; }
/// <summary> /// Instantiate a new <see cref="ConnectResult"/> where the result is an error. /// <see cref="SessionState"/> will be <see cref="SessionState.Unknown"/>. /// <see cref="ConnectReturnCode"/> will be <see cref="ConnectReturnCode.Unknown"/>. /// </summary> /// <param name="connectError">The reason the client could not connect.</param> public ConnectResult(ConnectError connectError) { ConnectError = connectError; SessionState = SessionState.Unknown; ConnectReturnCode = ConnectReturnCode.Unknown; }
public ConnAckPacket(bool sessionPresent, ConnectReturnCode returnCode) : base(new ConnAckVariableHeader(sessionPresent, returnCode), new PayloadNone()) { FixedHeader = FixedHeader.CreateStandardHeader(ControlPacketType.CONNACK, (UInt16)(VariableHeader.Encode().Count() + Payload.Encode().Count())); }
public override void Decode(IByteBuffer buffer) { SessionPresent = (buffer.ReadByte() & 0x01) == 1; ConnectReturnCode = (ConnectReturnCode)buffer.ReadByte(); }
private static void Connected(ConnectReturnCode connectResponse) { Console.WriteLine("Connected Ssuccessful!, ConnectReturnCode: " + connectResponse); }
public ConnectResult(bool success, ConnectReturnCode returnCode, Task closeFuture) { Success = success; ReturnCode = returnCode; CloseFuture = closeFuture; }
private int ReadVariableHeader() { // Variable header could potentially be read by more than one thread but we're OK with that. // Just trying to guard against multiple threads reading in the variables at the same time. lock (_msg.SyncLock) { int pos; _msg.ReadRemainingLength(out pos); byte b1 = _msg.MsgBuffer[pos++]; // Skip past reserved header byte byte b2 = _msg.MsgBuffer[pos++]; if (b2 < (byte)ConnectReturnCode.Unknown) { _connectReturnCode = (ConnectReturnCode)b2; } else { _connectReturnCode = ConnectReturnCode.Unknown; } _msg.VariableHeaderRead = true; return pos; } }
public ConnAckVariableHeader(bool sessionPresent, ConnectReturnCode returnCode) { SessionPresent = sessionPresent; ReturnCode = returnCode; }