in rust/azure_iot_operations_protocol/src/telemetry/sender.rs [252:284]
fn validate(&self) -> Result<(), String> {
if let Some(custom_user_data) = &self.custom_user_data {
for (key, _) in custom_user_data {
if CloudEventFields::from_str(key).is_ok() {
return Err(format!(
"Invalid user data property '{key}' is a reserved Cloud Event key"
));
}
}
validate_user_properties(custom_user_data)?;
}
if let Some(timeout) = &self.message_expiry {
match <u64 as TryInto<u32>>::try_into(timeout.as_secs()) {
Ok(_) => {}
Err(_) => {
return Err("Timeout in seconds must be less than or equal to u32::max to be used as message_expiry_interval".to_string());
}
}
}
if let Some(qos) = &self.qos {
if *qos != QoS::AtMostOnce && *qos != QoS::AtLeastOnce {
return Err("QoS must be AtMostOnce or AtLeastOnce".to_string());
}
}
// If there's a cloud event, make sure the content type is valid for the cloud event spec version
if let Some(Some(cloud_event)) = &self.cloud_event {
if let Some(serialized_payload) = &self.serialized_payload {
CloudEventFields::DataContentType
.validate(&serialized_payload.content_type, &cloud_event.spec_version)?;
}
}
Ok(())
}