aboutsummaryrefslogtreecommitdiff
path: root/src/mqtt
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-12-09 22:43:40 +0000
committerdiogo464 <[email protected]>2025-12-09 22:50:34 +0000
commit9aed552c491aaabc84e3141bc70e4d26c03efa85 (patch)
treefbf614c2c67e631d97b28b97d8d6d8168355b85d /src/mqtt
parenta5845673cf052b606f722be10d48c5d963958050 (diff)
fixed warnings/lints
Diffstat (limited to 'src/mqtt')
-rw-r--r--src/mqtt/mod.rs50
-rw-r--r--src/mqtt/qos.rs3
-rw-r--r--src/mqtt/varint.rs4
3 files changed, 27 insertions, 30 deletions
diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs
index 30e3a33..04e63b6 100644
--- a/src/mqtt/mod.rs
+++ b/src/mqtt/mod.rs
@@ -1,3 +1,5 @@
1#![allow(unused)]
2
1mod connect_code; 3mod connect_code;
2mod field; 4mod field;
3mod packet_id; 5mod packet_id;
@@ -23,7 +25,7 @@ pub enum Error<T: Transport> {
23 Transport(T::Error), 25 Transport(T::Error),
24 TransportEOF, 26 TransportEOF,
25 InsufficientBufferSpace, 27 InsufficientBufferSpace,
26 ProtocolError(&'static str), 28 Protocol(&'static str),
27 ConnectFailed(ConnectCode), 29 ConnectFailed(ConnectCode),
28} 30}
29 31
@@ -33,7 +35,7 @@ impl<T: Transport> core::fmt::Debug for Error<T> {
33 Error::Transport(err) => f.debug_tuple("Transport").field(err).finish(), 35 Error::Transport(err) => f.debug_tuple("Transport").field(err).finish(),
34 Error::TransportEOF => f.write_str("TransportEOF"), 36 Error::TransportEOF => f.write_str("TransportEOF"),
35 Error::InsufficientBufferSpace => f.write_str("InsufficientBufferSpace"), 37 Error::InsufficientBufferSpace => f.write_str("InsufficientBufferSpace"),
36 Error::ProtocolError(msg) => f.debug_tuple("ProtocolError").field(msg).finish(), 38 Error::Protocol(msg) => f.debug_tuple("ProtocolError").field(msg).finish(),
37 Error::ConnectFailed(code) => f.debug_tuple("ConnectFailed").field(code).finish(), 39 Error::ConnectFailed(code) => f.debug_tuple("ConnectFailed").field(code).finish(),
38 } 40 }
39 } 41 }
@@ -47,7 +49,7 @@ impl<T: Transport> core::fmt::Display for Error<T> {
47 Error::InsufficientBufferSpace => { 49 Error::InsufficientBufferSpace => {
48 write!(f, "insufficient buffer space to receive packet") 50 write!(f, "insufficient buffer space to receive packet")
49 } 51 }
50 Error::ProtocolError(msg) => write!(f, "MQTT protocol error: {}", msg), 52 Error::Protocol(msg) => write!(f, "MQTT protocol error: {}", msg),
51 Error::ConnectFailed(code) => write!(f, "connection failed: {}", code), 53 Error::ConnectFailed(code) => write!(f, "connection failed: {}", code),
52 } 54 }
53 } 55 }
@@ -209,7 +211,7 @@ where
209 // Wait for CONNACK response 211 // Wait for CONNACK response
210 match self.receive_inner().await? { 212 match self.receive_inner().await? {
211 rx::Packet::ConnAck { 213 rx::Packet::ConnAck {
212 session_present, 214 session_present: _,
213 code, 215 code,
214 } => { 216 } => {
215 if code == ConnectCode::ConnectionAccepted { 217 if code == ConnectCode::ConnectionAccepted {
@@ -218,7 +220,7 @@ where
218 Err(Error::ConnectFailed(code)) 220 Err(Error::ConnectFailed(code))
219 } 221 }
220 } 222 }
221 _ => Err(Error::ProtocolError( 223 _ => Err(Error::Protocol(
222 "expected CONNACK packet after CONNECT", 224 "expected CONNACK packet after CONNECT",
223 )), 225 )),
224 } 226 }
@@ -351,12 +353,12 @@ where
351 return Err(Error::InsufficientBufferSpace); 353 return Err(Error::InsufficientBufferSpace);
352 } 354 }
353 } 355 }
354 rx::Error::InvalidPacket(msg) => return Err(Error::ProtocolError(msg)), 356 rx::Error::InvalidPacket(msg) => return Err(Error::Protocol(msg)),
355 rx::Error::UnsupportedPacket { packet_type, .. } => { 357 rx::Error::UnsupportedPacket { packet_type: _, .. } => {
356 return Err(Error::ProtocolError("unsupported packet type")); 358 return Err(Error::Protocol("unsupported packet type"));
357 } 359 }
358 rx::Error::UnknownPacket { packet_type, .. } => { 360 rx::Error::UnknownPacket { packet_type: _, .. } => {
359 return Err(Error::ProtocolError("unknown packet type")); 361 return Err(Error::Protocol("unknown packet type"));
360 } 362 }
361 }, 363 },
362 } 364 }
@@ -367,9 +369,7 @@ where
367 369
368 pub async fn receive<'s>(&'s mut self) -> Result<Packet<'s>, Error<T>> { 370 pub async fn receive<'s>(&'s mut self) -> Result<Packet<'s>, Error<T>> {
369 match self.receive_inner().await? { 371 match self.receive_inner().await? {
370 rx::Packet::ConnAck { .. } => { 372 rx::Packet::ConnAck { .. } => Err(Error::Protocol("unexpected CONNACK packet")),
371 return Err(Error::ProtocolError("unexpected CONNACK packet"));
372 }
373 rx::Packet::Publish { 373 rx::Packet::Publish {
374 topic, 374 topic,
375 packet_id, 375 packet_id,
@@ -377,23 +377,19 @@ where
377 retain, 377 retain,
378 dup: _dup, 378 dup: _dup,
379 data_len, 379 data_len,
380 } => { 380 } => Ok(Packet::Publish(Publish {
381 return Ok(Packet::Publish(Publish { 381 topic,
382 topic, 382 packet_id,
383 packet_id, 383 qos,
384 qos, 384 retain,
385 retain, 385 data_len,
386 data_len, 386 })),
387 })); 387 rx::Packet::PubAck { packet_id } => Ok(Packet::PublishAck(PublishAck { packet_id })),
388 }
389 rx::Packet::PubAck { packet_id } => {
390 return Ok(Packet::PublishAck(PublishAck { packet_id }));
391 }
392 rx::Packet::SubscribeAck { packet_id, success } => { 388 rx::Packet::SubscribeAck { packet_id, success } => {
393 return Ok(Packet::SubscribeAck(SubscribeAck { packet_id, success })); 389 Ok(Packet::SubscribeAck(SubscribeAck { packet_id, success }))
394 } 390 }
395 rx::Packet::UnsubscribeAck { packet_id } => { 391 rx::Packet::UnsubscribeAck { packet_id } => {
396 return Ok(Packet::UnsubscribeAck(UnsubscribeAck { packet_id })); 392 Ok(Packet::UnsubscribeAck(UnsubscribeAck { packet_id }))
397 } 393 }
398 } 394 }
399 } 395 }
diff --git a/src/mqtt/qos.rs b/src/mqtt/qos.rs
index 0d464b4..34fa7c1 100644
--- a/src/mqtt/qos.rs
+++ b/src/mqtt/qos.rs
@@ -9,6 +9,7 @@ impl core::fmt::Display for InvalidQos {
9 9
10impl core::error::Error for InvalidQos {} 10impl core::error::Error for InvalidQos {}
11 11
12#[allow(clippy::enum_variant_names)]
12#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] 13#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum Qos { 14pub enum Qos {
14 #[default] 15 #[default]
@@ -28,7 +29,7 @@ impl core::fmt::Display for Qos {
28} 29}
29 30
30impl Qos { 31impl Qos {
31 pub fn to_u8(&self) -> u8 { 32 pub fn to_u8(self) -> u8 {
32 match self { 33 match self {
33 Qos::AtMostOnce => 0, 34 Qos::AtMostOnce => 0,
34 Qos::AtLeastOnce => 1, 35 Qos::AtLeastOnce => 1,
diff --git a/src/mqtt/varint.rs b/src/mqtt/varint.rs
index 63bdd06..d5416ca 100644
--- a/src/mqtt/varint.rs
+++ b/src/mqtt/varint.rs
@@ -41,8 +41,8 @@ pub fn encode(mut v: u32) -> ([u8; 4], usize) {
41pub fn decode(buf: &[u8]) -> Result<(u32, usize), Error> { 41pub fn decode(buf: &[u8]) -> Result<(u32, usize), Error> {
42 let mut value = 0u32; 42 let mut value = 0u32;
43 43
44 let v = buf.get(0).ok_or(Error::NeedMoreData)?; 44 let v = buf.first().ok_or(Error::NeedMoreData)?;
45 value |= ((v & 0x7F) as u32) << 0; 45 value |= (v & 0x7F) as u32;
46 if v & 0x80 == 0 { 46 if v & 0x80 == 0 {
47 return Ok((value, 1)); 47 return Ok((value, 1));
48 } 48 }