public async Task <int> Write(DbDataReader reader, Memory <byte> buffer, CancellationToken ct = default) { int rowCount = 0; int pos = 0; buffer.Span[pos++] = OpenBracket; if (!await reader.ReadAsync(ct).ConfigureAwait(false)) { return(0); } pos += _serializer.Write(reader, buffer.Span.Slice(pos, _bufferSize)); rowCount++; while (await reader.ReadAsync(ct).ConfigureAwait(false)) { buffer.Span[pos++] = Comma; buffer.Span[pos++] = Newline; pos += _serializer.Write(reader, buffer.Span.Slice(pos, _bufferSize)); rowCount++; } buffer.Span[pos] = CloseBracket; return(rowCount); }
public async Task <int> WriteSingle(DbDataReader reader, Memory <byte> buffer, CancellationToken ct = default) { if (await reader.ReadAsync(ct).ConfigureAwait(false)) { return(_serializer.Write(reader, buffer.Span)); } return(0); }