From 8f59eab2d7c30827d151c6dda9f002424094d741 Mon Sep 17 00:00:00 2001 From: Bruce Wayne Date: Fri, 13 Aug 2021 10:16:43 +0800 Subject: [PATCH] refactor: SOCKS5 udp data use ReadOnlyMemory instead --- Socks5/Models/Socks5UdpReceivePacket.cs | 2 +- Socks5/Utils/Unpack.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Socks5/Models/Socks5UdpReceivePacket.cs b/Socks5/Models/Socks5UdpReceivePacket.cs index f7c16df..20564e8 100644 --- a/Socks5/Models/Socks5UdpReceivePacket.cs +++ b/Socks5/Models/Socks5UdpReceivePacket.cs @@ -16,6 +16,6 @@ public struct Socks5UdpReceivePacket public IPAddress? Address; public string? Domain; public ushort Port; - public Memory Data; + public ReadOnlyMemory Data; } } diff --git a/Socks5/Utils/Unpack.cs b/Socks5/Utils/Unpack.cs index ae3ff8a..e9b8ce0 100644 --- a/Socks5/Utils/Unpack.cs +++ b/Socks5/Utils/Unpack.cs @@ -7,7 +7,6 @@ using System.Buffers.Binary; using System.Collections.Generic; using System.Net; -using System.Runtime.InteropServices; using System.Text; namespace Socks5.Utils @@ -145,7 +144,7 @@ public static Socks5UdpReceivePacket Udp(ReadOnlyMemory buffer) offset += DestinationAddress(res.Type, span[offset..], out res.Address, out res.Domain); res.Port = BinaryPrimitives.ReadUInt16BigEndian(span[offset..]); - res.Data = MemoryMarshal.AsMemory(buffer[(offset + 2)..]); + res.Data = buffer[(offset + 2)..]; return res; }