public static bool TryDeserialize(this IMqttPacketSerializer serializer, in ReadOnlySequence<byte> input, out MqttBasePacket packet, out SequencePosition consumed, out SequencePosition observed)
public static bool TryDeserialize(this IMqttPacketSerializer serializer, in ReadOnlySequence<byte> input, out MqttBasePacket packet, out SequencePosition consumed, out SequencePosition observed)
{
{
packet = null;
packet = null;
consumed = input.Start;
observed = input.End;
var copy = input;
var copy = input;
var header = copy.ReadHeader();
if (header == null || copy.Length < header.BodyLength)
if (copy.Length < 2)
{
return false;
}
var fixedheader = copy.First.Span[0];
if (!TryReadBodyLength(ref copy, out var bodyLength))
{
{
consumed = input.Start;
observed = input.End;
return false;
return false;
}
}
var bodySlice = copy.Slice(0, header.BodyLength);
var bodySlice = copy.Slice(0, bodyLength);
using (var body = new MemoryStream(bodySlice.GetArray()))
using (var body = new MemoryStream(bodySlice.GetArray()))