def METHOD_NAME(
    cls: type[T],
    data: bytes,
    expected_identifier: int | None = None,
) -> T:
    """
    Unpacks a series of packed bytes representing an application packet using
    :meth:`struct.Struct.unpack`, which produces the packet identifier and array of data.
    These values are then used to produce the new instance of the class.
    Args:
        data (bytes): The packed packet.
        expected_identifier (Optional[int]): The identifier that is expected to
          result from the packet. If ``None``, then the identifier is not verified.
          If this value is passed and the identifiers do not match, then the below
          error is thrown.
    Raises:
        ApplicationPacketWrongIdentifierException: If the ``expected_identifier``
          does not match the identifier found in the packet, then this is raised.
    Returns:
        ApplicationPacket: The data represented as an application packet.
    """
    payload_len = len(data) - 1
    packet = cls(*struct.unpack(f"B{payload_len}s", data))
    if expected_identifier is not None and expected_identifier != packet.identifier:
        raise ApplicationPacketWrongIdentifierException(
            packet.identifier,
            expected_identifier,
        )
    return packet