def _dechunk(raw):
    """
    Given a BLE advertisement in hex format, interpret the first
    byte as a length byte, return the data indicated by the length
    byte, and the remainder of the data in a tuple.

    The lenght byte itself is not included in the length.

    If the length indicated is longer than the data, raise a ValueError
    """
    if len(raw) < 2:
        raise ValueError("Data too short")

    dlen = int(raw[:2], 16)
    if (dlen + 1) * 2 > len(raw):
        raise ValueError("Cannot read %d bytes, data too short: %s" % (dlen, raw))

    return raw[2:(dlen * 2) + 2], raw[(dlen * 2) + 2:]