MiscUtil.IO.EndianBinaryReader.ReadBigEndian7BitEncodedInt C# (CSharp) Method

ReadBigEndian7BitEncodedInt() public method

Reads a 7-bit encoded integer from the stream. This is stored with the most significant information first, with 7 bits of information per byte of value, and the top bit as a continuation flag. This method is not affected by the endianness of the bit converter.
public ReadBigEndian7BitEncodedInt ( ) : int
return int
        public int ReadBigEndian7BitEncodedInt()
        {
            CheckDisposed();

            int ret=0;
            for (int i=0; i < 5; i++)
            {
                int b = stream.ReadByte();
                if (b==-1)
                {
                    throw new EndOfStreamException();
                }
                ret = (ret << 7) | (b&0x7f);
                if ((b & 0x80) == 0)
                {
                    return ret;
                }
            }
            // Still haven't seen a byte with the high bit unset? Dodgy data.
            throw new IOException("Invalid 7-bit encoded integer in stream.");
        }