Nelze vybrat více než 25 témat
Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
|
- using System;
-
- namespace MQTTnet.Core.Packets
- {
- public static class MqttPacketExtensions
- {
- public static TResponsePacket CreateResponse<TResponsePacket>(this MqttBasePacket packet)
- {
- if (packet == null) throw new ArgumentNullException(nameof(packet));
-
- var responsePacket = Activator.CreateInstance<TResponsePacket>();
-
- if (responsePacket is IMqttPacketWithIdentifier responsePacketWithIdentifier)
- {
- var requestPacketWithIdentifier = packet as IMqttPacketWithIdentifier;
- if (requestPacketWithIdentifier == null)
- {
- throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not.");
- }
-
- responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier;
- }
-
- return responsePacket;
- }
- }
- }
|