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

Implement fallback for getting UAttributes from payload if MQTT5 is not supported #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 22 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,25 +361,31 @@ impl UPClientMqtt {
.get_int(mqtt::PropertyCode::SubscriptionIdentifier);

// Get attributes from mqtt header.
let uattributes = {
match UPClientMqtt::get_uattributes_from_mqtt_properties(msg.properties()) {
Ok(uattributes) => uattributes,
Err(e) => {
warn!("Unable to get UAttributes from mqtt properties: {}", e);
continue;
let umessage = if UPClientMqtt::get_uattributes_from_mqtt_properties(msg.properties()).is_err() {
debug!("empty properties");
protobuf::Message::parse_from_bytes(msg.payload()).unwrap()
} else {
let uattributes = {
match UPClientMqtt::get_uattributes_from_mqtt_properties(msg.properties()) {
Ok(uattributes) => uattributes,
Err(e) => {
warn!("Unable to get UAttributes from mqtt properties: {}", e);
continue;
}
}
};

let payload = msg.payload();
let upayload = payload.to_vec();

// Create UMessage from UAttributes and UPayload.
UMessage {
attributes: Some(uattributes).into(),
payload: Some(upayload.into()),
..Default::default()
}
};

let payload = msg.payload();
let upayload = payload.to_vec();

// Create UMessage from UAttributes and UPayload.
let umessage = UMessage {
attributes: Some(uattributes).into(),
payload: Some(upayload.into()),
..Default::default()
};


let topic_map_read = topic_map.read().await;
let subscription_map_read = subscription_map.read().await;
Expand Down
Loading