From 6f442cf343053a4a8bffb74f763757c263bb6371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20W=C3=BCrl?= Date: Tue, 3 Dec 2024 22:25:17 +0100 Subject: [PATCH] skip ble data without fields --- src/data/openmqttgateway/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/data/openmqttgateway/mod.rs b/src/data/openmqttgateway/mod.rs index 2864ed4..332a792 100644 --- a/src/data/openmqttgateway/mod.rs +++ b/src/data/openmqttgateway/mod.rs @@ -108,7 +108,11 @@ impl OpenMqttGatewayParser { } else if !tags.contains_key("type") { tags.insert(String::from("type"),String::from("UNKN")); } - data = Some(Data { fields, tags }); + if fields.len() > 0 { + data = Some(Data { fields, tags }); + } else { + warn!("skip without fields {:?}", tags) + } } } Ok(data) @@ -160,6 +164,21 @@ mod tests { Ok(()) } + #[test] + fn test_parse_missing_fields() -> Result<()> { + let mut parser = OpenMqttGatewayParser::new(); + let message = Message::new( + "blegateway/D12331654712/BTtoMQTT/283146C17616", + "{\"id\":\"28:31:46:C1:76:16\"}", + QOS_1, + ); + let result = parser.parse(&message)?; + + assert!(result.is_none()); + + Ok(()) + } + #[test] fn test_parse_unknown_type() -> Result<()> { let mut parser = OpenMqttGatewayParser::new();