/// <summary>
        /// Writes the specified bytes to the other byte array.
        /// </summary>
        /// <param name="bytes">The bytes to write.</param>
        /// <param name="to">The byte array to write to.</param>
        /// <param name="position">The current position in the array (used for resizing)</param>
        /// <param name="offset">The offset from the current position of the array.</param>
        /// <param name="readSize">How many bytes to read from the bytes array.
        /// Specify -1 to make equal to the bytes array's length</param>
        /// <exception cref="Dash.Net.NetException"></exception>
        public static void WriteBytes(byte[] bytes, ref byte[] to, ref int position, int offset, int readSize)
        {
            if (readSize == -1)
            {
                readSize = bytes.Length;                 // Special case to save memory
            }
            int start = position;

            MakeRoom(ref to, readSize, position);
            position += readSize;

            NetException.Assert(readSize > to.Length - offset || offset > to.Length, NetException.PastBuffer);

            if (readSize > bytes.Length)
            {
                readSize = bytes.Length;
            }
            int forEnd = Math.Min(to.Length - start, bytes.Length);

            for (int i = offset; i < forEnd; i++)
            {
                to[start + i] = bytes[i];
            }
        }
Beispiel #2
0
        // PEEKING //
        #region Peeking

        /// <summary>
        /// Peeks the next byte in the buffer.
        /// </summary>
        /// <returns>The next byte.</returns>
        public byte PeekByte()
        {
            PreRead();
            NetException.Assert(position + 1 > data.Length, NetException.PastBuffer);
            return(data[position]);
        }