mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 09:43:05 +08:00
removed dead code and make new connection context an opt in so kestrel 2.0 still works
This commit is contained in:
@@ -97,46 +97,12 @@ namespace MQTTnet.AspNetCore
|
||||
{
|
||||
foreach (var packet in packets)
|
||||
{
|
||||
await WriteAsync(packet);
|
||||
var buffer = PacketSerializer.Serialize(packet);
|
||||
await Connection.Transport.Output.WriteAsync(buffer.AsMemory());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task WriteAsync(MqttBasePacket packet)
|
||||
{
|
||||
var buffer = PacketSerializer.Serialize(packet);
|
||||
await Connection.Transport.Output.WriteAsync(buffer.AsMemory());
|
||||
}
|
||||
|
||||
private int messageId;
|
||||
|
||||
|
||||
public event EventHandler ReadingPacketStarted;
|
||||
public event EventHandler ReadingPacketCompleted;
|
||||
|
||||
public Task PublishAsync(MqttPublishPacket packet)
|
||||
{
|
||||
if (!packet.PacketIdentifier.HasValue && packet.QualityOfServiceLevel > MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce)
|
||||
{
|
||||
packet.PacketIdentifier = (ushort)Interlocked.Increment(ref messageId);
|
||||
}
|
||||
return WriteAsync(packet);
|
||||
}
|
||||
|
||||
public Task SubscribeAsync(MqttSubscribePacket packet)
|
||||
{
|
||||
if (!packet.PacketIdentifier.HasValue)
|
||||
{
|
||||
packet.PacketIdentifier = (ushort)Interlocked.Increment(ref messageId);
|
||||
}
|
||||
return WriteAsync(packet);
|
||||
}
|
||||
|
||||
public Task ConnectAsync(MqttConnectPacket packet)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packet.ClientId))
|
||||
{
|
||||
packet.ClientId = Guid.NewGuid().ToString();
|
||||
}
|
||||
return WriteAsync(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Exceptions;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Serializer;
|
||||
|
||||
namespace MQTTnet.AspNetCore
|
||||
@@ -59,30 +58,6 @@ namespace MQTTnet.AspNetCore
|
||||
return input.ToArray();
|
||||
}
|
||||
|
||||
public static bool TryDeserialize(this IMqttPacketSerializer serializer, ref ReadOnlySequence<byte> input, out MqttBasePacket packet)
|
||||
{
|
||||
packet = null;
|
||||
var copy = input;
|
||||
if (copy.Length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var fixedheader = copy.First.Span[0];
|
||||
if (!TryReadBodyLength(ref copy, out var bodyLength))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input = copy.Slice(bodyLength);
|
||||
var bodySlice = copy.Slice(0, bodyLength);
|
||||
using (var body = new MemoryStream(bodySlice.GetArray()))
|
||||
{
|
||||
packet = serializer.Deserialize(new ReceivedMqttPacket(fixedheader, body));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryDeserialize(this IMqttPacketSerializer serializer, in ReadOnlySequence<byte> input, out MqttBasePacket packet, out SequencePosition consumed, out SequencePosition observed)
|
||||
{
|
||||
packet = null;
|
||||
|
||||
Reference in New Issue
Block a user