diff options
Diffstat (limited to 'src/MessagePack/StringEncoding.cs')
-rw-r--r-- | src/MessagePack/StringEncoding.cs | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/MessagePack/StringEncoding.cs b/src/MessagePack/StringEncoding.cs index 318ce955..f7ba9ecf 100644 --- a/src/MessagePack/StringEncoding.cs +++ b/src/MessagePack/StringEncoding.cs @@ -1,4 +1,7 @@ -using System; +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; namespace MessagePack @@ -7,20 +10,7 @@ namespace MessagePack { internal static readonly Encoding UTF8 = new UTF8Encoding(false); - internal static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan<char> chars, Span<byte> bytes) - { - if (chars.Length == 0) - { - return 0; - } - - fixed (char* pChars = &chars[0]) - fixed (byte* pBytes = &bytes[0]) - { - return encoding.GetBytes(pChars, chars.Length, pBytes, bytes.Length); - } - } - +#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) @@ -33,7 +23,6 @@ namespace MessagePack return encoding.GetString(pBytes, bytes.Length); } } - - internal static unsafe int GetBytes(this Encoding encoding, string chars, Span<byte> bytes) => GetBytes(encoding, chars.AsSpan(), bytes); +#endif } } |