From f2a81eaac976522d260c090b0748515c9b12ef8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Fri, 6 Dec 2024 14:33:50 +0800 Subject: [PATCH] MqttPacketInspector: add FillReceiveBuffer(ReadOnlySequence) method. --- Source/MQTTnet/Adapter/MqttPacketInspector.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/MQTTnet/Adapter/MqttPacketInspector.cs b/Source/MQTTnet/Adapter/MqttPacketInspector.cs index e7983717d..f646d49f6 100644 --- a/Source/MQTTnet/Adapter/MqttPacketInspector.cs +++ b/Source/MQTTnet/Adapter/MqttPacketInspector.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Buffers; using System.IO; using System.Threading.Tasks; using MQTTnet.Diagnostics.Logger; @@ -81,6 +82,22 @@ public void FillReceiveBuffer(ReadOnlySpan buffer) _receivedPacketBuffer?.Write(buffer); } + public void FillReceiveBuffer(ReadOnlySequence buffer) + { + if (!_asyncEvent.HasHandlers) + { + return; + } + + if (_receivedPacketBuffer != null) + { + foreach (var memory in buffer) + { + _receivedPacketBuffer.Write(memory.Span); + } + } + } + async Task InspectPacket(byte[] buffer, MqttPacketFlowDirection direction) { try