Skip to content

Commit

Permalink
添加是否合并分包成功的属性
Browse files Browse the repository at this point in the history
  • Loading branch information
yedajiang44 committed Jul 24, 2024
1 parent 0730cc5 commit cfa2cf2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x9208 v
writer.WriteByte(value.AlarmIdentification.AttachCount);
writer.WriteByte(value.AlarmIdentification.Retain);
writer.WriteString(value.AlarmId.PadRight(32, '\0'));
writer.WriteArray(Retain);
writer.WriteArray(value.Retain);
}
}
}
4 changes: 3 additions & 1 deletion src/JT808.Protocol.Test/JT808SerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void MergerTest()
{
var config = new DefaultGlobalConfig("merge");
config.EnableAutoMerge = true;
config.AutoMergeTimeoutSecond = 5;
config.AutoMergeTimeoutSecond = 500;
var array = new[]
{
//分包数据第一包
Expand All @@ -67,6 +67,7 @@ public void MergerTest()
var package = config.GetSerializer().Deserialize(array[i - 1].ToHexBytes());
if (i == array.Length)
{
Assert.True(package.Header.MessageBodyProperty.IsMerged);
Assert.NotNull(package.Bodies);
//分包合并成功并获取消息体进行处理
if (package.Bodies is JT808_0x0104 _0x0104 && _0x0104.AnswerParamsCount > 0)
Expand All @@ -86,6 +87,7 @@ public void MergerTest()
var package = config.GetSerializer().Deserialize(array[i].ToHexBytes());
if (i == 0)
{
Assert.True(package.Header.MessageBodyProperty.IsMerged);
Assert.NotNull(package.Bodies);
//分包合并成功并获取消息体进行处理
if (package.Bodies is JT808_0x0104 _0x0104 && _0x0104.AnswerParamsCount > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/JT808.Protocol/Internal/DefaultMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public DefaultMerger()
/// <inheritdoc/>
public bool TryMerge(JT808Header header, byte[] data, IJT808Config config, out JT808Bodies body)
{
// TODO: 添加SplitPackages缓存超时,达到阈值时移除该项缓存
body = null;
var timeoutKey = GenerateKey(header.TerminalPhoneNo, header.MsgId);
if (!CheckTimeout(timeoutKey)) return false;
Expand All @@ -65,6 +64,7 @@ public bool TryMerge(JT808Header header, byte[] data, IJT808Config config, out J
if (config.MsgIdFactory.TryGetValue(header.MsgId, out var value) && value is JT808Bodies instance)
{
body = instance.DeserializeExt<JT808Bodies>(ref reader, config);
header.MessageBodyProperty.IsMerged = true;
return true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/JT808.Protocol/JT808.Protocol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6089,6 +6089,11 @@
false-0 消息头中无消息包封装项字段。
</summary>
</member>
<member name="P:JT808.Protocol.JT808HeaderMessageBodyProperty.IsMerged">
<summary>
当<see cref="P:JT808.Protocol.JT808HeaderMessageBodyProperty.IsPackage"/>为true时,表示是否已自动合并为完整的包
</summary>
</member>
<member name="P:JT808.Protocol.JT808HeaderMessageBodyProperty.Encrypt">
<summary>
加密标识,0为不加密
Expand Down
4 changes: 4 additions & 0 deletions src/JT808.Protocol/JT808HeaderMessageBodyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public JT808HeaderMessageBodyProperty(ushort value)
/// </summary>
public bool IsPackage { get; set; } = false;
/// <summary>
/// 当<see cref="IsPackage"/>为true时,表示是否已自动合并为完整的包
/// </summary>
public bool IsMerged { get; set; }
/// <summary>
/// 加密标识,0为不加密
/// 当此三位都为 0,表示消息体不加密;
/// 当第 10 位为 1,表示消息体经过 RSA 算法加密;
Expand Down

0 comments on commit cfa2cf2

Please sign in to comment.