public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel) { int num1 = 0; MqttMsgUnsuback mqttMsgUnsuback1 = new MqttMsgUnsuback(); if (protocolVersion == (byte)4 && ((uint)fixedHeaderFirstByte & 15U) > 0U) { throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits); } byte[] buffer = new byte[MqttMsgBase.decodeRemainingLength(channel)]; channel.Receive(buffer); MqttMsgUnsuback mqttMsgUnsuback2 = mqttMsgUnsuback1; byte[] numArray1 = buffer; int index1 = num1; int num2 = checked (index1 + 1); int num3 = (int)checked ((ushort)((int)numArray1[index1] << 8 & 65280)); mqttMsgUnsuback2.messageId = (ushort)num3; MqttMsgUnsuback mqttMsgUnsuback3 = mqttMsgUnsuback1; int messageId = (int)mqttMsgUnsuback3.messageId; byte[] numArray2 = buffer; int index2 = num2; int num4 = checked (index2 + 1); int num5 = (int)numArray2[index2]; mqttMsgUnsuback3.messageId = (ushort)(messageId | num5); return(mqttMsgUnsuback1); }
/// <summary> /// Parse bytes for a UNSUBACK message /// </summary> /// <param name="fixedHeaderFirstByte">First fixed header byte</param> /// <param name="protocolVersion">Protocol Version</param> /// <param name="channel">Channel connected to the broker</param> /// <returns>UNSUBACK message instance</returns> public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel) { byte[] buffer; int index = 0; MqttMsgUnsuback msg = new MqttMsgUnsuback(); if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1) { // [v3.1.1] check flag bits if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_UNSUBACK_FLAG_BITS) throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits); } // get remaining length and allocate buffer int remainingLength = MqttMsgBase.decodeRemainingLength(channel); buffer = new byte[remainingLength]; // read bytes from socket... channel.Receive(buffer); // message id msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00); msg.messageId |= (buffer[index++]); return msg; }
/// <summary> /// Parse bytes for a UNSUBACK message /// </summary> /// <param name="fixedHeaderFirstByte">First fixed header byte</param> /// <param name="protocolVersion">Protocol Version</param> /// <param name="channel">Channel connected to the broker</param> /// <returns>UNSUBACK message instance</returns> public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel) { byte[] buffer; int index = 0; MqttMsgUnsuback msg = new MqttMsgUnsuback(); if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1) { // [v3.1.1] check flag bits if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_UNSUBACK_FLAG_BITS) { throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits); } } // get remaining length and allocate buffer int remainingLength = MqttMsgBase.decodeRemainingLength(channel); buffer = new byte[remainingLength]; // read bytes from socket... channel.Receive(buffer); // message id msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00); msg.messageId |= (buffer[index++]); return(msg); }
/// <summary> /// Parse bytes for a UNSUBACK message /// </summary> /// <param name="fixedHeaderFirstByte">First fixed header byte</param> /// <param name="channel">Channel connected to the broker</param> /// <returns>UNSUBACK message instance</returns> public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel) { byte[] buffer; int index = 0; MqttMsgUnsuback msg = new MqttMsgUnsuback(); // get remaining length and allocate buffer int remainingLength = MqttMsgBase.decodeRemainingLength(channel); buffer = new byte[remainingLength]; // read bytes from socket... channel.Receive(buffer); // message id msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00); msg.messageId |= (buffer[index++]); return msg; }
/// <summary> /// Parse bytes for a UNSUBACK message /// </summary> /// <param name="fixedHeaderFirstByte">First fixed header byte</param> /// <param name="socket">Socket connected to the broker</param> /// <returns>UNSUBACK message instance</returns> public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, Socket socket) { byte[] buffer; int index = 0; MqttMsgUnsuback msg = new MqttMsgUnsuback(); // get remaining length and allocate buffer int remainingLength = MqttMsgBase.decodeRemainingLength(socket); buffer = new byte[remainingLength]; // read bytes from socket... socket.Receive(buffer); // message id msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00); msg.messageId |= (buffer[index++]); return(msg); }
/// <summary> /// Send UNSUBACK message to the client /// </summary> /// <param name="messageId">Message Id for the UNSUBSCRIBE message that is being acknowledged</param> public void Unsuback(ushort messageId) { MqttMsgUnsuback unsuback = new MqttMsgUnsuback(); unsuback.MessageId = messageId; this.Send(unsuback); }