diff --git a/README.md b/README.md
index cb88beb..4ca391c 100644
--- a/README.md
+++ b/README.md
@@ -261,7 +261,6 @@ JT808Serializer JT808Serializer = new JT808Serializer(jT808Coonfig);
| Package Name | Version | Downloads |
| --------------------- | -------------------------------------------------- | --------------------------------------------------- |
| Install-Package JT808 |  |  |
-| Install-Package JT808.Extensions.DependencyInjection |  |  |
## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真)
diff --git a/src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj b/src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj
index 7ab4c33..5fa242c 100644
--- a/src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj
+++ b/src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj
@@ -15,7 +15,7 @@
-
+
diff --git a/src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs b/src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs
index 4c754cd..f634060 100644
--- a/src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs
+++ b/src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs
@@ -3,7 +3,6 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
-using JT808.Protocol.MessageBody;
using System.Linq;
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach;
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl;
diff --git a/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj b/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj
index ab7050d..a22cc5d 100644
--- a/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj
+++ b/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj
@@ -30,6 +30,7 @@
+
@@ -62,6 +63,7 @@
+
diff --git a/src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs b/src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs
new file mode 100644
index 0000000..7b911f9
--- /dev/null
+++ b/src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs
@@ -0,0 +1,51 @@
+using JT808.Protocol.Formatters;
+using JT808.Protocol.Interfaces;
+using JT808.Protocol.MessagePack;
+using JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT808.Protocol.Test.MessageBody.JT808Formatters
+{
+ public class JT808_0x8103_0x0075_Formatter : IJT808MessagePackFormatter
+ {
+ public JT808_0x8103_0x0075 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8103_0x0075 jT808_0X8103_0X0075 = new JT808_0x8103_0x0075();
+ jT808_0X8103_0X0075.ParamId = reader.ReadUInt32();
+ jT808_0X8103_0X0075.ParamLength = reader.ReadByte();
+ jT808_0X8103_0X0075.RTS_EncodeMode = reader.ReadByte();
+ jT808_0X8103_0X0075.RTS_Resolution = reader.ReadByte();
+ jT808_0X8103_0X0075.RTS_KF_Interval = reader.ReadUInt16();
+ jT808_0X8103_0X0075.RTS_Target_FPS = reader.ReadByte();
+ jT808_0X8103_0X0075.RTS_Target_CodeRate = reader.ReadUInt32();
+ jT808_0X8103_0X0075.StreamStore_EncodeMode = reader.ReadByte();
+ jT808_0X8103_0X0075.StreamStore_Resolution = reader.ReadByte();
+ jT808_0X8103_0X0075.StreamStore_KF_Interval = reader.ReadUInt16();
+ jT808_0X8103_0X0075.StreamStore_Target_FPS = reader.ReadByte();
+ jT808_0X8103_0X0075.StreamStore_Target_CodeRate = reader.ReadUInt32();
+ jT808_0X8103_0X0075.OSD = reader.ReadUInt16();
+ jT808_0X8103_0X0075.AudioOutputEnabled = reader.ReadByte();
+ return jT808_0X8103_0X0075;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8103_0x0075 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.ParamId);
+ writer.WriteByte(value.ParamLength);
+ writer.WriteByte(value.RTS_EncodeMode);
+ writer.WriteByte(value.RTS_Resolution);
+ writer.WriteUInt16(value.RTS_KF_Interval);
+ writer.WriteByte(value.RTS_Target_FPS);
+ writer.WriteUInt32(value.RTS_Target_CodeRate);
+ writer.WriteByte(value.StreamStore_EncodeMode);
+ writer.WriteByte(value.StreamStore_Resolution);
+ writer.WriteUInt16(value.StreamStore_KF_Interval);
+ writer.WriteByte(value.StreamStore_Target_FPS);
+ writer.WriteUInt32(value.StreamStore_Target_CodeRate);
+ writer.WriteUInt16(value.OSD);
+ writer.WriteByte(value.AudioOutputEnabled);
+ }
+ }
+}
diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs
new file mode 100644
index 0000000..279f082
--- /dev/null
+++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs
@@ -0,0 +1,77 @@
+using JT808.Protocol.Attributes;
+using JT808.Protocol.MessageBody;
+using JT808.Protocol.Test.MessageBody.JT808Formatters;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions
+{
+ ///
+ /// 音视频参数设置
+ /// 0x8103_0x0075
+ ///
+ [JT808Formatter(typeof(JT808_0x8103_0x0075_Formatter))]
+ public class JT808_0x8103_0x0075 : JT808_0x8103_CustomBodyBase
+ {
+ public override uint ParamId { get; set; } = 0x0075;
+ ///
+ /// 数据 长度
+ ///
+ public override byte ParamLength { get; set; } = 21;
+ ///
+ /// 实时流编码模式
+ ///
+ public byte RTS_EncodeMode { get; set; }
+ ///
+ /// 实时流分辨率
+ ///
+ public byte RTS_Resolution { get; set; }
+ ///
+ /// 实时流关键帧间隔
+ /// (范围1-1000)帧
+ ///
+ public ushort RTS_KF_Interval { get; set; }
+ ///
+ /// 实时流目标帧率
+ ///
+ public byte RTS_Target_FPS { get; set; }
+ ///
+ /// 实时流目标码率
+ /// 单位未千位每秒(kbps)
+ ///
+ public uint RTS_Target_CodeRate { get; set; }
+ ///
+ /// 存储流编码模式
+ ///
+ public byte StreamStore_EncodeMode { get; set; }
+ ///
+ /// 存储流分辨率
+ ///
+ public byte StreamStore_Resolution { get; set; }
+ ///
+ /// 存储流关键帧间隔
+ /// (范围1-1000)帧
+ ///
+ public ushort StreamStore_KF_Interval { get; set; }
+ ///
+ /// 存储流目标帧率
+ ///
+ public byte StreamStore_Target_FPS { get; set; }
+ ///
+ /// 存储流目标码率
+ /// 单位未千位每秒(kbps)
+ ///
+ public uint StreamStore_Target_CodeRate { get; set; }
+ ///
+ ///OSD字幕叠加设置
+ ///
+ public ushort OSD { get; set; }
+ ///
+ ///是否启用音频输出
+ ///0:不启用
+ ///1:启用
+ ///
+ public byte AudioOutputEnabled { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs
index a04d775..f34261a 100644
--- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs
+++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs
@@ -2,6 +2,7 @@
using JT808.Protocol.Interfaces;
using JT808.Protocol.Internal;
using JT808.Protocol.MessageBody;
+using JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions;
using System.Collections.Generic;
using System.Reflection;
using Xunit;
@@ -119,8 +120,47 @@ namespace JT808.Protocol.Test.MessageBody
default:
break;
}
-
}
}
+
+ [Fact]
+ public void Test3()
+ {
+ var JT808_0x8103 = new JT808_0x8103
+ {
+ ParamList=new List(),
+ CustomParamList = new List {
+ new JT808_0x8103_0x0075() {
+ AudioOutputEnabled=1,
+ OSD=2,
+ RTS_EncodeMode=3,
+ RTS_KF_Interval=4,
+ RTS_Resolution=5,
+ RTS_Target_CodeRate=6,
+ RTS_Target_FPS=7,
+ StreamStore_EncodeMode=8,
+ StreamStore_KF_Interval=9,
+ StreamStore_Resolution=10,
+ StreamStore_Target_CodeRate=11,
+ StreamStore_Target_FPS=12
+ }
+ }
+ };
+ var customParams = Newtonsoft.Json.JsonConvert.SerializeObject(JT808_0x8103.CustomParamList);
+ //"[{\"ParamId\":117,\"ParamLength\":21,\"RTS_EncodeMode\":3,\"RTS_Resolution\":5,\"RTS_KF_Interval\":4,\"RTS_Target_FPS\":7,\"RTS_Target_CodeRate\":6,\"StreamStore_EncodeMode\":8,\"StreamStore_Resolution\":10,\"StreamStore_KF_Interval\":9,\"StreamStore_Target_FPS\":12,\"StreamStore_Target_CodeRate\":11,\"OSD\":2,\"AudioOutputEnabled\":1}]"
+ var hex = JT808Serializer.Serialize(JT808_0x8103).ToHexString();
+ //"010000007515030500040700000006080A00090C0000000B000201"
+ Assert.Equal("010000007515030500040700000006080A00090C0000000B000201", hex);
+ }
+
+ [Fact]
+ public void Test3_1()
+ {
+ var customParams = "[{\"ParamId\":117,\"ParamLength\":21,\"RTS_EncodeMode\":3,\"RTS_Resolution\":5,\"RTS_KF_Interval\":4,\"RTS_Target_FPS\":7,\"RTS_Target_CodeRate\":6,\"StreamStore_EncodeMode\":8,\"StreamStore_Resolution\":10,\"StreamStore_KF_Interval\":9,\"StreamStore_Target_FPS\":12,\"StreamStore_Target_CodeRate\":11,\"OSD\":2,\"AudioOutputEnabled\":1}]";
+ byte[] bytes = "010000007515030500040700000006080A00090C0000000B000201".ToHexBytes();
+ JT808_0x8103 jT808_0X8103 = JT808Serializer.Deserialize(bytes);
+
+ Assert.Equal(customParams, Newtonsoft.Json.JsonConvert.SerializeObject(jT808_0X8103.CustomParamList));
+ }
}
}
diff --git a/src/JT808.Protocol.sln b/src/JT808.Protocol.sln
index e0964df..968c2e7 100644
--- a/src/JT808.Protocol.sln
+++ b/src/JT808.Protocol.sln
@@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Benchmark", "JT808.Protocol.Benchmark\JT808.Protocol.Benchmark.csproj", "{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.DependencyInjection", "JT808.Protocol.Extensions.DependencyInjection\JT808.Protocol.Extensions.DependencyInjection.csproj", "{B5F627C8-D3EF-4DE2-B2F0-249595D170E1}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.DependencyInjection.Test", "JT808.Protocol.Extensions.DependencyInjection.Test\JT808.Protocol.Extensions.DependencyInjection.Test.csproj", "{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}"
EndProject
Global
@@ -37,10 +35,6 @@ Global
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Release|Any CPU.Build.0 = Release|Any CPU
- {B5F627C8-D3EF-4DE2-B2F0-249595D170E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B5F627C8-D3EF-4DE2-B2F0-249595D170E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B5F627C8-D3EF-4DE2-B2F0-249595D170E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B5F627C8-D3EF-4DE2-B2F0-249595D170E1}.Release|Any CPU.Build.0 = Release|Any CPU
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/src/JT808.Protocol/DependencyInjectionExtensions.cs b/src/JT808.Protocol/DependencyInjectionExtensions.cs
new file mode 100644
index 0000000..ad96745
--- /dev/null
+++ b/src/JT808.Protocol/DependencyInjectionExtensions.cs
@@ -0,0 +1,26 @@
+using JT808.Protocol.Interfaces;
+using JT808.Protocol.Internal;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT808.Protocol
+{
+ public static class DependencyInjectionExtensions
+ {
+ public static IJT808Builder AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config)
+ {
+ services.AddSingleton(jT808Config.GetType(), jT808Config);
+ services.AddSingleton(jT808Config);
+ return new DefaultBuilder(services, jT808Config);
+ }
+
+ public static IJT808Builder AddJT808Configure(this IServiceCollection services)
+ {
+ DefaultGlobalConfig config = new DefaultGlobalConfig();
+ services.AddSingleton(config);
+ return new DefaultBuilder(services, config);
+ }
+ }
+}
diff --git a/src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs b/src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs
index 4aaf9e2..be26377 100644
--- a/src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs
+++ b/src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs
@@ -105,8 +105,8 @@ namespace JT808.Protocol.Extensions
{
Type type = value.GetType();
var ti = type.GetTypeInfo();
- (object Value, JT808SerializeMethod SerializeMethod) formatterAndDelegate;
- if (!jT808Serializers.TryGetValue(type, out formatterAndDelegate))
+ // (object Value, JT808SerializeMethod SerializeMethod) formatterAndDelegate;
+ if (!jT808Serializers.TryGetValue(type, out var formatterAndDelegate))
{
var t = type;
{
@@ -132,8 +132,8 @@ namespace JT808.Protocol.Extensions
public static dynamic JT808DynamicDeserialize(object objFormatter, ref JT808MessagePackReader reader, IJT808Config config)
{
var type = objFormatter.GetType();
- (object Value, JT808DeserializeMethod DeserializeMethod) formatterAndDelegate;
- if (!jT808Deserializes.TryGetValue(type, out formatterAndDelegate))
+ // (object Value, JT808DeserializeMethod DeserializeMethod) formatterAndDelegate;
+ if (!jT808Deserializes.TryGetValue(type, out var formatterAndDelegate))
{
var t = type;
{
diff --git a/src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs b/src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
index dec980c..aff2aba 100644
--- a/src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
+++ b/src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
@@ -32,7 +32,7 @@ namespace JT808.Protocol.Formatters.MessageBodyFormatters
{
object attachImplObj = config.GetMessagePackFormatterByType(customType);
dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(attachImplObj, ref reader, config);
- jT808_0x8103.ParamList.Add(attachImpl);
+ jT808_0x8103.CustomParamList.Add(attachImpl);
}
}
}
diff --git a/src/JT808.Protocol/IJT808Builder.cs b/src/JT808.Protocol/IJT808Builder.cs
new file mode 100644
index 0000000..fee3826
--- /dev/null
+++ b/src/JT808.Protocol/IJT808Builder.cs
@@ -0,0 +1,15 @@
+using JT808.Protocol.Interfaces;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT808.Protocol
+{
+ public interface IJT808Builder
+ {
+ IServiceCollection Services { get; }
+
+ IJT808Config Config { get; }
+ }
+}
diff --git a/src/JT808.Protocol/Internal/DefaultBuilder.cs b/src/JT808.Protocol/Internal/DefaultBuilder.cs
new file mode 100644
index 0000000..65e0d01
--- /dev/null
+++ b/src/JT808.Protocol/Internal/DefaultBuilder.cs
@@ -0,0 +1,21 @@
+using JT808.Protocol.Interfaces;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT808.Protocol.Internal
+{
+ class DefaultBuilder : IJT808Builder
+ {
+ public IServiceCollection Services { get; }
+
+ public IJT808Config Config { get; }
+
+ public DefaultBuilder(IServiceCollection services, IJT808Config config)
+ {
+ Services = services;
+ Config = config;
+ }
+ }
+}
diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj
index b44da2f..90dbbbb 100644
--- a/src/JT808.Protocol/JT808.Protocol.csproj
+++ b/src/JT808.Protocol/JT808.Protocol.csproj
@@ -14,7 +14,7 @@
https://github.com/SmallChi/JT808/blob/master/LICENSE
https://github.com/SmallChi/JT808/blob/master/LICENSE
true
- 2.0.0
+ 2.1.0
bin\Release\netstandard2.0\JT808.Protocol.xml
@@ -41,6 +41,7 @@
+