def decode(ibytes):
    """Decode ibytes from run-length-encoding."""

    obytes = bytearray()

    while ibytes:
        byte = ibytes.pop(0)
        count = (byte & 0x7F) + 1

        if byte & 0x80:
            byte = ibytes.pop(0)
            obytes.extend([byte] * count)
        else:
            obytes.extend(ibytes[:count])
            del ibytes[:count]

    return obytes