<PackageReference Include="Microsoft.Bcl.Memory" Version="11.0.0-preview.2.26159.112" />

System.Text.Unicode.Utf8Utility

static class Utf8Utility
public static int GetIndexOfFirstInvalidUtf8Sequence(ReadOnlySpan<byte> utf8Data, out bool isAscii)

Returns the byte index in utf8Data where the first invalid UTF-8 sequence begins, or -1 if the buffer contains no invalid sequences. Also outs the isAscii parameter stating whether all data observed (up to the first invalid sequence or the end of the buffer, whichever comes first) is ASCII.

public static Byte* GetPointerToFirstInvalidByte(Byte* pInputBuffer, int inputLength, out int utf16CodeUnitCountAdjustment, out int scalarCountAdjustment)

Given an input buffer pInputBuffer of byte length inputLength, returns a pointer to where the first invalid data appears in pInputBuffer.

public static OperationStatus TranscodeToUtf16(Byte* pInputBuffer, int inputLength, Char* pOutputBuffer, int outputCharsRemaining, out byte pInputBufferRemaining, out char pOutputBufferRemaining)

public static OperationStatus TranscodeToUtf8(Char* pInputBuffer, int inputLength, Byte* pOutputBuffer, int outputBytesRemaining, out char pInputBufferRemaining, out byte pOutputBufferRemaining)