/// <summary> /// Reads the specified number of bytes without advancing the read pointer /// </summary> public byte[] PeekBytes(int numberOfBytes) { NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError); byte[] retval = new byte[numberOfBytes]; NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, retval, 0); return(retval); }
/// <summary> /// Reads the specified number of bytes without advancing the read pointer /// </summary> public void PeekBytes(byte[] into, int offset, int numberOfBytes) { NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError); NetException.Assert(offset + numberOfBytes <= into.Length); NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, into, offset); return; }
/// <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 void ReadBits(byte[] into, int offset, int numberOfBits) { NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError); NetException.Assert(offset + NetUtility.BytesToHoldBits(numberOfBits) <= into.Length); int numberOfWholeBytes = numberOfBits / 8; int extraBits = numberOfBits - (numberOfWholeBytes * 8); NetBitWriter.ReadBytes(m_data, numberOfWholeBytes, m_readPosition, into, offset); m_readPosition += (8 * numberOfWholeBytes); if (extraBits > 0) { into[offset + numberOfWholeBytes] = ReadByte(extraBits); } return; }