예제 #1
0
        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);
        }
예제 #2
0
        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);
        }