Procházet zdrojové kódy

v2.1.0

1.修复0x8103消息的自定义id反序列化时报错
2.新增0x8103消息的自定义id的测试用例

3.更改版本号

4.移除依赖注入扩展项目
5.将依赖注入以扩展的形式写入主项目中

6.更新说明文档
7.修复IJT808Builder的修饰符为Interface

Author:    waterliu99 <qqcc2012game@163.com>
Date:      Wed Jul 3 18:57:39 2019 +0800
    squash 2fcc930 更改版本号
    squash c0e7fc1 1.移除依赖注入扩展项目 2.将依赖注入以扩展的形式写入主项目中
	modified:   src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj
	modified:   src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs
	modified:   src/JT808.Protocol.Test/JT808.Protocol.Test.csproj
	new file:   src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs
	new file:   src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs
	modified:   src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs
	modified:   src/JT808.Protocol.sln
	new file:   src/JT808.Protocol/DependencyInjectionExtensions.cs
	modified:   src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs
	modified:   src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
        new file:   src/JT808.Protocol/IJT808Builder.cs
tags/v2.1.0
waterliu99 před 5 roky
rodič
revize
3854c64923
14 změnil soubory, kde provedl 241 přidání a 16 odebrání
  1. +0
    -1
      README.md
  2. +1
    -1
      src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj
  3. +0
    -1
      src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs
  4. +2
    -0
      src/JT808.Protocol.Test/JT808.Protocol.Test.csproj
  5. +51
    -0
      src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs
  6. +77
    -0
      src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs
  7. +41
    -1
      src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs
  8. +0
    -6
      src/JT808.Protocol.sln
  9. +26
    -0
      src/JT808.Protocol/DependencyInjectionExtensions.cs
  10. +4
    -4
      src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs
  11. +1
    -1
      src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
  12. +15
    -0
      src/JT808.Protocol/IJT808Builder.cs
  13. +21
    -0
      src/JT808.Protocol/Internal/DefaultBuilder.cs
  14. +2
    -1
      src/JT808.Protocol/JT808.Protocol.csproj

+ 0
- 1
README.md Zobrazit soubor

@@ -261,7 +261,6 @@ JT808Serializer JT808Serializer = new JT808Serializer(jT808Coonfig);
| Package Name | Version | Downloads |
| --------------------- | -------------------------------------------------- | --------------------------------------------------- |
| Install-Package JT808 | ![JT808](https://img.shields.io/nuget/v/JT808.svg) | ![JT808](https://img.shields.io/nuget/dt/JT808.svg) |
| Install-Package JT808.Extensions.DependencyInjection | ![JT808](https://img.shields.io/nuget/v/JT808.Extensions.DependencyInjection.svg) | ![JT808](https://img.shields.io/nuget/dt/JT808.Extensions.DependencyInjection.svg) |

## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真)



+ 1
- 1
src/JT808.Protocol.Extensions.DependencyInjection.Test/JT808.Protocol.Extensions.DependencyInjection.Test.csproj Zobrazit soubor

@@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\JT808.Protocol.Extensions.DependencyInjection\JT808.Protocol.Extensions.DependencyInjection.csproj" />
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" />
</ItemGroup>

<ItemGroup>


+ 0
- 1
src/JT808.Protocol.Extensions.DependencyInjection.Test/Program.cs Zobrazit soubor

@@ -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;


+ 2
- 0
src/JT808.Protocol.Test/JT808.Protocol.Test.csproj Zobrazit soubor

@@ -30,6 +30,7 @@
<Compile Include="MessageBody\JT808Formatters\JT808_0x0200_0x06Formatter.cs" />
<Compile Include="MessageBody\JT808Formatters\JT808_0x0701TestBodiesImplFormatter.cs" />
<Compile Include="MessageBody\JT808Formatters\JT808_0x0900_0x83Formatter.cs" />
<Compile Include="MessageBody\JT808Formatters\JT808_0x8103_0x0075_Formatter.cs" />
<Compile Include="MessageBody\JT808Formatters\JT808_0X8900_Test_BodiesImplFormatter.cs" />
<Compile Include="MessageBody\JT808LocationAttachExtensions\JT808LocationAttachImpl0x06.cs" />
<Compile Include="MessageBody\JT808_0x0001Test.cs" />
@@ -62,6 +63,7 @@
<Compile Include="MessageBody\JT808_0x8001Test.cs" />
<Compile Include="MessageBody\JT808_0x8003Test.cs" />
<Compile Include="MessageBody\JT808_0x8100Test.cs" />
<Compile Include="MessageBody\JT808_0x8103CustomIdExtensions\JT808_0x8103_0x0075.cs" />
<Compile Include="MessageBody\JT808_0x8103Test.cs" />
<Compile Include="MessageBody\JT808_0x8104Test.cs" />
<Compile Include="MessageBody\JT808_0x8105Test.cs" />


+ 51
- 0
src/JT808.Protocol.Test/MessageBody/JT808Formatters/JT808_0x8103_0x0075_Formatter.cs Zobrazit soubor

@@ -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<JT808_0x8103_0x0075>
{
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);
}
}
}

+ 77
- 0
src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs Zobrazit soubor

@@ -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
{
/// <summary>
/// 音视频参数设置
/// 0x8103_0x0075
/// </summary>
[JT808Formatter(typeof(JT808_0x8103_0x0075_Formatter))]
public class JT808_0x8103_0x0075 : JT808_0x8103_CustomBodyBase
{
public override uint ParamId { get; set; } = 0x0075;
/// <summary>
/// 数据 长度
/// </summary>
public override byte ParamLength { get; set; } = 21;
/// <summary>
/// 实时流编码模式
/// </summary>
public byte RTS_EncodeMode { get; set; }
/// <summary>
/// 实时流分辨率
/// </summary>
public byte RTS_Resolution { get; set; }
/// <summary>
/// 实时流关键帧间隔
/// (范围1-1000)帧
/// </summary>
public ushort RTS_KF_Interval { get; set; }
/// <summary>
/// 实时流目标帧率
/// </summary>
public byte RTS_Target_FPS { get; set; }
/// <summary>
/// 实时流目标码率
/// 单位未千位每秒(kbps)
/// </summary>
public uint RTS_Target_CodeRate { get; set; }
/// <summary>
/// 存储流编码模式
/// </summary>
public byte StreamStore_EncodeMode { get; set; }
/// <summary>
/// 存储流分辨率
/// </summary>
public byte StreamStore_Resolution { get; set; }
/// <summary>
/// 存储流关键帧间隔
/// (范围1-1000)帧
/// </summary>
public ushort StreamStore_KF_Interval { get; set; }
/// <summary>
/// 存储流目标帧率
/// </summary>
public byte StreamStore_Target_FPS { get; set; }
/// <summary>
/// 存储流目标码率
/// 单位未千位每秒(kbps)
/// </summary>
public uint StreamStore_Target_CodeRate { get; set; }
/// <summary>
///OSD字幕叠加设置
/// </summary>
public ushort OSD { get; set; }
/// <summary>
///是否启用音频输出
///0:不启用
///1:启用
/// </summary>
public byte AudioOutputEnabled { get; set; }
}
}

+ 41
- 1
src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs Zobrazit soubor

@@ -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<JT808_0x8103_BodyBase>(),
CustomParamList = new List<JT808_0x8103_CustomBodyBase> {
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<JT808_0x8103>(bytes);

Assert.Equal(customParams, Newtonsoft.Json.JsonConvert.SerializeObject(jT808_0X8103.CustomParamList));
}
}
}

+ 0
- 6
src/JT808.Protocol.sln Zobrazit soubor

@@ -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


+ 26
- 0
src/JT808.Protocol/DependencyInjectionExtensions.cs Zobrazit soubor

@@ -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<IJT808Config>(config);
return new DefaultBuilder(services, config);
}
}
}

+ 4
- 4
src/JT808.Protocol/Extensions/JT808FormatterResolverExtensions.cs Zobrazit soubor

@@ -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;
{


+ 1
- 1
src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs Zobrazit soubor

@@ -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);
}
}
}


+ 15
- 0
src/JT808.Protocol/IJT808Builder.cs Zobrazit soubor

@@ -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; }
}
}

+ 21
- 0
src/JT808.Protocol/Internal/DefaultBuilder.cs Zobrazit soubor

@@ -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;
}
}
}

+ 2
- 1
src/JT808.Protocol/JT808.Protocol.csproj Zobrazit soubor

@@ -14,7 +14,7 @@
<licenseUrl>https://github.com/SmallChi/JT808/blob/master/LICENSE</licenseUrl>
<license>https://github.com/SmallChi/JT808/blob/master/LICENSE</license>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\JT808.Protocol.xml</DocumentationFile>
@@ -41,6 +41,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Memory" Version="4.5.3" />


Načítá se…
Zrušit
Uložit