Skip to content

Commit

Permalink
removed guess encoding (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin authored Oct 11, 2024
1 parent 3cbaa37 commit 77371cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 87 deletions.
94 changes: 28 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions zenoh-plugin-mqtt/src/mqtt_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::convert::TryInto;
use ntex::util::{ByteString, Bytes};
use ntex_mqtt::{error::SendPacketError, v3, v5};
use zenoh::{
bytes::Encoding,
internal::bail,
key_expr::{KeyExpr, OwnedKeyExpr},
Result as ZResult,
Expand Down Expand Up @@ -104,22 +103,6 @@ pub(crate) fn is_allowed(mqtt_topic: &str, config: &Config) -> bool {
}
}

pub(crate) fn guess_encoding(payload: &[u8]) -> Encoding {
if serde_json::from_slice::<serde_json::Value>(payload).is_ok() {
Encoding::APPLICATION_JSON
} else if let Ok(s) = std::str::from_utf8(payload) {
if s.parse::<i64>().is_ok() {
Encoding::ZENOH_INT64
} else if s.parse::<f64>().is_ok() {
Encoding::ZENOH_FLOAT64
} else {
Encoding::TEXT_PLAIN
}
} else {
Encoding::default()
}
}

#[derive(Clone, Debug)]
pub(crate) enum MqttSink {
V3(v3::MqttSink),
Expand Down
5 changes: 1 addition & 4 deletions zenoh-plugin-mqtt/src/mqtt_session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,15 @@ impl MqttSessionState {
} else {
topic.try_into()?
};
let encoding = guess_encoding(payload.deref());
// TODO: check allow/deny
tracing::trace!(
"MQTT client {}: route from MQTT '{}' to Zenoh '{}' (encoding={})",
"MQTT client {}: route from MQTT '{}' to Zenoh '{}'",
self.client_id,
topic,
ke,
encoding
);
self.zsession
.put(ke, payload.deref())
.encoding(encoding)
.allowed_destination(destination)
.await
}
Expand Down

0 comments on commit 77371cd

Please sign in to comment.