def _read_varint_helper(self):
        """Helper for the various varint-reading methods above.
        Reads an unsigned, varint-encoded integer from the stream and
        returns this integer.

        Does no bounds checking except to ensure that we read at most as many bytes
        as could possibly be present in a varint-encoded 64-bit number.
        """
        result = 0
        shift = 0
        while 1:
            if shift >= 64:
                raise errors.DecodeError('Too many bytes when decoding varint.')
            try:
                b = ord(self._input.read(1))
            except IndexError:
                raise errors.DecodeError('Truncated varint.')
            self._pos += 1
            result |= ((b & 0x7f) << shift)
            shift += 7
            if not (b & 0x80):
                return result