Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/MessagePack/StringEncoding.cs')
-rw-r--r--src/MessagePack/StringEncoding.cs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/MessagePack/StringEncoding.cs b/src/MessagePack/StringEncoding.cs
index dfde7d40..caa6336d 100644
--- a/src/MessagePack/StringEncoding.cs
+++ b/src/MessagePack/StringEncoding.cs
@@ -1,9 +1,21 @@
-using System.Text;
+using System;
+using System.Text;
namespace MessagePack
{
internal static class StringEncoding
{
- public static readonly Encoding UTF8 = new UTF8Encoding(false);
+ internal static readonly Encoding UTF8 = new UTF8Encoding(false);
+
+ internal static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan<char> chars, Span<byte> bytes)
+ {
+ fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = &bytes[0])
+ {
+ return encoding.GetBytes(pChars, chars.Length, pBytes, bytes.Length);
+ }
+ }
+
+ internal static unsafe int GetBytes(this Encoding encoding, string chars, Span<byte> bytes) => GetBytes(encoding, chars.AsSpan(), bytes);
}
}