From e99f35f437c8cf9c2293836cd74604911bd6ab01 Mon Sep 17 00:00:00 2001 From: Ruslan Pyrch Date: Sat, 6 Jul 2024 20:14:46 +0300 Subject: [PATCH] add NetDataWriter.AsReadOnlySpan() --- LiteNetLib/Utils/NetDataWriter.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LiteNetLib/Utils/NetDataWriter.cs b/LiteNetLib/Utils/NetDataWriter.cs index 528dcb53..c2579658 100644 --- a/LiteNetLib/Utils/NetDataWriter.cs +++ b/LiteNetLib/Utils/NetDataWriter.cs @@ -29,6 +29,13 @@ public int Length get => _position; } +#if LITENETLIB_SPANS || NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1 || NETCOREAPP3_1 || NET5_0 || NETSTANDARD2_1 + public ReadOnlySpan AsReadOnlySpan() + { + return new ReadOnlySpan(_data, 0, _position); + } +#endif + public static readonly ThreadLocal uTF8Encoding = new ThreadLocal(() => new UTF8Encoding(false, true)); public NetDataWriter() : this(true, InitialSize)