1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using uPLibrary.Networking.M2Mqtt.Exceptions;
- namespace uPLibrary.Networking.M2Mqtt.Messages
- {
-
-
-
- public class MqttMsgDisconnect : MqttMsgBase
- {
-
-
-
- public MqttMsgDisconnect()
- {
- this.type = MQTT_MSG_DISCONNECT_TYPE;
- }
-
-
-
-
-
-
-
- public static MqttMsgDisconnect Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
- {
- MqttMsgDisconnect msg = new MqttMsgDisconnect();
- if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
- {
-
- if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_DISCONNECT_FLAG_BITS)
- throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
- }
-
- int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
-
- return msg;
- }
- public override byte[] GetBytes(byte protocolVersion)
- {
- byte[] buffer = new byte[2];
- int index = 0;
-
- if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
- buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_DISCONNECT_FLAG_BITS;
- else
- buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET);
- buffer[index++] = 0x00;
- return buffer;
- }
- public override string ToString()
- {
- #if TRACE
- return this.GetTraceString(
- "DISCONNECT",
- null,
- null);
- #else
- return base.ToString();
- #endif
- }
- }
- }
|