True when flags comply with [MQTT-2.2.2-1] requirements based on
    packet_type; False otherwise.

    Parameters
    ----------
    packet_type: MqttControlPacketType
    flags: int
        Integer representation of 4-bit MQTT header flags field.
        Values outside of the range [0, 15] will certainly cause the
        function to return False.

    Returns
    -------
    bool

def are_flags_valid(packet_type, flags):
    """True when flags comply with [MQTT-2.2.2-1] requirements based on
    packet_type; False otherwise.

    Parameters
    ----------
    packet_type: MqttControlPacketType
    flags: int
        Integer representation of 4-bit MQTT header flags field.
        Values outside of the range [0, 15] will certainly cause the
        function to return False.

    Returns
    -------
    bool
    """
    if packet_type == MqttControlPacketType.publish:
        rv = 0 <= flags <= 15
    elif packet_type in (MqttControlPacketType.pubrel,
                         MqttControlPacketType.subscribe,
                         MqttControlPacketType.unsubscribe):
        rv = flags == 2
    elif packet_type in (MqttControlPacketType.connect,
                         MqttControlPacketType.connack,
                         MqttControlPacketType.puback,
                         MqttControlPacketType.pubrec,
                         MqttControlPacketType.pubcomp,
                         MqttControlPacketType.suback,
                         MqttControlPacketType.unsuback,
                         MqttControlPacketType.pingreq,
                         MqttControlPacketType.pingresp,
                         MqttControlPacketType.disconnect):
        rv = flags == 0
    else:
        raise NotImplementedError(packet_type)

    return rv