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