/// <summary>
 /// Writes blocks of bytes to the current sink using data read from a list.
 /// </summary>
 /// <param name="sink"></param>
 /// <param name="source"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 /// <param name="bufferSize">
 /// The size of the temporary buffer used to copy elements from the provided source.
 /// </param>
 internal static void Write(ITriflesByteWriter sink, IList <byte> source, int offset, int count, int bufferSize = 0)
 {
     Checker.NotNull(sink, "sink");
     Checker.NotNull(source, "source");
     Checker.SpanInRange(source.Count, offset, count, "offset", "count");
     WriteNoCheck(sink, source, offset, count, bufferSize);
 }
 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);
 }
 public StreamTriflesByteWriter(Stream sink)
 {
     Checker.NotNull(sink, "sink");
     if (!sink.CanWrite)
     {
         throw new ArgumentException("This stream does not support writing.", "sink");
     }
     this.sink = sink;
 }
 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));
 }
 public StreamTriflesByteReader(Stream source)
 {
     Checker.NotNull(source, "source");
     if (!source.CanRead)
     {
         throw new ArgumentException("This stream does not support reading.", "source");
     }
     this.source = source;
 }
        // Pre-check parameters for Get*Bytes()
        private static void CheckGetNBytes(IList <byte> value, int startIndex, int count)
        {
            Checker.NotNull(value, "value");
            int size = value.Count;

            if (startIndex < 0 || startIndex > size - count)
            {
                throw new ArgumentOutOfRangeException("startIndex");
            }
        }
        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);
            }
        }
        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);
            }
        }
        // Pre-check parameters for Swap*Bytes()
        private static void CheckSwapN(byte[] buffer, int startIndex, int length)
        {
            Checker.NotNull(buffer, "buffer");
            int size = buffer.Length;

            if (startIndex < 0 || startIndex > size)
            {
                throw new ArgumentOutOfRangeException("startIndex");
            }
            if (startIndex > size - length)
            {
                throw new ArgumentOutOfRangeException("length");
            }
        }
 public BinaryWriterTriflesByteWriter(BinaryWriter sink)
 {
     Checker.NotNull(sink, "sink");
     this.sink = sink;
 }
 internal static ITriflesByteWriter ToTriflesByteWriter(ITriflesByteWriter sink)
 {
     Checker.NotNull(sink, "sink");
     return(sink);
 }
 /// <summary>
 /// Writes blocks of bytes to the current sink using data read from a sequence.
 /// </summary>
 /// <param name="sink"></param>
 /// <param name="source"></param>
 /// <param name="bufferSize">
 /// The size of the temporary buffer used to copy elements from the provided source.
 /// </param>
 internal static void Write(ITriflesByteWriter sink, IEnumerable <byte> source, int bufferSize = 0)
 {
     Checker.NotNull(sink, "sink");
     Checker.NotNull(source, "source");
     WriteNoCheck(sink, source, bufferSize);
 }
 /// <summary>
 /// Writes blocks of bytes to the current sink using data read from a list.
 /// </summary>
 /// <param name="sink"></param>
 /// <param name="source"></param>
 /// <param name="bufferSize">
 /// The size of the temporary buffer used to copy elements from the provided source.
 /// </param>
 internal static void Write(ITriflesByteWriter sink, IList <byte> source, int bufferSize = 0)
 {
     Checker.NotNull(sink, "sink");
     Checker.NotNull(source, "source");
     WriteNoCheck(sink, source, 0, source.Count, bufferSize);
 }
示例#14
0
 /// <summary>
 /// Returns a deferred option that will contain the value of the dictionary at the given key,
 /// if the dictionary contains the key, or an empty option otherwise. Since this option is
 /// deferred, repeated evaluations (of <see cref="IOpt{T}.Fix()"/>, <see
 /// cref="OptExtensions.Single{T}(IOpt{T})"/>, and so forth) reflect the current state of the
 /// dictionary rather than its state as of the call to this method.
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="source"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static IOpt <TValue> ValueOpt <TKey, TValue>(this IDictionary <TKey, TValue> source, TKey key)
 {
     Checker.NotNull(source, "source");
     return(Opt.Defer(() => ValueFixOpt0(source, key)));
 }
 public BinaryReaderTriflesByteReader(BinaryReader source)
 {
     Checker.NotNull(source, "source");
     this.source = source;
 }
 internal static ITriflesByteReader ToTriflesByteReader(ITriflesByteReader source)
 {
     Checker.NotNull(source, "source");
     return(source);
 }
示例#17
0
 /// <summary>
 /// Creates an option whose value is the result of calling the given function.
 /// </summary>
 /// <param name="getCurrentFixedValue">A function that returns the current value of the option as an <see cref="Opt{T}"/>.</param>
 public DeferredOpt(Func <Opt <T> > getCurrentFixedValue)
 {
     this.getCurrentFixedValue = Checker.NotNull(getCurrentFixedValue, "getCurrentFixedValue");
 }
 internal static IEnumerable <int> ReadViaArray(ITriflesByteReader source, byte[] buffer)
 {
     Checker.NotNull(buffer, "buffer");
     EnsureBufferNonZero(buffer);
     return(ReadViaArrayNoCheck(source, buffer));
 }