mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 08:33:01 +08:00
26 lines
886 B
C#
26 lines
886 B
C#
using System;
|
|
|
|
namespace MQTTnet.Core.Packets
|
|
{
|
|
public abstract class MqttBasePacket
|
|
{
|
|
public TResponsePacket CreateResponse<TResponsePacket>()
|
|
{
|
|
var responsePacket = Activator.CreateInstance<TResponsePacket>();
|
|
var responsePacketWithIdentifier = responsePacket as IPacketWithIdentifier;
|
|
if (responsePacketWithIdentifier != null)
|
|
{
|
|
var requestPacketWithIdentifier = this as IPacketWithIdentifier;
|
|
if (requestPacketWithIdentifier == null)
|
|
{
|
|
throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not.");
|
|
}
|
|
|
|
responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier;
|
|
}
|
|
|
|
return responsePacket;
|
|
}
|
|
}
|
|
}
|