diff --git a/README.md b/README.md index 262b28a..1f8c83f 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,13 @@ JT808Serializer DT2JT808Serializer = new JT808Serializer(DT2JT808Config); [可以参考Simples的Demo14](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo14.cs) +### 举个栗子15 + +场景: +由于某些厂商不按要求去做,明明使用的2013的协议但是在消息头部的版本标识位置为1,导致程序认为是2019协议。从而解析报错。此时可以强制解析成2013后,然后修正版本标识,重新序列化消息,以供下游服务使用 + +[可以参考Simples的Demo15](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo15.cs) + ## NuGet安装 | Package Name| Version| Preview Version |Downloads|Remark| diff --git a/src/JT808.Protocol.Test/Simples/Demo15.cs b/src/JT808.Protocol.Test/Simples/Demo15.cs new file mode 100644 index 0000000..f48ea51 --- /dev/null +++ b/src/JT808.Protocol.Test/Simples/Demo15.cs @@ -0,0 +1,48 @@ +using JT808.Protocol.Enums; +using JT808.Protocol.Interfaces; +using JT808.Protocol.Internal; +using JT808.Protocol.Extensions; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT808.Protocol.MessageBody; +using JT808.Protocol.Formatters; +using JT808.Protocol.MessagePack; +using System.Text.Json; +using JT808.Protocol.MessageBody.CarDVR; +using System.Linq; +using JT808.Protocol.Test.JT808LocationAttach; +using static JT808.Protocol.MessageBody.JT808_0x8105; +using System.Buffers.Binary; +using Newtonsoft.Json; + +namespace JT808.Protocol.Test.Simples +{ + public class Demo15 + { + JT808Serializer JT808Serializer; + + public Demo15() + { + IServiceCollection serviceDescriptors = new ServiceCollection(); + serviceDescriptors.AddJT808Configure(); + //通常在startup中使用app的Use进行扩展 + IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); + JT808Serializer = serviceProvider.GetRequiredService().GetSerializer(); + } + + [Fact] + public void Test1() + { + var bytes = "7e0102400c01003000068109024a3130303330303030363831857e".ToHexBytes(); + JT808Package jT808Package = JT808Serializer.Deserialize(bytes, JT808Version.JTT2013Force);//强制使用2013协议转换 + //因头部的版本标识号是2019,实际上是使用2013的协议 + jT808Package.Header.MessageBodyProperty.VersionFlag = false; + //修改版本号之后,重新编码协议,以便后续服务正常使用 + var newBytes=JT808Serializer.Serialize(jT808Package); + JT808Package jT808PackageNew = JT808Serializer.Deserialize(newBytes); + } + } +}