Skip to content

Commit

Permalink
Make from_msh_status a pure Rust function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed May 23, 2024
1 parent 8f26bb3 commit 6146f91
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use meshtastic::protobufs::{telemetry, Data, ServiceEnvelope, Telemetry};
use meshtastic::protobufs::{MeshPacket, PortNum, Position as PositionProto};
use meshtastic::Message as MeshtaticMessage;
use prost_wkt_types::Timestamp;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -328,9 +327,8 @@ impl MshLogMessage {
now: DateTime<FixedOffset>,
dns: &HashMap<String, String>,
recv_position: Option<PositionName>,
) -> PyResult<Option<Self>> {
let service_envelope = ServiceEnvelope::decode(payload)
.map_err(|e| PyValueError::new_err(format!("Cannot decode proto: {e}")))?;
) -> Result<Option<Self>, std::io::Error> {
let service_envelope = ServiceEnvelope::decode(payload)?;
match service_envelope.packet {
Some(MeshPacket {
payload_variant: Some(PayloadVariant::Decoded(data)),
Expand All @@ -354,14 +352,13 @@ impl MshLogMessage {
RssiSnr::new(rx_rssi, rx_snr),
recv_position,
)
.map_err(|_| PyValueError::new_err("Cannot parse inner proto"))
}
Some(MeshPacket {
payload_variant: Some(PayloadVariant::Encrypted(_)),
..
}) => Err(PyValueError::new_err(
"Encrypted message, disable encryption in MQTT!",
)),
}) => Err(
prost::DecodeError::new("Encrypted message, disable encryption in MQTT!").into(),
),
_ => Ok(None),
}
}
Expand Down

0 comments on commit 6146f91

Please sign in to comment.