/// <summary> /// Reads an array of values from a <see cref="BitStream"/>. /// </summary> /// <param name="bs">The <see cref="BitStream"/> to read from.</param> /// <param name="count">The number of values to read.</param> /// <returns>The array of read values.</returns> public static uint[] ReadUInts(this BitStream bs, int count) { var ret = new uint[count]; for (var i = 0; i < count; i++) { ret[i] = bs.ReadUInt(); } return(ret); }
/// <summary> /// Checks that the rest of the <paramref name="bitStream"/> contains only unset bits. /// </summary> /// <param name="bitStream"><see cref="BitStream"/> to check.</param> /// <returns>True if all of the bits in the <paramref name="bitStream"/> are unset; otherwise false.</returns> static bool RestOfStreamIsZero(BitStream bitStream) { // Read 32 bits at a time while (bitStream.PositionBits + 32 <= bitStream.LengthBits) { if (bitStream.ReadUInt() != 0) return false; } // Read the remaining bits if (bitStream.ReadUInt(bitStream.LengthBits - bitStream.PositionBits) != 0) return false; return true; }
/// <summary> /// Reads the next message ID. /// </summary> /// <param name="reader">The <see cref="BitStream"/> to read the ID from.</param> /// <returns>The next message ID.</returns> protected virtual MessageProcessorID ReadMessageID(BitStream reader) { return (MessageProcessorID)reader.ReadUInt(_messageIDBitLength); }
/// <summary> /// Reads an unsigned integer of up to 32 bits. /// </summary> /// <param name="name">Unused by the <see cref="BinaryValueReader"/>.</param> /// <param name="bits">Number of bits to read.</param> /// <returns>Value read from the reader.</returns> public uint ReadUInt(string name, int bits) { return(_reader.ReadUInt(bits)); }