Skip to content

Commit

Permalink
[fix]修正数据包编码器获取长度时报错,Test项目客户端服务端测试通过
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 13, 2024
1 parent ca2cb69 commit 03314eb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
17 changes: 9 additions & 8 deletions NewLife.MQTT/Messaging/MqttMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ public abstract class MqttMessage : IAccessor
/// <summary>已重载</summary>
public override String ToString()
{
var name = GetType().Name;
return Type switch
{
MqttType.Connect => $"{GetType().Name}[Type={Type}]",
MqttType.ConnAck or MqttType.Disconnect => $"{GetType().Name}[Type={Type}]",
MqttType.Publish => $"{GetType().Name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
MqttType.PubAck or MqttType.PubRec or MqttType.PubRel or MqttType.PubComp => $"{GetType().Name}[Type={Type}]",
MqttType.Subscribe => $"{GetType().Name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
MqttType.SubAck or MqttType.UnSubscribe or MqttType.UnSubAck => $"{GetType().Name}[Type={Type}]",
MqttType.PingReq or MqttType.PingResp => $"{GetType().Name}[Type={Type}]",
_ => $"{GetType().Name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
MqttType.Connect => $"{name}[Type={Type}]",
MqttType.ConnAck or MqttType.Disconnect => $"{name}[Type={Type}]",
MqttType.Publish => $"{name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
MqttType.PubAck or MqttType.PubRec or MqttType.PubRel or MqttType.PubComp => $"{name}[Type={Type}]",
MqttType.Subscribe => $"{name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
MqttType.SubAck or MqttType.UnSubscribe or MqttType.UnSubAck => $"{name}[Type={Type}]",
MqttType.PingReq or MqttType.PingResp => $"{name}[Type={Type}]",
_ => $"{name}[Type={Type}, QoS={(Int32)QoS}, Duplicate={Duplicate}, Retain={Retain}]",
};
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion NewLife.MQTT/MqttCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override IList<MqttMessage> Decode(IHandlerContext context, IPacket pk
if (context.Owner is not IExtend ss) return [];

if (ss["Codec"] is not PacketCodec pc)
ss["Codec"] = pc = new PacketCodec { GetLength = p => GetLength(p, 1, 0), Offset = 1 };
ss["Codec"] = pc = new PacketCodec { GetLength = p => GetLength(p, 1, 0), GetLength2 = p => GetLength(p, 1, 0) };

var pks = pc.Parse(pk);
//var list = pks.Select(_Factory.ReadMessage).ToList();
Expand Down
4 changes: 2 additions & 2 deletions NewLife.MQTT/NewLife.MQTT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1001" />
<PackageReference Include="NewLife.Remoting" Version="3.1.2024.1002" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1013-beta0746" />
<PackageReference Include="NewLife.Remoting" Version="3.1.2024.1011-beta1545" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions NewLife.MqttServer/NewLife.MqttServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1001" />
<PackageReference Include="NewLife.Stardust" Version="3.1.2024.1004" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1013-beta0746" />
<PackageReference Include="NewLife.Stardust" Version="3.1.2024.1012-beta1536" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1001" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1013-beta0746" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NewLife.MQTT\NewLife.MQTT.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion XUnitTestClient/MqttClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace XUnitTestClient;
[TestCaseOrderer("NewLife.UnitTest.DefaultOrderer", "NewLife.UnitTest")]
public class MqttClientTests
{
private MqttServer _server;
private static MqttServer _server;
private static MqttClient _client;
private static readonly Queue<String> _mq = new Queue<String>();

Expand Down
2 changes: 1 addition & 1 deletion XUnitTestClient/PropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: TestCaseOrderer("Xunit.Extensions.Ordering.TestCaseOrderer", "Xunit.Extensions.Ordering")]
//[assembly: TestCaseOrderer("Xunit.Extensions.Ordering.TestCaseOrderer", "Xunit.Extensions.Ordering")]
2 changes: 1 addition & 1 deletion XUnitTestClient/XUnitTestClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1001" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1013-beta0746" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2024.1006" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down

0 comments on commit 03314eb

Please sign in to comment.