Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pub: correlation data #168

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,34 @@ impl<'a, P: ToPayload> Publication<'a, P> {
/// [Property::ResponseTopic].
///
/// * If correlation data is found, it is automatically appended to the
/// publication properties.
/// publication properties.
///
/// * If a response topic is identified, the message topic will be
/// configured for it, which will override any previously-specified topic.
/// configured for it, which will override any previously-specified topic.
pub fn respond(
received_properties: &'a Properties<'a>,
payload: P,
) -> Result<Self, ProtocolError> {
let Some(response_topic) = received_properties.into_iter().find_map(|p| {
if let Ok(Property::ResponseTopic(topic)) = p {
Some(topic.0)
} else {
None
}
}) else {
return Err(ProtocolError::NoTopic);
};
let response_topic = received_properties
.into_iter()
.flatten()
.find_map(|p| {
if let Property::ResponseTopic(topic) = p {
Some(topic.0)
} else {
None
}
})
.ok_or(ProtocolError::NoTopic)?;

Ok(Self::new(response_topic, payload))
let publication = Self::new(response_topic, payload);

for p in received_properties.into_iter().flatten() {
if let Property::CorrelationData(data) = p {
return Ok(publication.correlate(data.0));
}
}
Ok(publication)
}

/// Construct a new publication with a payload.
Expand Down
Loading