Beispiel #1
0
 public static long ReadLines(Stream stream, Encoding encoding, byte[] workingBuffer, string separator,
                              NewValueAsSpan onNewValue, IMetricsHost metrics = null, CancellationToken cancellationToken = default)
 {
     unsafe
     {
         NewLine onNewLine = (lineNumber, partial, start, length, e, m) =>
         {
             LineValuesReader.ReadValues(lineNumber, start, length, e, separator, onNewValue, m);
         };
         return(ReadLines(stream, encoding, workingBuffer, onNewLine, metrics, cancellationToken));
     }
 }
        public static long ReadLines(Stream stream, Encoding encoding, byte[] buffer, string separator,
                                     NewValueAsSpan onNewValue, ISafeLogger logger = null, IMetricsHost metrics = null,
                                     CancellationToken cancellationToken           = default)
        {
            unsafe
            {
                return(ReadLines(stream, encoding, buffer, OnNewLine, logger, metrics, cancellationToken));

                void OnNewLine(long lineNumber, bool partial, byte *start, int length, Encoding e)
                {
                    LineValuesReader.ReadValues(lineNumber, start, length, e, separator, onNewValue);
                }
            }
        }
Beispiel #3
0
        public static void ReadValues(long lineNumber, ReadOnlySpan <byte> line, Encoding encoding, byte[] separator,
                                      NewValueAsSpan newValue)
        {
            var position = 0;

            while (true)
            {
                var next = line.IndexOf(separator);
                if (next == -1)
                {
                    newValue?.Invoke(lineNumber, position, line, encoding);
                    break;
                }

                newValue?.Invoke(lineNumber, position, line.Slice(0, next), encoding);
                line      = line.Slice(next + separator.Length);
                position += next + separator.Length;
            }
        }
Beispiel #4
0
 public static long ReadLines(Stream stream, Encoding encoding, string separator, NewValueAsSpan onNewValue,
                              IMetricsHost metrics = null, CancellationToken cancellationToken = default)
 {
     return(ReadLines(stream, encoding, Constants.Buffer, separator, onNewValue, metrics, cancellationToken));
 }
Beispiel #5
0
 public static unsafe void ReadValues(long lineNumber, byte *start, int length, Encoding encoding,
                                      byte[] separator, NewValueAsSpan newValue)
 {
     ReadValues(lineNumber, new ReadOnlySpan <byte>(start, length), encoding, separator, newValue);
 }
Beispiel #6
0
 public static unsafe void ReadValues(long lineNumber, byte *start, int length, Encoding encoding,
                                      string separator, NewValueAsSpan newValue)
 {
     ReadValues(lineNumber, start, length, encoding, encoding.GetSeparatorBuffer(separator), newValue);
 }