コード例 #1
0
 internal static void ReadFully(ITriflesByteReader source, byte[] buffer, int offset, int count)
 {
     Checker.NotNull(source, "source");
     Checker.NotNull(buffer, "buffer");
     Checker.SpanInRange(buffer.Length, offset, count, "offset", "count");
     ReadFullyNoCheck(source, buffer, offset, count);
 }
コード例 #2
0
 internal static IEnumerable <int> ReadViaArray(ITriflesByteReader source, ulong maxCount, byte[] buffer, bool requireFullCount)
 {
     Checker.NotNull(buffer, "buffer");
     if (maxCount > 0)
     {
         EnsureBufferNonZero(buffer);
     }
     return(ReadViaArrayNoCheck(source, maxCount, buffer, requireFullCount));
 }
コード例 #3
0
        // Repeatedly calls a partial read function until a buffer is full.
        private static void ReadFullyNoCheck(ITriflesByteReader source, byte[] buffer, int index, int count)
        {
            int totalReadLength = ReadAsFullyAsPossibleNoCheck(source, buffer, index, count);

            if (totalReadLength < count)
            {
                // Stream ended before full read.
                throw new EndOfStreamException();
            }
        }
コード例 #4
0
        internal static void ReadViaArray(ITriflesByteReader source, ulong maxCount, Action <byte[], int, int> fillAction, byte[] buffer = null, bool requireFullCount = false)
        {
            Checker.NotNull(fillAction, "fillAction");

            if (buffer == null)
            {
                buffer = new byte[MathTrifles.Min(maxCount, DefaultReadBufferSize)];
            }

            foreach (var countThisPass in ReadViaArray(source, maxCount, buffer, requireFullCount))
            {
                fillAction(buffer, 0, countThisPass);
            }
        }
コード例 #5
0
        internal static void ReadViaArray(ITriflesByteReader source, Action <byte[], int, int> fillAction, byte[] buffer = null)
        {
            Checker.NotNull(fillAction, "fillAction");

            if (buffer == null)
            {
                buffer = new byte[DefaultReadBufferSize];
            }

            foreach (var countThisPass in ReadViaArray(source, buffer))
            {
                fillAction(buffer, 0, countThisPass);
            }
        }
コード例 #6
0
        // Read to the end of the stream using the given byte array as a buffer.
        private static IEnumerable <int> ReadViaArrayNoCheck(ITriflesByteReader source, byte[] buffer)
        {
            var bufferSize = buffer.Length;

            while (true)
            {
                var countThisPass = ReadAsFullyAsPossibleNoCheck(source, buffer, 0, bufferSize);

                if (countThisPass > 0)
                {
                    yield return(countThisPass);
                }

                if (countThisPass < bufferSize)
                {
                    break;
                }
            }
        }
コード例 #7
0
        private static IEnumerable <int> ReadViaArrayNoCheck(ITriflesByteReader source, ulong maxCount, byte[] buffer, bool requireFullCount)
        {
            var bufferSize = buffer.Length;

            while (maxCount > 0)
            {
                var targetCountThisPass = MathTrifles.Min(bufferSize, maxCount);
                var countThisPass       = ReadAsFullyAsPossibleNoCheck(source, buffer, 0, targetCountThisPass);
                if (countThisPass > 0)
                {
                    yield return(countThisPass);

                    maxCount -= (ulong)countThisPass;
                }
            }

            if (requireFullCount && maxCount > 0)
            {
                throw new EndOfStreamException();
            }
        }
コード例 #8
0
        // Repeatedly calls a partial read function until a buffer is full or the stream ends.
        private static int ReadAsFullyAsPossibleNoCheck(ITriflesByteReader source, byte[] buffer, int index, int count)
        {
            int totalReadLength = 0;

            while (totalReadLength < count)
            {
                int readLengthThisPass = source.Read(buffer, index + totalReadLength, count - totalReadLength);

                if (readLengthThisPass > 0)
                {
                    // At least one byte was read.
                    totalReadLength += readLengthThisPass;
                }
                else
                {
                    // Stream ended.
                    break;
                }
            }

            return(totalReadLength);
        }
コード例 #9
0
 /// <summary>
 /// Returns this source as an <see cref="ITriflesByteReader"/>.
 /// </summary>
 /// <param name="source">A source to convert.</param>
 /// <returns><paramref name="source"/> as an <see cref="ITriflesByteReader"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception>
 public static ITriflesByteReader ToTriflesByteReader(this ITriflesByteReader source)
 {
     return(TriflesByteReaderImpl.ToTriflesByteReader(source));
 }
コード例 #10
0
 internal static void ReadViaArray(ITriflesByteReader triflesByteReader, Action <byte[], int, int> fillAction, int maxCount, byte[] buffer, bool requireFullCount)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 internal static ITriflesByteReader ToTriflesByteReader(ITriflesByteReader source)
 {
     Checker.NotNull(source, "source");
     return(source);
 }
コード例 #12
0
 internal static void ReadViaArray(ITriflesByteReader source, long maxCount, Action <byte[], int, int> fillAction, byte[] buffer = null, bool requireFullCount = false)
 {
     ReadViaArray(source, EnsureMaxCountNotNegative(maxCount), fillAction, buffer, requireFullCount);
 }
コード例 #13
0
 internal static IEnumerable <int> ReadViaArray(ITriflesByteReader source, long maxCount, byte[] buffer, bool requireFullCount)
 {
     return(ReadViaArray(source, EnsureMaxCountNotNegative(maxCount), buffer, requireFullCount));
 }
コード例 #14
0
 internal static IEnumerable <int> ReadViaArray(ITriflesByteReader source, byte[] buffer)
 {
     Checker.NotNull(buffer, "buffer");
     EnsureBufferNonZero(buffer);
     return(ReadViaArrayNoCheck(source, buffer));
 }