MqttMsgDisconnect.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (c) 2013, 2014 Paolo Patierno
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. http://www.eclipse.org/legal/epl-v10.html
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. Contributors:
  11. Paolo Patierno - initial API and implementation and/or initial documentation
  12. */
  13. namespace uPLibrary.Networking.M2Mqtt.Messages
  14. {
  15. /// <summary>
  16. /// Class for DISCONNECT message from client to broker
  17. /// </summary>
  18. public class MqttMsgDisconnect : MqttMsgBase
  19. {
  20. /// <summary>
  21. /// Constructor
  22. /// </summary>
  23. public MqttMsgDisconnect()
  24. {
  25. this.type = MQTT_MSG_DISCONNECT_TYPE;
  26. }
  27. /// <summary>
  28. /// Parse bytes for a DISCONNECT message
  29. /// </summary>
  30. /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
  31. /// <param name="channel">Channel connected to the broker</param>
  32. /// <returns>DISCONNECT message instance</returns>
  33. public static MqttMsgDisconnect Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
  34. {
  35. MqttMsgDisconnect msg = new MqttMsgDisconnect();
  36. // get remaining length and allocate buffer
  37. int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
  38. // NOTE : remainingLength must be 0
  39. return msg;
  40. }
  41. public override byte[] GetBytes()
  42. {
  43. byte[] buffer = new byte[2];
  44. int index = 0;
  45. // first fixed header byte
  46. buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET);
  47. buffer[index++] = 0x00;
  48. return buffer;
  49. }
  50. public override string ToString()
  51. {
  52. #if TRACE
  53. return this.GetTraceString(
  54. "DISCONNECT",
  55. null,
  56. null);
  57. #else
  58. return base.ToString();
  59. #endif
  60. }
  61. }
  62. }