65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
|
/*
|
||
|
M2Mqtt - MQTT Client Library for .Net
|
||
|
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Lesser General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 3.0 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Lesser General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Lesser General Public
|
||
|
License along with this library.
|
||
|
*/
|
||
|
|
||
|
|
||
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Class for PINGREQ message from client to broker
|
||
|
/// </summary>
|
||
|
public class MqttMsgPingReq : MqttMsgBase
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Constructor
|
||
|
/// </summary>
|
||
|
public MqttMsgPingReq()
|
||
|
{
|
||
|
this.type = MQTT_MSG_PINGREQ_TYPE;
|
||
|
}
|
||
|
|
||
|
public override byte[] GetBytes()
|
||
|
{
|
||
|
byte[] buffer = new byte[2];
|
||
|
int index = 0;
|
||
|
|
||
|
// first fixed header byte
|
||
|
buffer[index++] = (MQTT_MSG_PINGREQ_TYPE << MSG_TYPE_OFFSET);
|
||
|
buffer[index++] = 0x00;
|
||
|
|
||
|
return buffer;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Parse bytes for a PINGREQ message
|
||
|
/// </summary>
|
||
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||
|
/// <param name="channel">Channel connected to the broker</param>
|
||
|
/// <returns>PINGREQ message instance</returns>
|
||
|
public static MqttMsgPingReq Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
||
|
{
|
||
|
MqttMsgPingReq msg = new MqttMsgPingReq();
|
||
|
|
||
|
// already know remaininglength is zero (MQTT specification),
|
||
|
// so it isn't necessary to read other data from socket
|
||
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||
|
|
||
|
return msg;
|
||
|
}
|
||
|
}
|
||
|
}
|