public async ValueTask WriteStringAsync(StringBuilder sb, Stream stream, CancellationToken token) { var remaining = FreeCapacity; var value = sb.ToString(); // Try with an approximate cell value length var bytesNeeded = value.Length * Utf8Helper.MaxBytePerChar; if (bytesNeeded > remaining) { // Try with a more accurate cell value length bytesNeeded = Utf8Helper.GetByteCount(value); } if (bytesNeeded > remaining) { await FlushToStreamAsync(stream, token).ConfigureAwait(false); } // Write whole value if it fits in the buffer if (bytesNeeded <= _buffer.Length) { _index += Utf8Helper.GetBytes(value, GetSpan()); return; } // Otherwise, write value piece by piece var valueIndex = 0; while (!WriteLongString(value.AsSpan(), ref valueIndex)) { await FlushToStreamAsync(stream, token).ConfigureAwait(false); } }
private static int GetSheetElementByteCount(string path, int sheetId) { var sheetIdDigits = sheetId.GetNumberOfDigits(); return(SheetStart.Length + Utf8Helper.GetByteCount(path) + BetweenPathAndRelationId.Length + SharedMetadata.RelationIdPrefix.Length + sheetIdDigits + RelationEnd.Length); }
private static int GetSheetElementByteCount(string path) { return(SheetStart.Length + Utf8Helper.GetByteCount(path) + SheetEnd.Length); }