From 86589bb9b26c5a36a91a09b5db688fdd64cdf8dc Mon Sep 17 00:00:00 2001
From: SmallChi <564952747@qq.com>
Date: Fri, 2 Nov 2018 14:05:23 +0800
Subject: [PATCH] =?UTF-8?q?1.=E8=B0=83=E6=95=B4=E4=B8=BAbyte=E6=95=B0?=
=?UTF-8?q?=E7=BB=84=E7=B1=BB=E5=9E=8B=202.=E5=A2=9E=E5=8A=A0byte=E5=AF=B9?=
=?UTF-8?q?=E8=B1=A1=E6=B1=A0=E7=9A=84=E4=BD=BF=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/JT809.Protocol/JT809.Protocol.csproj | 3 +-
src/JT809.Protocol/JT809ArrayPool.cs | 27 +++++++++
.../JT809Extensions/JT809BCDExtensions.cs | 5 +-
.../JT809Extensions/JT809BinaryExtensions.cs | 60 +++++++++----------
.../JT809Extensions/JT809CRCExtensions.cs | 2 +-
.../JT809DateTimeExtensions.cs | 26 ++++----
.../JT809FormatterResolverExtensions.cs | 10 ++--
.../JT809Extensions/JT809HexExtensions.cs | 4 +-
.../JT809Extensions/JT809StringExtensions.cs | 26 ++++----
.../JT809Formatters/IJT809FormatterOfT.cs | 2 +-
.../JT809Formatters/JT809BodiesFormatter.cs | 12 ++--
.../JT809Formatters/JT809HeaderFormatter.cs | 16 ++---
.../JT809_0x1001Formatter.cs | 10 ++--
.../JT809_0x1002Formatter.cs | 6 +-
.../JT809_0x1003Formatter.cs | 6 +-
.../JT809_0x1007Formatter.cs | 4 +-
.../JT809_0x1008Formatter.cs | 4 +-
.../JT809_0x1300Formatter.cs | 8 +--
.../JT809_0x9001Formatter.cs | 4 +-
.../JT809_0x9002Formatter.cs | 4 +-
.../JT809_0x9003Formatter.cs | 4 +-
.../JT809_0x9007Formatter.cs | 4 +-
.../JT809_0x9008Formatter.cs | 4 +-
.../JT809_0x9101Formatter.cs | 8 +--
.../JT809_0x9300Formatter.cs | 8 +--
.../JT809Formatters/JT809PackageFormatter.cs | 21 ++++---
.../JT809_0x1200_0x1201Formatter.cs | 12 ++--
.../JT809_0x1200_0x1202Formatter.cs | 34 +++++------
.../JT809_0x1200_0x1203Formatter.cs | 6 +-
.../JT809_0x1200_0x1207Formatter.cs | 6 +-
.../JT809_0x1200_0x1209Formatter.cs | 6 +-
.../JT809_0x1200_0x120AFormatter.cs | 10 ++--
.../JT809_0x1200_0x120BFormatter.cs | 6 +-
.../JT809_0x1200_0x120CFormatter.cs | 10 ++--
.../JT809_0x1200_0x120DFormatter.cs | 6 +-
.../JT809_0x1300_0x1301Formatter.cs | 12 ++--
.../JT809_0x1300_0x1302Formatter.cs | 4 +-
.../JT809_0x1400_0x1401Formatter.cs | 6 +-
.../JT809_0x1400_0x1402Formatter.cs | 14 ++---
.../JT809_0x1400_0x1403Formatter.cs | 6 +-
.../JT809_0x1500_0x1501Formatter.cs | 4 +-
.../JT809_0x1500_0x1502Formatter.cs | 46 +++++++-------
.../JT809_0x1500_0x1503Formatter.cs | 6 +-
.../JT809_0x1500_0x1504Formatter.cs | 8 +--
.../JT809_0x1500_0x1505Formatter.cs | 4 +-
.../JT809_0x9200_0x9202Formatter.cs | 34 +++++------
.../JT809_0x9200_0x9203Formatter.cs | 6 +-
.../JT809_0x9200_0x9204Formatter.cs | 4 +-
.../JT809_0x9200_0x9205Formatter.cs | 4 +-
.../JT809_0x9200_0x9206Formatter.cs | 4 +-
.../JT809_0x9200_0x9207Formatter.cs | 4 +-
.../JT809_0x9200_0x9208Formatter.cs | 4 +-
.../JT809_0x9200_0x9209Formatter.cs | 4 +-
.../JT809_0x9300_0x9301Formatter.cs | 12 ++--
.../JT809_0x9300_0x9302Formatter.cs | 12 ++--
.../JT809_0x9400_0x9401Formatter.cs | 20 +++----
.../JT809_0x9400_0x9402Formatter.cs | 12 ++--
.../JT809_0x9400_0x9403Formatter.cs | 12 ++--
.../JT809_0x9500_0x9501Formatter.cs | 4 +-
.../JT809_0x9500_0x9502Formatter.cs | 6 +-
.../JT809_0x9500_0x9503Formatter.cs | 10 ++--
.../JT809_0x9500_0x9504Formatter.cs | 10 ++--
.../JT809_0x9500_0x9505Formatter.cs | 18 +++---
.../JT809_0x9600_0x1601Formatter.cs | 4 +-
src/JT809.Protocol/JT809Serializer.cs | 25 ++++----
65 files changed, 363 insertions(+), 340 deletions(-)
create mode 100644 src/JT809.Protocol/JT809ArrayPool.cs
diff --git a/src/JT809.Protocol/JT809.Protocol.csproj b/src/JT809.Protocol/JT809.Protocol.csproj
index 9aed2ce..715e829 100644
--- a/src/JT809.Protocol/JT809.Protocol.csproj
+++ b/src/JT809.Protocol/JT809.Protocol.csproj
@@ -14,7 +14,7 @@
https://github.com/SmallChi/JT809
https://github.com/SmallChi/JT809/blob/master/LICENSE
true
- 1.0.6
+ 1.0.7
@@ -89,6 +89,7 @@
+
diff --git a/src/JT809.Protocol/JT809ArrayPool.cs b/src/JT809.Protocol/JT809ArrayPool.cs
new file mode 100644
index 0000000..e7f7085
--- /dev/null
+++ b/src/JT809.Protocol/JT809ArrayPool.cs
@@ -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 ArrayPool;
+
+ static JT809ArrayPool()
+ {
+ ArrayPool = ArrayPool.Create();
+ }
+
+ public static byte[] Rent(int minimumLength)
+ {
+ return ArrayPool.Rent(minimumLength);
+ }
+
+ public static void Return(byte[] array, bool clearArray = false)
+ {
+ ArrayPool.Return(array, clearArray);
+ }
+ }
+}
diff --git a/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs
index 9013f31..d3f1af7 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs
@@ -19,10 +19,9 @@ namespace JT809.Protocol.JT809Extensions
return bcdSb.ToString();
}
- public static int WriteBCDLittle(IMemoryOwner 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++;
}
diff --git a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs
index dccd1a6..1edb330 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs
@@ -104,53 +104,53 @@ namespace JT809.Protocol.JT809Extensions
return result.ToString();
}
- public static int WriteInt32Little(IMemoryOwner 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 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 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 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 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 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
///
///
///
- public static int WriteBigNumberLittle(IMemoryOwner 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
///
///
///
- public static int WriteLowNumberLittle(IMemoryOwner 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;
diff --git a/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs
index 49f68df..c395814 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs
@@ -13,7 +13,7 @@ namespace JT809.Protocol.JT809Extensions
///
///
///
- public static ushort ToCRC16_CCITT(this Span 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)
diff --git a/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs
index 2dd0927..6679a3c 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs
@@ -79,13 +79,13 @@ namespace JT809.Protocol.JT809Extensions
return UTCBaseTime.AddSeconds(result).AddHours(8);
}
- public static int WriteUTCDateTimeLittle(IMemoryOwner 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
///
/// BCD:10 HEX:16
///
- public static int WriteDateTime6Little(IMemoryOwner 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
///
/// BCD:10 HEX:16
///
- public static int WriteDateTime4Little(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs
index 96cf1c3..0046240 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809FormatterResolverExtensions.cs
@@ -17,7 +17,7 @@ namespace JT809.Protocol.JT809Extensions
///
public static class JT809FormatterResolverExtensions
{
- delegate int JT809SerializeMethod(object dynamicFormatter, IMemoryOwner memoryOwner, int offset, object value);
+ delegate int JT809SerializeMethod(object dynamicFormatter, ref byte[] bytes, int offset, object value);
delegate dynamic JT809DeserializeMethod(object dynamicFormatter, ReadOnlySpan bytes, out int readSize);
@@ -28,7 +28,7 @@ namespace JT809.Protocol.JT809Extensions
//T Deserialize(ReadOnlySpan bytes, out int readSize);
//int Serialize(IMemoryOwner memoryOwner, int offset, T value);
- public static int JT809DynamicSerialize(object objFormatter, IMemoryOwner 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), "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), 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 bytes, out int readSize)
diff --git a/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs
index 482f60c..f39ae64 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs
@@ -83,7 +83,7 @@ namespace JT809.Protocol.JT809Extensions
return ToHexString(source, false);
}
- public static int WriteHexStringLittle(IMemoryOwner 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++;
}
diff --git a/src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs
index caea63f..693c0ba 100644
--- a/src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs
+++ b/src/JT809.Protocol/JT809Extensions/JT809StringExtensions.cs
@@ -23,47 +23,47 @@ namespace JT809.Protocol.JT809Extensions
return value.Trim('\0');
}
- public static int WriteStringLittle(IMemoryOwner 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 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 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 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs b/src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs
index 11c45fd..3d0caba 100644
--- a/src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs
+++ b/src/JT809.Protocol/JT809Formatters/IJT809FormatterOfT.cs
@@ -7,6 +7,6 @@ namespace JT809.Protocol.JT809Formatters
{
T Deserialize(ReadOnlySpan bytes, out int readSize);
- int Serialize(IMemoryOwner memoryOwner, int offset, T value);
+ int Serialize(ref byte[] bytes, int offset, T value);
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs
index b65bf9e..7ad1ec3 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs
@@ -38,11 +38,11 @@ namespace JT809.Protocol.JT809Formatters
return jT809Bodies;
}
- public int Serialize(IMemoryOwner 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();
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
diff --git a/src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs
index 0926234..1256ef3 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809HeaderFormatter.cs
@@ -24,15 +24,15 @@ namespace JT809.Protocol.JT809Formatters
return jT809Header;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs
index 800c6cb..618c6b9 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1001Formatter.cs
@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1001;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs
index 59a1da3..7aa3353 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1002Formatter.cs
@@ -20,10 +20,10 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1002;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs
index 6443356..00c12ff 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1003Formatter.cs
@@ -20,10 +20,10 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1003;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs
index 4f1f836..50e00da 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1007Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1007;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs
index 7a77ff0..eee656c 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1008Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1008;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs
index e552469..e49925b 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs
@@ -36,9 +36,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X1300;
}
- public int Serialize(IMemoryOwner 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();
@@ -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
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs
index 75d5f37..f648e76 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9001Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9001;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs
index 926faa6..40c813c 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9002Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9002;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs
index 7a1830a..a6a4fcc 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9003Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9003;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs
index fb36a01..0305a33 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9007Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9007;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs
index 919c883..b38a750 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9008Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9008;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs
index aa7a42d..b2aeb36 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9101Formatter.cs
@@ -20,11 +20,11 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9101;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs
index 35e10df..f7eac93 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs
@@ -36,9 +36,9 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters
return jT809_0X9300;
}
- public int Serialize(IMemoryOwner 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();
@@ -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
diff --git a/src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs
index 83b2dc1..6b49f2a 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809PackageFormatter.cs
@@ -81,7 +81,7 @@ namespace JT809.Protocol.JT809Formatters
return jT809Package;
}
- public int Serialize(IMemoryOwner 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().Serialize(memoryOwner, offset, value.Header);
+ offset = JT809FormatterExtensions.GetFormatter().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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs
index 37d0d8c..0a8526d 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1201Formatter.cs
@@ -24,13 +24,13 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1201;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs
index 5b2e7db..741251c 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1202Formatter.cs
@@ -34,24 +34,24 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1202;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs
index f0a1048..3bbf25d 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1203Formatter.cs
@@ -50,14 +50,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1203;
}
- public int Serialize(IMemoryOwner 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().Serialize(memoryOwner, offset, item);
+ int positionOffset = JT809FormatterExtensions.GetFormatter().Serialize(ref bytes, offset, item);
offset = positionOffset;
}
catch (Exception ex)
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs
index 2c489c0..f444471 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1207Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1207;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs
index 4286f10..eb4aefa 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x1209Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1207;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs
index c4f0218..7137ec0 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120AFormatter.cs
@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120A;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs
index 80ad93a..35eb9d7 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120BFormatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120B;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs
index fc3f86a..8a5aa0c 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120CFormatter.cs
@@ -21,12 +21,12 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120C;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs
index 493b2cb..b508cae 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1200_0x120DFormatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X120D;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs
index dedf0c8..a147a4e 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1301Formatter.cs
@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1301;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs
index 639e076..67309af 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1300_0x1302Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0X1302;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs
index 9349d11..96d57ce 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1401Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1401;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs
index 30a1ec2..0740c11 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs
@@ -23,16 +23,16 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1402;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs
index 9cf7ec2..e94a035 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1403Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1400_0X1403;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs
index 83602d2..98e8e62 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1501Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1501;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs
index 817f4f2..7330e22 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs
@@ -43,33 +43,33 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1502;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs
index 6e47bd3..30b74f3 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1503Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1503;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs
index 991cd74..34b78a1 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs
@@ -21,13 +21,13 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1504;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs
index 4121469..a2e8853 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1505Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1500_0X1505;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs
index ddbfdfd..8d993b7 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9202Formatter.cs
@@ -34,24 +34,24 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9202;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs
index 371bc46..571fbec 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9203Formatter.cs
@@ -50,14 +50,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9203;
}
- public int Serialize(IMemoryOwner 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().Serialize(memoryOwner, offset, item);
+ int positionOffset = JT809FormatterExtensions.GetFormatter().Serialize(ref bytes, offset, item);
offset = positionOffset;
}
catch (Exception ex)
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs
index ddc3515..3049eeb 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9204Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9204;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs
index 0688d4c..49a994a 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9205Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9205;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs
index c719d0f..93a51fa 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9206Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9206;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs
index 829255c..2817666 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9207Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9207;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs
index f5b4001..f1958e1 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9208Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9208;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs
index c3cbcbc..59bb74d 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9200_0x9209Formatter.cs
@@ -19,9 +19,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X1200_0x9209;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs
index 03d025f..c3e6efe 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9301Formatter.cs
@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9300_0X9301;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs
index 2da3210..d4716f0 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9300_0x9302Formatter.cs
@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9300_0X9302;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs
index fc472ae..34f2cfd 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs
@@ -26,17 +26,17 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9401;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs
index 3f12841..12b0c30 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9402Formatter.cs
@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9402;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs
index d3172aa..b91c01a 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9403Formatter.cs
@@ -22,15 +22,15 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9400_0X9403;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs
index 5253afb..3eaf7d1 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9501Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9501;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs
index 355c5ee..6eaa0d9 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9502Formatter.cs
@@ -19,10 +19,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9502;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs
index 3e01be1..f1b0c23 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9503Formatter.cs
@@ -21,14 +21,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9503;
}
- public int Serialize(IMemoryOwner 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;
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs
index b73c166..849c24d 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs
@@ -42,9 +42,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9504;
}
- public int Serialize(IMemoryOwner 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;
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs
index 7ffab0c..c541410 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs
@@ -25,16 +25,16 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9500_0X9505;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs
index c6a305b..0919527 100644
--- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs
+++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9600_0x1601Formatter.cs
@@ -18,9 +18,9 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters
return jT809_0X9600_0X1601;
}
- public int Serialize(IMemoryOwner 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;
}
}
diff --git a/src/JT809.Protocol/JT809Serializer.cs b/src/JT809.Protocol/JT809Serializer.cs
index c78c51d..81a1328 100644
--- a/src/JT809.Protocol/JT809Serializer.cs
+++ b/src/JT809.Protocol/JT809Serializer.cs
@@ -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
{
+ ///
+ ///
+ /// ref:https://adamsitnik.com/Array-Pool/
+ ///
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, minBufferSize);
}
@@ -20,23 +22,18 @@ namespace JT809.Protocol
return Deserialize(bytes);
}
- public static byte[] Serialize(T obj, int minBufferSize = 4096)
+ public static byte[] Serialize(T obj, int minBufferSize = 1024)
{
var formatter = JT809FormatterExtensions.GetFormatter();
- var pool = MemoryPool.Shared;
- IMemoryOwner 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 s_shared = new ArrayMemoryPool();
- // 单例内存池 不需要手动释放资源
- // buffer.Dispose() 相当于调用ArrayPool.Shared.Return(array)
- buffer.Dispose();
+ JT809ArrayPool.Return(buffer);
}
}