import struct


def _decode_u32(reader):
    """
    Reads and decodes unsigned 32-bit integer.

    Parameters
    ----------
    reader : apptrace.Reader
        Trace reader object.

    Returns
    -------
    tuple
        a tuple containg number of read bytes and decoded value.
    """
    sz = 0
    val = 0
    while True:
        b, = struct.unpack('<B', reader.read(1))
        if b & 0x80:
            val |= (b & 0x7F) << (7 * sz)
        else:
            val |= b << (7 * sz)
            break
        sz += 1
    return (sz + 1,val)