/// <summary> /// Reads the specified number of bytes 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="numberOfBytes">The number of bytes to read</param> public void ReadBytes(byte[] into, int offset, int numberOfBytes) { Debug.CheckArgument(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError); Debug.CheckArgument(offset + numberOfBytes <= into.Length); BitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, into, offset); m_readPosition += (8 * numberOfBytes); return; }
/// <summary> /// Reads the specified number of bytes /// </summary> public byte[] ReadBytes(int numberOfBytes) { Debug.CheckArgument(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError); byte[] retval = new byte[numberOfBytes]; BitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, retval, 0); m_readPosition += (8 * numberOfBytes); return(retval); }
/// <summary> /// Reads the specified number of bytes and returns true for success /// </summary> public bool ReadBytes(int numberOfBytes, out byte[] result) { if (m_bitLength - m_readPosition + 7 < (numberOfBytes * 8)) { result = null; return(false); } result = new byte[numberOfBytes]; BitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, result, 0); m_readPosition += (8 * numberOfBytes); return(true); }
/// <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) { Debug.CheckArgument(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError); Debug.CheckArgument(offset + BitUtils.BytesToHoldBits(numberOfBits) <= into.Length); int numberOfWholeBytes = numberOfBits / 8; int extraBits = numberOfBits - (numberOfWholeBytes * 8); BitWriter.ReadBytes(m_data, numberOfWholeBytes, m_readPosition, into, offset); m_readPosition += (8 * numberOfWholeBytes); if (extraBits > 0) { into[offset + numberOfWholeBytes] = ReadByte(extraBits); } return; }