namespace System.Text;
///
/// Extensions for the type.
///
internal static class EncodingExtensions
{
///
/// Encodes into a span of bytes a set of characters from the specified read-only span.
///
/// The input instance to use.
/// The span containing the set of characters to encode.
/// The byte span to hold the encoded bytes.
/// The number of encoded bytes.
public static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan chars, Span bytes)
{
fixed (char* charsPtr = chars)
fixed (byte* bytesPtr = bytes)
{
return encoding.GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length);
}
}
}