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

Crash when QosValue == 2 #54

Open
kenji21 opened this issue Apr 30, 2020 · 0 comments
Open

Crash when QosValue == 2 #54

kenji21 opened this issue Apr 30, 2020 · 0 comments

Comments

@kenji21
Copy link

kenji21 commented Apr 30, 2020

When creating:

        let qos = MQTTQoS(rawValue: header.flags & 0x06)!

this force unwrap crashes if QoS on a publish message is 2, to fix this crash:

public enum MQTTQoS: UInt8 {
    case atMostOnce     = 0x0
-    case atLeastOnce    = 0x01
+    case atLeastOnce    = 0x02
-    case exactlyOnce    = 0x02
+    case exactlyOnce    = 0x04
}

Why this crash ? as MQTTQoS is declared as a UInt8, and http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718038 state that QoS bits are:

 3.3.1.2 QoS

Position: byte 1, bits 2-1.

so having 0b0101 00100 on the header flags byte, then ANDing with 0x06 gives 0b0000 0100 (=> 4 decimal)

QoS value 1 (0b0101 00010 & 0x06 => 2 decimal) was working, but using exactlyOnce value.

Should I send a PR for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant