ndi_sdk_sys/
util.rs

1use std::{ffi::CString, time::Duration};
2
3pub(crate) fn duration_to_ms(dur: Duration) -> u32 {
4    dur.as_millis().try_into().unwrap_or(u32::MAX)
5}
6
7/// The total length of an NDI source name should be limited to 253 characters. The following characters
8/// are considered invalid: `\ / : * ? " < > |`. If any of these characters are found in the name, they will
9/// be replaced with a space. These characters are reserved according to Windows file system naming conventions
10pub fn validate_source_name(name: &str) -> Result<CString, SourceNameError> {
11    let name = CString::new(name).map_err(SourceNameError::NulError)?;
12    if name.count_bytes() >= 253 {
13        Err(SourceNameError::TooLong)
14    } else {
15        Ok(name)
16    }
17}
18
19/// see [validate_source_name] for more information
20#[non_exhaustive]
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum SourceNameError {
23    /// The input name contained Nul characters
24    NulError(std::ffi::NulError),
25    /// The total length of an NDI source name should be limited to 253 characters
26    TooLong,
27}