blob: f7ba9ecfe37c13b53f3bab4bb0ea9d1ae371883f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace MessagePack
{
internal static class StringEncoding
{
internal static readonly Encoding UTF8 = new UTF8Encoding(false);
#if !NETCOREAPP2_1 // Define the extension method only where an instance method does not already exist.
internal static unsafe string GetString(this Encoding encoding, ReadOnlySpan<byte> bytes)
{
if (bytes.Length == 0)
{
return string.Empty;
}
fixed (byte* pBytes = bytes)
{
return encoding.GetString(pBytes, bytes.Length);
}
}
#endif
}
}
|