Example #1
0
        /// <summary>
        /// Reads the specified number of bytes without advancing the read pointer
        /// </summary>
        public byte[] PeekBytes(int numberOfBytes)
        {
            ReadOverflowException.Assert(_lengthBits - _readPosition >= (numberOfBytes * 8));

            byte[] retval = new byte[numberOfBytes];
            BitReaderWriter.ReadBytes(_data, numberOfBytes, _readPosition, retval, 0);
            return(retval);
        }
Example #2
0
        /// <summary>
        /// Reads the specified number of bytes without advancing the read pointer
        /// </summary>
        public void PeekBytes(byte[] into, int offset, int numberOfBytes)
        {
            ReadOverflowException.Assert(_lengthBits - _readPosition >= (numberOfBytes * 8));
            BitBufferException.Assert(offset + numberOfBytes <= into.Length);

            BitReaderWriter.ReadBytes(_data, numberOfBytes, _readPosition, into, offset);
            return;
        }
Example #3
0
        /// <summary>
        /// Reads the specified number of bits into a preallocated array
        /// </summary>
        /// <param name="into">The destination array</param>
        /// <param name="offset">The offset where to start writing in the destination array</param>
        /// <param name="numberOfBits">The number of bits to read</param>
        public BitReader ReadBits(byte[] into, int offset, int numberOfBits)
        {
            ReadOverflowException.Assert(_lengthBits - _readPosition >= numberOfBits);
            BitBufferException.Assert(offset + BitUtility.BytesToHoldBits(numberOfBits) <= into.Length);

            int numberOfWholeBytes = numberOfBits / 8;
            int extraBits          = numberOfBits - (numberOfWholeBytes * 8);

            BitReaderWriter.ReadBytes(_data, numberOfWholeBytes, _readPosition, into, offset);
            _readPosition += (8 * numberOfWholeBytes);

            if (extraBits > 0)
            {
                into[offset + numberOfWholeBytes] = ReadByte(extraBits);
            }

            return(this);
        }