// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Common utilities for use with the protocol.

/// Implementation of hybrid logical clock.
pub mod hybrid_logical_clock;

/// This module contains a trait that payload structs should implement to be serializable.
pub mod payload_serialize;

/// This module contains the error type for the Azure IoT Operations Protocol.
pub mod aio_protocol_error;

/// This module contains the topic processor functions for the Azure IoT Operations Protocol
pub(crate) mod topic_processor;

/// This module contains string values for Azure IoT Operations Protocol defined user properties.
pub(crate) mod user_properties;

/// This module contains a convenience for dispatching to a receiver based on an ID.
/// This module is in development and subject to change.
#[cfg(feature = "internal-utils")]
pub mod dispatcher;
#[cfg(not(feature = "internal-utils"))]
pub(crate) mod dispatcher;

/// This module contains the sending side cloud event implementation for the Azure IoT Operations Protocol.
pub(crate) mod cloud_event;
pub use cloud_event::CloudEventSubject;

/// Used to validate that a string is well-formed UTF-8 per the [MQTT 5 spec](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_UTF-8_Encoded_String)
#[must_use]
pub(crate) fn is_invalid_utf8(s: &str) -> bool {
    s.chars()
        .any(|c| ('\u{0000}'..='\u{001F}').contains(&c) || ('\u{007F}'..='\u{009F}').contains(&c))
}
