Skip to content

Commit

Permalink
Merge pull request #121 from nayato/packetid
Browse files Browse the repository at this point in the history
Check MQTT packet identifier > 0. Fixes #76
  • Loading branch information
nayato committed Jun 1, 2016
2 parents 65410d2 + ff93b80 commit fd13b62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/DotNetty.Codecs.Mqtt/MqttDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ static void DecodePublishPacket(IByteBuffer buffer, PublishPacket packet, ref in

static void DecodePacketIdVariableHeader(IByteBuffer buffer, PacketWithId packet, ref int remainingLength)
{
packet.PacketId = DecodeUnsignedShort(buffer, ref remainingLength);
int packetId = packet.PacketId = DecodeUnsignedShort(buffer, ref remainingLength);
if (packetId == 0)
{
throw new DecoderException("[MQTT-2.3.1-1]");
}
}

static void DecodeSubscribePayload(IByteBuffer buffer, SubscribePacket packet, ref int remainingLength)
Expand Down
14 changes: 7 additions & 7 deletions test/DotNetty.Codecs.Mqtt.Tests/MqttCodecTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void TestConnAckMessage(bool sessionPresent, ConnectReturnCode returnCode
}

[Theory]
[InlineData(0, new[] { "+", "+/+", "//", "/#", "+//+" }, new[] { QualityOfService.ExactlyOnce, QualityOfService.AtLeastOnce, QualityOfService.AtMostOnce, QualityOfService.ExactlyOnce, QualityOfService.AtMostOnce })]
[InlineData(1, new[] { "+", "+/+", "//", "/#", "+//+" }, new[] { QualityOfService.ExactlyOnce, QualityOfService.AtLeastOnce, QualityOfService.AtMostOnce, QualityOfService.ExactlyOnce, QualityOfService.AtMostOnce })]
[InlineData(ushort.MaxValue, new[] { "a" }, new[] { QualityOfService.AtLeastOnce })]
public void TestSubscribeMessage(int packetId, string[] topicFilters, QualityOfService[] requestedQosValues)
{
Expand All @@ -117,7 +117,7 @@ public void TestSubscribeMessage(int packetId, string[] topicFilters, QualityOfS
}

[Theory]
[InlineData(0, new[] { QualityOfService.ExactlyOnce, QualityOfService.AtLeastOnce, QualityOfService.AtMostOnce, QualityOfService.Failure, QualityOfService.AtMostOnce })]
[InlineData(1, new[] { QualityOfService.ExactlyOnce, QualityOfService.AtLeastOnce, QualityOfService.AtMostOnce, QualityOfService.Failure, QualityOfService.AtMostOnce })]
[InlineData(ushort.MaxValue, new[] { QualityOfService.AtLeastOnce })]
public void TestSubAckMessage(int packetId, QualityOfService[] qosValues)
{
Expand All @@ -133,7 +133,7 @@ public void TestSubAckMessage(int packetId, QualityOfService[] qosValues)
}

[Theory]
[InlineData(0, new[] { "+", "+/+", "//", "/#", "+//+" })]
[InlineData(1, new[] { "+", "+/+", "//", "/#", "+//+" })]
[InlineData(ushort.MaxValue, new[] { "a" })]
public void TestUnsubscribeMessage(int packetId, string[] topicFilters)
{
Expand All @@ -147,10 +147,10 @@ public void TestUnsubscribeMessage(int packetId, string[] topicFilters)
}

[Theory]
[InlineData(QualityOfService.AtMostOnce, false, false, 0, "a", null)]
[InlineData(QualityOfService.AtMostOnce, false, false, 1, "a", null)]
[InlineData(QualityOfService.ExactlyOnce, true, false, ushort.MaxValue, "/", new byte[0])]
[InlineData(QualityOfService.AtLeastOnce, false, true, 0, "a/b", new byte[] { 1, 2, 3 })]
[InlineData(QualityOfService.ExactlyOnce, true, true, 1, "topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/", new byte[] { 1 })]
[InlineData(QualityOfService.AtLeastOnce, false, true, 129, "a/b", new byte[] { 1, 2, 3 })]
[InlineData(QualityOfService.ExactlyOnce, true, true, ushort.MaxValue - 1, "topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/topic/name/that/is/longer/than/256/characters/", new byte[] { 1 })]
public void TestPublishMessage(QualityOfService qos, bool dup, bool retain, int packetId, string topicName, byte[] payload)
{
var packet = new PublishPacket(qos, dup, retain);
Expand All @@ -173,8 +173,8 @@ public void TestPublishMessage(QualityOfService qos, bool dup, bool retain, int
}

[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(127)]
[InlineData(128)]
[InlineData(256)]
[InlineData(257)]
Expand Down

0 comments on commit fd13b62

Please sign in to comment.