Browse Source

1.调整为byte数组类型

2.增加byte对象池的使用
tags/v1.3.0
SmallChi 6 years ago
parent
commit
86589bb9b2
65 changed files with 363 additions and 340 deletions
  1. +2
    -1
      src/JT809.Protocol/JT809.Protocol.csproj
  2. +27
    -0
      src/JT809.Protocol/JT809ArrayPool.cs
  3. +2
    -3
      src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs
  4. +30
    -30
      src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs
  5. +1
    -1
      src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs
  6. +13
    -13
      src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs
  7. +5
    -5
      src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs
  8. +2
    -2
      src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs
  9. +13
    -13
      src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs
  10. +1
    -1
      src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs
  11. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs
  12. +8
    -8
      src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs
  13. +5
    -5
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs
  14. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs
  15. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs
  16. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs
  17. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs
  18. +4
    -4
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs
  19. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs
  20. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs
  21. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs
  22. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs
  23. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs
  24. +4
    -4
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs
  25. +4
    -4
      src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs
  26. +10
    -11
      src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs
  27. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs
  28. +17
    -17
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs
  29. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs
  30. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs
  31. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs
  32. +5
    -5
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs
  33. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs
  34. +5
    -5
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs
  35. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs
  36. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs
  37. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs
  38. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs
  39. +7
    -7
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs
  40. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs
  41. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs
  42. +23
    -23
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs
  43. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs
  44. +4
    -4
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs
  45. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs
  46. +17
    -17
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs
  47. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs
  48. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs
  49. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs
  50. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs
  51. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs
  52. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs
  53. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs
  54. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs
  55. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs
  56. +10
    -10
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs
  57. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs
  58. +6
    -6
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs
  59. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs
  60. +3
    -3
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs
  61. +5
    -5
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs
  62. +5
    -5
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs
  63. +9
    -9
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs
  64. +2
    -2
      src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs
  65. +11
    -14
      src/JT809.Protocol/JT809Serializer.cs

+ 2
- 1
src/JT809.Protocol/JT809.Protocol.csproj View File

@@ -14,7 +14,7 @@
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/SmallChi/JT809/blob/master/LICENSE</PackageLicenseUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.6</Version>
<Version>1.0.7</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -89,6 +89,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.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.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0" />


+ 27
- 0
src/JT809.Protocol/JT809ArrayPool.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;

namespace JT809.Protocol
{
public static class JT809ArrayPool
{
private readonly static ArrayPool<byte> ArrayPool;

static JT809ArrayPool()
{
ArrayPool = ArrayPool<byte>.Create();
}

public static byte[] Rent(int minimumLength)
{
return ArrayPool.Rent(minimumLength);
}

public static void Return(byte[] array, bool clearArray = false)
{
ArrayPool.Return(array, clearArray);
}
}
}

+ 2
- 3
src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs View File

@@ -19,10 +19,9 @@ namespace JT809.Protocol.JT809Extensions
return bcdSb.ToString();
}

public static int WriteBCDLittle(IMemoryOwner<byte> memoryOwner, int offset, string data,int len)
public static int WriteBCDLittle(byte[] bytes, int offset, string data,int len)
{
string bcdText = data == null ? "" : data;
byte[] bytes = new byte[len];
int startIndex = 0;
int noOfZero = len * 2 - bcdText.Length;
if (noOfZero > 0)
@@ -32,7 +31,7 @@ namespace JT809.Protocol.JT809Extensions
int byteIndex = 0;
while (startIndex < bcdText.Length && byteIndex < len)
{
memoryOwner.Memory.Span[startIndex + offset] = Convert.ToByte(bcdText.Substring(startIndex, 2), 16);
bytes[startIndex + offset] = Convert.ToByte(bcdText.Substring(startIndex, 2), 16);
startIndex += 2;
byteIndex++;
}


+ 30
- 30
src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs View File

@@ -104,53 +104,53 @@ namespace JT809.Protocol.JT809Extensions
return result.ToString();
}

public static int WriteInt32Little(IMemoryOwner<byte> memoryOwner, int offset, int data)
public static int WriteInt32Little(byte[] bytes, int offset, int data)
{
memoryOwner.Memory.Span[offset] = (byte)(data >> 24);
memoryOwner.Memory.Span[offset + 1] = (byte)(data >> 16);
memoryOwner.Memory.Span[offset + 2] = (byte)(data >> 8);
memoryOwner.Memory.Span[offset + 3] = (byte)data;
bytes[offset] = (byte)(data >> 24);
bytes[offset + 1] = (byte)(data >> 16);
bytes[offset + 2] = (byte)(data >> 8);
bytes[offset + 3] = (byte)data;
return 4;
}

public static int WriteUInt32Little(IMemoryOwner<byte> memoryOwner, int offset, uint data)
public static int WriteUInt32Little(byte[] bytes, int offset, uint data)
{
memoryOwner.Memory.Span[offset] = (byte)(data >> 24);
memoryOwner.Memory.Span[offset + 1] = (byte)(data >> 16);
memoryOwner.Memory.Span[offset + 2] = (byte)(data >> 8);
memoryOwner.Memory.Span[offset + 3] = (byte)data;
bytes[offset] = (byte)(data >> 24);
bytes[offset + 1] = (byte)(data >> 16);
bytes[offset + 2] = (byte)(data >> 8);
bytes[offset + 3] = (byte)data;
return 4;
}

public static int WriteUInt64Little(IMemoryOwner<byte> memoryOwner, int offset, ulong data)
public static int WriteUInt64Little(byte[] bytes, int offset, ulong data)
{
memoryOwner.Memory.Span[offset] = (byte)(data >> 56);
memoryOwner.Memory.Span[offset + 1] = (byte)(data >> 48);
memoryOwner.Memory.Span[offset + 2] = (byte)(data >> 40);
memoryOwner.Memory.Span[offset + 3] = (byte)(data >> 32);
memoryOwner.Memory.Span[offset + 4] = (byte)(data >> 24);
memoryOwner.Memory.Span[offset + 5] = (byte)(data >> 16);
memoryOwner.Memory.Span[offset + 6] = (byte)(data >> 8);
memoryOwner.Memory.Span[offset + 7] = (byte)data;
bytes[offset] = (byte)(data >> 56);
bytes[offset + 1] = (byte)(data >> 48);
bytes[offset + 2] = (byte)(data >> 40);
bytes[offset + 3] = (byte)(data >> 32);
bytes[offset + 4] = (byte)(data >> 24);
bytes[offset + 5] = (byte)(data >> 16);
bytes[offset + 6] = (byte)(data >> 8);
bytes[offset + 7] = (byte)data;
return 8;
}

public static int WriteUInt16Little(IMemoryOwner<byte> memoryOwner, int offset, ushort data)
public static int WriteUInt16Little(byte[] bytes, int offset, ushort data)
{
memoryOwner.Memory.Span[offset] = (byte)(data >> 8);
memoryOwner.Memory.Span[offset + 1] = (byte)data;
bytes[offset] = (byte)(data >> 8);
bytes[offset + 1] = (byte)data;
return 2;
}

public static int WriteByteLittle(IMemoryOwner<byte> memoryOwner, int offset, byte data)
public static int WriteByteLittle(byte[] bytes, int offset, byte data)
{
memoryOwner.Memory.Span[offset] = data;
bytes[offset] = data;
return 1;
}

public static int WriteBytesLittle(IMemoryOwner<byte> memoryOwner, int offset, byte[] data)
public static int WriteBytesLittle(byte[] bytes, int offset, byte[] data)
{
CopyTo(data, memoryOwner.Memory.Span, offset);
Array.Copy(data, 0, bytes, offset, data.Length);
return data.Length;
}

@@ -162,12 +162,12 @@ namespace JT809.Protocol.JT809Extensions
/// <param name="data"></param>
/// <param name="len"></param>
/// <returns></returns>
public static int WriteBigNumberLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteBigNumberLittle(byte[] bytes, int offset, string data, int len)
{
ulong number = string.IsNullOrEmpty(data) ? 0 : (ulong)double.Parse(data);
for (int i = len - 1; i >= 0; i--)
{
memoryOwner.Memory.Span[offset+i] = (byte)(number & 0xFF); //取低8位
bytes[offset+i] = (byte)(number & 0xFF); //取低8位
number = number >> 8;
}
return len;
@@ -181,12 +181,12 @@ namespace JT809.Protocol.JT809Extensions
/// <param name="data"></param>
/// <param name="len"></param>
/// <returns></returns>
public static int WriteLowNumberLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteLowNumberLittle(byte[] bytes, int offset, string data, int len)
{
ulong number = string.IsNullOrEmpty(data) ? 0 : (ulong)double.Parse(data);
for (int i = 0; i < len; i++)
{
memoryOwner.Memory.Span[offset + i] = (byte)(number & 0xFF); //取低8位
bytes[offset + i] = (byte)(number & 0xFF); //取低8位
number = number >> 8;
}
return len;


+ 1
- 1
src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs View File

@@ -13,7 +13,7 @@ namespace JT809.Protocol.JT809Extensions
/// <param name="offset"></param>
/// <param name="iLen"></param>
/// <returns></returns>
public static ushort ToCRC16_CCITT(this Span<byte> ucbuf, int offset, int iLen)
public static ushort ToCRC16_CCITT(this byte[] ucbuf, int offset, int iLen)
{
ushort checkCode = 0xFFFF;
for (int j = offset; j < iLen; ++j)


+ 13
- 13
src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs View File

@@ -79,13 +79,13 @@ namespace JT809.Protocol.JT809Extensions
return UTCBaseTime.AddSeconds(result).AddHours(8);
}

public static int WriteUTCDateTimeLittle(IMemoryOwner<byte> memoryOwner, int offset, DateTime date)
public static int WriteUTCDateTimeLittle(byte[] bytes, int offset, DateTime date)
{
ulong totalSecends = (ulong)(date.AddHours(-8) - UTCBaseTime).TotalSeconds;
//高位在前
for (int i = 7; i >= 0; i--)
{
memoryOwner.Memory.Span[offset + i] = (byte)(totalSecends & 0xFF); //取低8位
bytes[offset + i] = (byte)(totalSecends & 0xFF); //取低8位
totalSecends = totalSecends >> 8;
}
return 8;
@@ -99,14 +99,14 @@ namespace JT809.Protocol.JT809Extensions
/// <param name="date"></param>
/// <param name="fromBase">BCD:10 HEX:16</param>
/// <returns></returns>
public static int WriteDateTime6Little(IMemoryOwner<byte> memoryOwner, int offset, DateTime date,int fromBase=16)
public static int WriteDateTime6Little(byte[] bytes, int offset, DateTime date,int fromBase=16)
{
memoryOwner.Memory.Span[offset] = Convert.ToByte(date.ToString("yy"), fromBase);
memoryOwner.Memory.Span[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase);
memoryOwner.Memory.Span[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase);
memoryOwner.Memory.Span[offset + 3] = Convert.ToByte(date.ToString("HH"), fromBase);
memoryOwner.Memory.Span[offset + 4] = Convert.ToByte(date.ToString("mm"), fromBase);
memoryOwner.Memory.Span[offset + 5] = Convert.ToByte(date.ToString("ss"), fromBase);
bytes[offset] = Convert.ToByte(date.ToString("yy"), fromBase);
bytes[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase);
bytes[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase);
bytes[offset + 3] = Convert.ToByte(date.ToString("HH"), fromBase);
bytes[offset + 4] = Convert.ToByte(date.ToString("mm"), fromBase);
bytes[offset + 5] = Convert.ToByte(date.ToString("ss"), fromBase);
return 6;
}

@@ -118,11 +118,11 @@ namespace JT809.Protocol.JT809Extensions
/// <param name="date"></param>
/// <param name="fromBase">BCD:10 HEX:16</param>
/// <returns></returns>
public static int WriteDateTime4Little(IMemoryOwner<byte> memoryOwner, int offset, DateTime date, int fromBase = 16)
public static int WriteDateTime4Little(byte[] bytes, int offset, DateTime date, int fromBase = 16)
{
memoryOwner.Memory.Span[offset] = Convert.ToByte(date.ToString("yy"), fromBase);
memoryOwner.Memory.Span[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase);
memoryOwner.Memory.Span[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase);
bytes[offset] = Convert.ToByte(date.ToString("yy"), fromBase);
bytes[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase);
bytes[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase);
return 4;
}
}


+ 5
- 5
src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs View File

@@ -17,7 +17,7 @@ namespace JT809.Protocol.JT809Extensions
/// </summary>
public static class JT809FormatterResolverExtensions
{
delegate int JT809SerializeMethod(object dynamicFormatter, IMemoryOwner<byte> memoryOwner, int offset, object value);
delegate int JT809SerializeMethod(object dynamicFormatter, ref byte[] bytes, int offset, object value);

delegate dynamic JT809DeserializeMethod(object dynamicFormatter, ReadOnlySpan<byte> bytes, out int readSize);

@@ -28,7 +28,7 @@ namespace JT809.Protocol.JT809Extensions
//T Deserialize(ReadOnlySpan<byte> bytes, out int readSize);
//int Serialize(IMemoryOwner<byte> memoryOwner, int offset, T value);

public static int JT809DynamicSerialize(object objFormatter, IMemoryOwner<byte> memoryOwner, int offset, dynamic value)
public static int JT809DynamicSerialize(object objFormatter,ref byte[] bytes, int offset, dynamic value)
{
Type type = value.GetType();
var ti = type.GetTypeInfo();
@@ -39,10 +39,10 @@ namespace JT809.Protocol.JT809Extensions
{
var formatterType = typeof(IJT809Formatter<>).MakeGenericType(t);
var param0 = Expression.Parameter(typeof(object), "formatter");
var param1 = Expression.Parameter(typeof(IMemoryOwner<byte>), "memoryOwner");
var param1 = Expression.Parameter(typeof(byte[]).MakeByRefType(), "bytes");
var param2 = Expression.Parameter(typeof(int), "offset");
var param3 = Expression.Parameter(typeof(object), "value");
var serializeMethodInfo = formatterType.GetRuntimeMethod("Serialize", new[] { typeof(IMemoryOwner<byte>), typeof(int), t});
var serializeMethodInfo = formatterType.GetRuntimeMethod("Serialize", new[] { typeof(byte[]).MakeByRefType(), typeof(int), t});
var body = Expression.Call(
Expression.Convert(param0, formatterType),
serializeMethodInfo,
@@ -54,7 +54,7 @@ namespace JT809.Protocol.JT809Extensions
}
jT809Serializers.TryAdd(t, formatterAndDelegate);
}
return formatterAndDelegate.SerializeMethod(formatterAndDelegate.Value, memoryOwner, offset, value);
return formatterAndDelegate.SerializeMethod(formatterAndDelegate.Value, ref bytes, offset, value);
}

public static dynamic JT809DynamicDeserialize(object objFormatter,ReadOnlySpan<byte> bytes, out int readSize)


+ 2
- 2
src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs View File

@@ -83,7 +83,7 @@ namespace JT809.Protocol.JT809Extensions
return ToHexString(source, false);
}

public static int WriteHexStringLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteHexStringLittle(byte[] bytes, int offset, string data, int len)
{
if (data == null) data = "";
data = data.Replace(" ", "");
@@ -105,7 +105,7 @@ namespace JT809.Protocol.JT809Extensions
int byteIndex = 0;
while (startIndex < data.Length && byteIndex < length)
{
memoryOwner.Memory.Span[offset+byteIndex] = Convert.ToByte(data.Substring(startIndex, 2), 16);
bytes[offset+byteIndex] = Convert.ToByte(data.Substring(startIndex, 2), 16);
startIndex += 2;
byteIndex++;
}


+ 13
- 13
src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs View File

@@ -23,47 +23,47 @@ namespace JT809.Protocol.JT809Extensions
return value.Trim('\0');
}

public static int WriteStringLittle(IMemoryOwner<byte> memoryOwner, int offset, string data)
public static int WriteStringLittle(byte[] bytes, int offset, string data)
{
byte[] codeBytes = encoding.GetBytes(data);
CopyTo(codeBytes, memoryOwner.Memory.Span, offset);
Array.Copy(codeBytes, 0, bytes, offset, codeBytes.Length);
return codeBytes.Length;
}

public static int WriteStringLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteStringLittle(byte[] bytes, int offset, string data, int len)
{
byte[] bytes = null;
byte[] tempBytes = null;
if (string.IsNullOrEmpty(data))
{
bytes = new byte[0];
tempBytes = new byte[0];
}
else
{
bytes = encoding.GetBytes(data);
tempBytes = encoding.GetBytes(data);
}
byte[] rBytes = new byte[len];
for (int i = 0; i < bytes.Length; i++)
for (int i = 0; i < tempBytes.Length; i++)
{
if (i >= len) break;
rBytes[i] = bytes[i];
rBytes[i] = tempBytes[i];
}
CopyTo(rBytes, memoryOwner.Memory.Span, offset);
Array.Copy(rBytes, 0, bytes, offset, rBytes.Length);
return rBytes.Length;
}

public static int WriteStringPadLeftLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteStringPadLeftLittle(byte[] bytes, int offset, string data, int len)
{
data = data.PadLeft(len, '\0');
byte[] codeBytes = encoding.GetBytes(data);
CopyTo(codeBytes, memoryOwner.Memory.Span, offset);
Array.Copy(codeBytes, 0, bytes, offset, codeBytes.Length);
return codeBytes.Length;
}

public static int WriteStringPadRightLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len)
public static int WriteStringPadRightLittle(byte[] bytes, int offset, string data, int len)
{
data = data.PadRight(len, '\0');
byte[] codeBytes = encoding.GetBytes(data);
CopyTo(codeBytes, memoryOwner.Memory.Span, offset);
Array.Copy(codeBytes, 0, bytes, offset, codeBytes.Length);
return codeBytes.Length;
}
}


+ 1
- 1
src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs View File

@@ -7,6 +7,6 @@ namespace JT809.Protocol.JT809Formatters
{
T Deserialize(ReadOnlySpan<byte> bytes, out int readSize);

int Serialize(IMemoryOwner<byte> memoryOwner, int offset, T value);
int Serialize(ref byte[] bytes, int offset, T value);
}
}

+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs View File

@@ -38,11 +38,11 @@ namespace JT809.Protocol.JT809Formatters
return jT809Bodies;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, TJT809Bodies value)
public int Serialize(ref byte[] bytes, int offset, TJT809Bodies value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.VehicleNo, 21);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.VehicleColor);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.SubBusinessType);
//JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性
JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute<JT809BodiesTypeAttribute>();
if (jT809SubBodiesTypeAttribute == null)
@@ -53,8 +53,8 @@ namespace JT809.Protocol.JT809Formatters
{
// 先写入内容,然后在根据内容反写内容长度
offset = offset + 4;
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset- offset));
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), ref bytes, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(bytes, offset - 4, (uint)(contentOffset- offset));
offset = contentOffset;
}
catch


+ 8
- 8
src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs View File

@@ -24,15 +24,15 @@ namespace JT809.Protocol.JT809Formatters
return jT809Header;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809Header value)
public int Serialize(ref byte[] bytes, int offset, JT809Header value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgLength);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgSN);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.BusinessType);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgGNSSCENTERID);
offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Version.Buffer);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.EncryptFlag);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.EncryptKey);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.MsgLength);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.MsgSN);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.BusinessType);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.MsgGNSSCENTERID);
offset += JT809BinaryExtensions.WriteBytesLittle(bytes, offset, value.Version.Buffer);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.EncryptFlag);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.EncryptKey);
return offset;
}
}


+ 5
- 5
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs View File

@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1001;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1001 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1001 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.UserId);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.Password,8);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.DownLinkIP,32);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.DownLinkPort);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.UserId);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.Password,8);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.DownLinkIP,32);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.DownLinkPort);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs View File

@@ -20,10 +20,10 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1002;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1002 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1002 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VerifyCode);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs View File

@@ -20,10 +20,10 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1003;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1003 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1003 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.UserId);
offset += JT809BinaryExtensions.WriteStringPadLeftLittle(memoryOwner, offset, value.Password,8);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.UserId);
offset += JT809BinaryExtensions.WriteStringPadLeftLittle(bytes, offset, value.Password,8);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1007;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1007 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1007 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ErrorCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ErrorCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1008;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1008 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1008 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ReasonCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ReasonCode);
return offset;
}
}


+ 4
- 4
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs View File

@@ -36,9 +36,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1300;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1300 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1300 value)
{
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.SubBusinessType);
//offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength);
//JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性
JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute<JT809BodiesTypeAttribute>();
@@ -50,8 +50,8 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
{
// 先写入内容,然后在根据内容反写内容长度
offset = offset + 4;
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset - offset));
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType),ref bytes, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(bytes, offset - 4, (uint)(contentOffset - offset));
offset = contentOffset;
}
catch


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9001;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9001 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9001 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VerifyCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9002;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9002 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9002 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9003;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9003 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9003 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VerifyCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9007;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9007 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9007 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte)value.ReasonCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte)value.ReasonCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9008;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9008 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9008 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ReasonCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ReasonCode);
return offset;
}
}


+ 4
- 4
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs View File

@@ -20,11 +20,11 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9101;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9101 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9101 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DynamicInfoTotal);
offset += JT809BinaryExtensions.WriteUInt64Little(memoryOwner, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUInt64Little(memoryOwner, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.DynamicInfoTotal);
offset += JT809BinaryExtensions.WriteUInt64Little(bytes, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUInt64Little(bytes, offset, value.EndTime);
return offset;
}
}


+ 4
- 4
src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs View File

@@ -36,9 +36,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9300;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9300 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9300 value)
{
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.SubBusinessType);
//offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength);
//JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性
JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute<JT809BodiesTypeAttribute>();
@@ -50,8 +50,8 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
{
// 先写入内容,然后在根据内容反写内容长度
offset = offset + 4;
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset - offset));
int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType),ref bytes, offset, value.SubBodies);
JT809BinaryExtensions.WriteUInt32Little(bytes, offset - 4, (uint)(contentOffset - offset));
offset = contentOffset;
}
catch


+ 10
- 11
src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs View File

@@ -81,7 +81,7 @@ namespace JT809.Protocol.JT809Formatters
return jT809Package;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809Package value)
public int Serialize(ref byte[] bytes, int offset, JT809Package value)
{
// 1. 先序列化数据体,根据数据体的长度赋值给头部,在序列化头部。
int messageBodyOffset = 0;
@@ -91,13 +91,13 @@ namespace JT809.Protocol.JT809Formatters
if (value.Bodies != null)
{
// 1.1 处理数据体
messageBodyOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), memoryOwner, messageBodyOffset, value.Bodies);
messageBodyOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), ref bytes, messageBodyOffset, value.Bodies);
}
}
byte[] messageBodyData=null;
if (messageBodyOffset != 0)
{
messageBodyData = memoryOwner.Memory.Slice(0, messageBodyOffset).Span.ToArray();
messageBodyData = bytes.AsSpan(0, messageBodyOffset).ToArray();
// 1.2 数据加密
switch (value.Header.EncryptFlag)
{
@@ -110,7 +110,7 @@ namespace JT809.Protocol.JT809Formatters
}
// ------------------------------------开始组包
// 1.起始符
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.BeginFlag);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.BeginFlag);
// 2.赋值头数据长度
if (messageBodyOffset != 0)
{
@@ -121,22 +121,21 @@ namespace JT809.Protocol.JT809Formatters
value.Header.MsgLength = JT809Package.FixedByteLength;
}
// 2.1写入头部数据
offset = JT809FormatterExtensions.GetFormatter<JT809Header>().Serialize(memoryOwner, offset, value.Header);
offset = JT809FormatterExtensions.GetFormatter<JT809Header>().Serialize(ref bytes, offset, value.Header);
if (messageBodyOffset != 0)
{
// 3. 写入数据体
JT809BinaryExtensions.CopyTo(messageBodyData, memoryOwner.Memory.Span, offset);
Array.Copy(messageBodyData, 0, bytes, offset, messageBodyData.Length);
offset += messageBodyData.Length;
messageBodyData = null;
}
// 4.校验码
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, memoryOwner.Memory.Span.ToCRC16_CCITT(1, offset));
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, bytes.ToCRC16_CCITT(1, offset));
// 5.终止符
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.EndFlag);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.EndFlag);
// 6.转义
byte[] temp = JT809Escape(memoryOwner.Memory.Slice(0, offset).Span);
memoryOwner.Memory.Span.Clear();
JT809BinaryExtensions.CopyTo(temp, memoryOwner.Memory.Span, 0);
byte[] temp = JT809Escape(bytes.AsSpan(0, offset));
Array.Copy(temp, 0, bytes, 0, temp.Length);
return temp.Length;
}



+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs View File

@@ -24,13 +24,13 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1201;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x1201 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x1201 value)
{
offset += JT809BinaryExtensions.WriteBigNumberLittle(memoryOwner, offset, value.PlateformId,11);
offset += JT809BinaryExtensions.WriteBigNumberLittle(memoryOwner, offset, value.ProducerId, 11);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.TerminalModelType, 20);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.TerminalId.ToUpper(), 7);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.TerminalSimCode, 12);
offset += JT809BinaryExtensions.WriteBigNumberLittle(bytes, offset, value.PlateformId,11);
offset += JT809BinaryExtensions.WriteBigNumberLittle(bytes, offset, value.ProducerId, 11);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.TerminalModelType, 20);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.TerminalId.ToUpper(), 7);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.TerminalSimCode, 12);
return offset;
}
}


+ 17
- 17
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs View File

@@ -34,24 +34,24 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1202;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x1202 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x1202 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte) value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Alarm);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte) value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Alarm);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs View File

@@ -50,14 +50,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1203;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x1203 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x1203 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.GNSS.Count);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.GNSS.Count);
foreach(var item in value.GNSS)
{
try
{
int positionOffset = JT809FormatterExtensions.GetFormatter<JT809_0x1200_0x1202>().Serialize(memoryOwner, offset, item);
int positionOffset = JT809FormatterExtensions.GetFormatter<JT809_0x1200_0x1202>().Serialize(ref bytes, offset, item);
offset = positionOffset;
}
catch (Exception ex)


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1207;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x1207 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x1207 value)
{
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.EndTime);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1207;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x1209 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x1209 value)
{
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.EndTime);
return offset;
}
}


+ 5
- 5
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs View File

@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120A;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x120A value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x120A value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.DriverName,16);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.DriverID,20);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Licence, 40);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.OrgName, 200);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.DriverName,16);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.DriverID,20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.Licence, 40);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.OrgName, 200);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120B;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x120B value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x120B value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, (uint)value.EwaybillInfo.Length);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.EwaybillInfo);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, (uint)value.EwaybillInfo.Length);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.EwaybillInfo);
return offset;
}
}


+ 5
- 5
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs View File

@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120C;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x120C value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x120C value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.DriverName, 16);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.DriverID, 20);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Licence, 40);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.OrgName, 200);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.DriverName, 16);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.DriverID, 20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.Licence, 40);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.OrgName, 200);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120D;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1200_0x120D value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1200_0x120D value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, (uint)value.EwaybillInfo.Length);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.EwaybillInfo);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, (uint)value.EwaybillInfo.Length);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.EwaybillInfo);
return offset;
}
}


+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs View File

@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1301;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1300_0x1301 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1300_0x1301 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1302;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1300_0x1302 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1300_0x1302 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1401;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1400_0x1401 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1400_0x1401 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.SupervisionID);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte)value.Result);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.SupervisionID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte)value.Result);
return offset;
}
}


+ 7
- 7
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs View File

@@ -23,16 +23,16 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1402;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1400_0x1402 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1400_0x1402 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset,(ushort)value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset,(ushort)value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1403;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1400_0x1403 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1400_0x1403 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1501;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1500_0x1501 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1500_0x1501 value)
{
offset+= JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset+= JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 23
- 23
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs View File

@@ -43,33 +43,33 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1502;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1500_0x1502 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1500_0x1502 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.PhotoRspFlag);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Alarm);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.LensID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.PhotoRspFlag);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Alarm);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.LensID);
bool isPhoto = (value.Photo != null && value.Photo.Length > 0);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, isPhoto ? (uint)value.Photo.Length : 0);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SizeType);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.Type);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, isPhoto ? (uint)value.Photo.Length : 0);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.SizeType);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.Type);
if (isPhoto)
{
offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Photo);
offset += JT809BinaryExtensions.WriteBytesLittle(bytes, offset, value.Photo);
}
return offset;
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1503;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1500_0x1503 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1500_0x1503 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgID);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.MsgID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 4
- 4
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs View File

@@ -21,13 +21,13 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1504;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1500_0x1504 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1500_0x1504 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.CommandType);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.CommandType);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.TraveldataInfo);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.TraveldataInfo);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1505;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1500_0x1505 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1500_0x1505 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte)value.Result);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte)value.Result);
return offset;
}
}


+ 17
- 17
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs View File

@@ -34,24 +34,24 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9202;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9202 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9202 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte) value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Alarm);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte) value.VehiclePosition.Encrypt);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Day);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Month);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Year);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Hour);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Minute);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.VehiclePosition.Second);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lon);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Lat);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec1);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Vec2);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Vec3);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Direction);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.VehiclePosition.Altitude);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.State);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.VehiclePosition.Alarm);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs View File

@@ -50,14 +50,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9203;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9203 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9203 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.GNSS.Count);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.GNSS.Count);
foreach(var item in value.GNSS)
{
try
{
int positionOffset = JT809FormatterExtensions.GetFormatter<JT809_0x9200_0x9202>().Serialize(memoryOwner, offset, item);
int positionOffset = JT809FormatterExtensions.GetFormatter<JT809_0x9200_0x9202>().Serialize(ref bytes, offset, item);
offset = positionOffset;
}
catch (Exception ex)


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9204;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9204 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9204 value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.CarInfo);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.CarInfo);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9205;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9205 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9205 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset,(byte)value.ReasonCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset,(byte)value.ReasonCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9206;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9206 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9206 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ReasonCode);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ReasonCode);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9207;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9207 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9207 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9208;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9208 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9208 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs View File

@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9209;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9200_0x9209 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9200_0x9209 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Result);
return offset;
}
}


+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs View File

@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9300_0X9301;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9300_0x9301 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9300_0x9301 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs View File

@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9300_0X9302;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9300_0x9302 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9300_0x9302 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.ObjectType);
offset += JT809BinaryExtensions.WriteStringPadRightLittle(bytes, offset, value.ObjectID, 12);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.InfoID);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.InfoContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 10
- 10
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs View File

@@ -26,17 +26,17 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9401;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9400_0x9401 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9400_0x9401 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteHexStringLittle(memoryOwner, offset, value.SupervisionID,4);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.SupervisionEndTime);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SupervisionLevel);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Supervisor,16);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.SupervisorTel,20);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.SupervisorEmail,32);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, (ushort)value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteHexStringLittle(bytes, offset, value.SupervisionID,4);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.SupervisionEndTime);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.SupervisionLevel);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.Supervisor,16);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.SupervisorTel,20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.SupervisorEmail,32);
return offset;
}
}


+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs View File

@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9402;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9400_0x9402 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9400_0x9402 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.WarnTime);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.WarnContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.WarnContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 6
- 6
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs View File

@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9403;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9400_0x9403 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9400_0x9403 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.WarnSrc);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.WarnType);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.WarnTime);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.WarnContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.WarnContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9501;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9501 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9500_0x9501 value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.MonitorTel,20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.MonitorTel,20);
return offset;
}
}


+ 3
- 3
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs View File

@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9502;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9502 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9500_0x9502 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.LensID);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SizeType);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.LensID);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.SizeType);
return offset;
}
}


+ 5
- 5
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs View File

@@ -21,14 +21,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9503;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9503 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9500_0x9503 value)
{
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgSequence);
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.MsgPriority);
offset += JT809BinaryExtensions.WriteUInt32Little(bytes, offset, value.MsgSequence);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, value.MsgPriority);
// 先计算内容长度(汉字为两个字节)
offset += 4;
int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.MsgContent);
JT809BinaryExtensions.WriteInt32Little(memoryOwner, offset - 4, byteLength);
int byteLength = JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.MsgContent);
JT809BinaryExtensions.WriteInt32Little(bytes, offset - 4, byteLength);
offset += byteLength;
return offset;
}


+ 5
- 5
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs View File

@@ -42,9 +42,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9504;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9504 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9500_0x9504 value)
{
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Command);
offset += JT809BinaryExtensions.WriteByteLittle(bytes, offset, (byte)value.Command);
switch (value.Command)
{
case JT809Enums.JT809CommandType.记录仪标准版本:
@@ -64,9 +64,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
case JT809Enums.JT809CommandType.采集记录仪外部供电记录:
case JT809Enums.JT809CommandType.采集记录仪参数修改记录:
case JT809Enums.JT809CommandType.采集记录仪速度状态日志:
offset += JT809BinaryExtensions.WriteDateTime6Little(memoryOwner, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteDateTime6Little(memoryOwner, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.Max);
offset += JT809BinaryExtensions.WriteDateTime6Little(bytes, offset, value.StartTime);
offset += JT809BinaryExtensions.WriteDateTime6Little(bytes, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.Max);
break;
}
return offset;


+ 9
- 9
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs View File

@@ -25,16 +25,16 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9505;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9505 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x9500_0x9505 value)
{
offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,20);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.AccessPointName,20);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.UserName, 49);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Password, 22);
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.ServerIP, 32);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.TcpPort);
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.UdpPort);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.EndTime);
offset += JT809BinaryExtensions.WriteBCDLittle(bytes, offset, value.AuthenticationCode,20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.AccessPointName,20);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.UserName, 49);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.Password, 22);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.ServerIP, 32);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.TcpPort);
offset += JT809BinaryExtensions.WriteUInt16Little(bytes, offset, value.UdpPort);
offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(bytes, offset, value.EndTime);
return offset;
}
}


+ 2
- 2
src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs View File

@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9600_0X1601;
}

public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1600_0x1601 value)
public int Serialize(ref byte[] bytes, int offset, JT809_0x1600_0x1601 value)
{
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.CarInfo);
offset += JT809BinaryExtensions.WriteStringLittle(bytes, offset, value.CarInfo);
return offset;
}
}


+ 11
- 14
src/JT809.Protocol/JT809Serializer.cs View File

@@ -1,6 +1,4 @@
using JT809.Protocol.JT809Enums;
using JT809.Protocol.JT809Exceptions;
using JT809.Protocol.JT809Extensions;
using JT809.Protocol.JT809Extensions;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -8,9 +6,13 @@ using System.Text;

namespace JT809.Protocol
{
/// <summary>
///
/// ref:https://adamsitnik.com/Array-Pool/
/// </summary>
public static class JT809Serializer
{
public static byte[] Serialize(JT809Package jT809Package, int minBufferSize = 4096)
public static byte[] Serialize(JT809Package jT809Package, int minBufferSize = 1024)
{
return Serialize<JT809Package>(jT809Package, minBufferSize);
}
@@ -20,23 +22,18 @@ namespace JT809.Protocol
return Deserialize<JT809Package>(bytes);
}

public static byte[] Serialize<T>(T obj, int minBufferSize = 4096)
public static byte[] Serialize<T>(T obj, int minBufferSize = 1024)
{
var formatter = JT809FormatterExtensions.GetFormatter<T>();
var pool = MemoryPool<byte>.Shared;
IMemoryOwner<byte> buffer = pool.Rent(minBufferSize);
byte[] buffer = JT809ArrayPool.Rent(minBufferSize);
try
{
var len = formatter.Serialize(buffer, 0, obj);
return buffer.Memory.Slice(0, len).ToArray();
var len = formatter.Serialize(ref buffer, 0, obj);
return buffer.AsSpan(0, len).ToArray();
}
finally
{
// 源码:System.Memory.MemoryPool
// private static readonly MemoryPool<T> s_shared = new ArrayMemoryPool<T>();
// 单例内存池 不需要手动释放资源
// buffer.Dispose() 相当于调用ArrayPool<T>.Shared.Return(array)
buffer.Dispose();
JT809ArrayPool.Return(buffer);
}
}



Loading…
Cancel
Save