@staticmethod
def _unpack_varint(bytes):
    """ Convert a varint to an integer.
        :param bytes: Bytes containing the varint.
        :return: integer
        """
    value = 0
    base = 1
    rd = 0
    for raw_byte in bytes:
        val_byte = ord(raw_byte) if type(raw_byte) != int else raw_byte
        rd += 1
        value += (val_byte & 127) * base
        if val_byte & 128:
            base *= 128
        else:
            break
    return value, rd
