public bool TryReadTextString(Span <char> destination, out int charsWritten)
{
CborInitialByte header = PeekInitialByte(expectedType: CborMajorType.TextString);
if (header.AdditionalInfo == CborAdditionalInfo.IndefiniteLength)
{
return(TryReadChunkedTextStringConcatenated(destination, out charsWritten));
}
int byteLength = checked ((int)ReadUnsignedInteger(_buffer.Span, header, out int additionalBytes));
EnsureBuffer(1 + additionalBytes + byteLength);
ReadOnlySpan <byte> encodedSlice = _buffer.Span.Slice(1 + additionalBytes, byteLength);
int charLength = ValidateUtf8AndGetCharCount(encodedSlice);
if (charLength > destination.Length)
{
charsWritten = 0;
return(false);
}
s_utf8Encoding.GetChars(encodedSlice, destination);
AdvanceBuffer(1 + additionalBytes + byteLength);
AdvanceDataItemCounters();
charsWritten = charLength;
return(true);
}