Skip to content
Snippets Groups Projects
Commit 09b77d31 authored by Davide Pianca's avatar Davide Pianca
Browse files

Fix WillQos field in ConnectFlags deserialization

parent 1e9775cc
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ public data class ConnectFlags( ...@@ -29,7 +29,7 @@ public data class ConnectFlags(
if (reserved) if (reserved)
throw MQTTException(ReasonCode.MALFORMED_PACKET) throw MQTTException(ReasonCode.MALFORMED_PACKET)
val willFlag = ((byte shr 2) and 1) == 1 val willFlag = ((byte shr 2) and 1) == 1
val willQos = ((byte shr 4) and 1) or ((byte shl 3) and 1) val willQos = ((byte shr 3) and 3)
val willRetain = ((byte shr 5) and 1) == 1 val willRetain = ((byte shr 5) and 1) == 1
if (willFlag) { if (willFlag) {
if (willQos == 3) if (willQos == 3)
......
...@@ -11,20 +11,64 @@ class MQTTConnectTest { ...@@ -11,20 +11,64 @@ class MQTTConnectTest {
private val array = ubyteArrayOf( private val array = ubyteArrayOf(
0x10u, 0x10u,
0x0Du, 0x39u,
0x00u, 0x00u,
0x04u, 0x04u,
0x4Du, 0x4du,
0x51u, 0x51u,
0x54u, 0x54u,
0x54u, 0x54u,
0x05u, 0x05u,
0x02u, 0x16u,
0x00u,
0x3cu,
0x05u,
0x11u,
0x00u,
0x00u,
0x00u,
0x00u,
0x00u,
0x0eu,
0x6du,
0x71u,
0x74u,
0x74u,
0x78u,
0x5fu,
0x66u,
0x35u,
0x61u,
0x63u,
0x30u,
0x31u,
0x37u,
0x31u,
0x06u,
0x03u,
0x00u, 0x00u,
0x3Cu,
0x00u, 0x00u,
0x08u,
0x00u, 0x00u,
0x00u 0x00u,
0x00u,
0x0au,
0x2fu,
0x74u,
0x65u,
0x73u,
0x74u,
0x2fu,
0x77u,
0x69u,
0x6cu,
0x6cu,
0x00u,
0x04u,
0x61u,
0x62u,
0x63u,
0x64u
) )
private val packet = MQTT5Connect( private val packet = MQTT5Connect(
"MQTT", "MQTT",
...@@ -32,12 +76,17 @@ class MQTTConnectTest { ...@@ -32,12 +76,17 @@ class MQTTConnectTest {
false, false,
false, false,
false, false,
Qos.AT_MOST_ONCE, Qos.EXACTLY_ONCE,
false, true,
true, true,
false false
), ),
60 60,
clientID = "mqttx_f5ac0171",
properties = MQTT5Properties(sessionExpiryInterval = 0u),
willTopic = "/test/will",
willPayload = "abcd".encodeToByteArray().toUByteArray(),
willProperties = MQTT5Properties(contentType = "", responseTopic = "")
) )
@Test @Test
...@@ -51,5 +100,7 @@ class MQTTConnectTest { ...@@ -51,5 +100,7 @@ class MQTTConnectTest {
assertEquals(packet.protocolName, result.protocolName) assertEquals(packet.protocolName, result.protocolName)
assertEquals(packet.protocolVersion, result.protocolVersion) assertEquals(packet.protocolVersion, result.protocolVersion)
assertEquals(packet.keepAlive, result.keepAlive) assertEquals(packet.keepAlive, result.keepAlive)
assertEquals(packet.connectFlags.willFlag, true)
assertEquals(packet.connectFlags.willQos, Qos.EXACTLY_ONCE)
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment