You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BufferExtensions.cs 630 B

12345678910111213141516171819202122
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace MQTTnet.AspNetCore.Client.Tcp
  4. {
  5. public static class BufferExtensions
  6. {
  7. public static ArraySegment<byte> GetArray(this Memory<byte> memory)
  8. {
  9. return ((ReadOnlyMemory<byte>)memory).GetArray();
  10. }
  11. public static ArraySegment<byte> GetArray(this ReadOnlyMemory<byte> memory)
  12. {
  13. if (!MemoryMarshal.TryGetArray(memory, out var result))
  14. {
  15. throw new InvalidOperationException("Buffer backed by array was expected");
  16. }
  17. return result;
  18. }
  19. }
  20. }