MqttMsgPingResp.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. using System;
  14. namespace uPLibrary.Networking.M2Mqtt.Messages
  15. {
  16. /// <summary>
  17. /// Class for PINGRESP message from client to broker
  18. /// </summary>
  19. public class MqttMsgPingResp : MqttMsgBase
  20. {
  21. /// <summary>
  22. /// Constructor
  23. /// </summary>
  24. public MqttMsgPingResp()
  25. {
  26. this.type = MQTT_MSG_PINGRESP_TYPE;
  27. }
  28. /// <summary>
  29. /// Parse bytes for a PINGRESP message
  30. /// </summary>
  31. /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
  32. /// <param name="channel">Channel connected to the broker</param>
  33. /// <returns>PINGRESP message instance</returns>
  34. public static MqttMsgPingResp Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
  35. {
  36. MqttMsgPingResp msg = new MqttMsgPingResp();
  37. // already know remaininglength is zero (MQTT specification),
  38. // so it isn't necessary to read other data from socket
  39. int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
  40. return msg;
  41. }
  42. public override byte[] GetBytes()
  43. {
  44. byte[] buffer = new byte[2];
  45. int index = 0;
  46. // first fixed header byte
  47. buffer[index++] = (MQTT_MSG_PINGRESP_TYPE << MSG_TYPE_OFFSET);
  48. buffer[index++] = 0x00;
  49. return buffer;
  50. }
  51. public override string ToString()
  52. {
  53. #if TRACE
  54. return this.GetTraceString(
  55. "PINGRESP",
  56. null,
  57. null);
  58. #else
  59. return base.ToString();
  60. #endif
  61. }
  62. }
  63. }