using System; using System.Runtime.InteropServices; namespace MQTTnet.AspNetCore.Client.Tcp { public static class BufferExtensions { public static ArraySegment GetArray(this Memory memory) { return ((ReadOnlyMemory)memory).GetArray(); } public static ArraySegment GetArray(this ReadOnlyMemory memory) { if (!MemoryMarshal.TryGetArray(memory, out var result)) { throw new InvalidOperationException("Buffer backed by array was expected"); } return result; } } }