/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="type"></param> /// <param name="version"></param> /// <returns></returns> public dynamic Deserialize(ReadOnlySpan <byte> bytes, Type type, JT808Version version = JT808Version.JTT2013) { var formatter = jT808Config.GetMessagePackFormatterByType(type); JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); return(JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(formatter, ref jT808MessagePackReader, jT808Config)); }
public byte[] AnalyzeJsonBuffer <T>(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default, int minBufferSize = 8096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); if (CheckPackageType(typeof(T))) { jT808MessagePackReader.Decode(buffer); } var analyze = jT808Config.GetAnalyze <T>(); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { if (!CheckPackageType(typeof(T))) { utf8JsonWriter.WriteStartObject(); } analyze.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); if (!CheckPackageType(typeof(T))) { utf8JsonWriter.WriteEndObject(); } utf8JsonWriter.Flush(); return(memoryStream.ToArray()); } } finally { JT808ArrayPool.Return(buffer); } }
/// <summary> /// 用于分包组合 /// </summary> /// <param name="msgid">对应消息id</param> /// <param name="bytes">组合的数据体</param> /// <param name="version">对应版本号</param> /// <param name="options">序列化选项</param> /// <param name="minBufferSize">默认65535</param> /// <returns></returns> public byte[] AnalyzeJsonBuffer(ushort msgid, ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default, int minBufferSize = 65535) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { if (jT808Config.MsgIdFactory.TryGetValue(msgid, out object msgHandle)) { if (jT808Config.FormatterFactory.FormatterDict.TryGetValue(msgHandle.GetType().GUID, out object instance)) { using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); utf8JsonWriter.WriteStartObject(); instance.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.WriteEndObject(); utf8JsonWriter.Flush(); return(memoryStream.ToArray()); } } return(Encoding.UTF8.GetBytes($"未找到对应的0x{msgid.ToString("X2")}消息数据体类型")); } return(Encoding.UTF8.GetBytes($"未找到对应的0x{msgid.ToString("X2")}消息数据体类型")); } finally { JT808ArrayPool.Return(buffer); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bytes"></param> /// <param name="version"></param> /// <returns></returns> public T Deserialize <T>(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); var formatter = jT808Config.GetMessagePackFormatter <T>(); return(formatter.Deserialize(ref jT808MessagePackReader, jT808Config)); }
public JT808DeviceConfig(string terminalPhoneNo, string tcpHost, int tcpPort, JT808Version version = JT808Version.JTT2013) { TerminalPhoneNo = terminalPhoneNo; TcpHost = tcpHost; TcpPort = tcpPort; Version = version; }
public static void Send(this JT808TcpClient client, JT808Package package, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { package.Header.TerminalPhoneNo = client.DeviceConfig.TerminalPhoneNo; JT808ClientRequest request = new JT808ClientRequest(package, version, minBufferSize); client.Send(request); }
public JT808DeviceConfig(string terminalPhoneNo, string tcpHost, int tcpPort, string localIPAddress = null, int localPort = 0, JT808Version version = JT808Version.JTT2013) { TerminalPhoneNo = terminalPhoneNo; TcpHost = tcpHost; TcpPort = tcpPort; Version = version; LocalIPAddress = localIPAddress; LocalPort = localPort; }
/// <summary> /// 解码(转义还原),计算校验和 /// </summary> /// <param name="buffer"></param> public JT808MessagePackReader(ReadOnlySpan <byte> srcBuffer, JT808Version version = JT808Version.JTT2013) { SrcBuffer = srcBuffer; ReaderCount = 0; _realCheckXorCode = 0x00; _calculateCheckXorCode = 0x00; _checkXorCodeVali = false; _decoded = false; Version = version; Reader = srcBuffer; }
public byte[] DownAnalyzeJsonBuffer(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { JT808CarDVRDownPackage.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.Flush(); return(memoryStream.ToArray()); } }
public string UpAnalyze(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { JT808CarDVRUpPackage.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.Flush(); string value = Encoding.UTF8.GetString(memoryStream.ToArray()); return(value); } }
public JT808Package Deserialize(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); jT808MessagePackReader.Decode(buffer); return(jT808Package.Deserialize(ref jT808MessagePackReader, jT808Config)); } finally { JT808ArrayPool.Return(buffer); } }
public ReadOnlySpan <byte> SerializeReadOnlySpan(JT808Package package, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackWriter jT808MessagePackWriter = new JT808MessagePackWriter(buffer, version); jT808Package.Serialize(ref jT808MessagePackWriter, package, jT808Config); return(jT808MessagePackWriter.FlushAndGetEncodingReadOnlySpan()); } finally { JT808ArrayPool.Return(buffer); } }
/// <summary> /// /// </summary> /// <param name="package"></param> /// <param name="version"></param> /// <param name="minBufferSize"></param> /// <returns></returns> public byte[] Serialize(JT808CarDVRDownPackage package, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackWriter jT808MessagePackWriter = new JT808MessagePackWriter(buffer, version); package.Serialize(ref jT808MessagePackWriter, package, jT808Config); return(jT808MessagePackWriter.FlushAndGetEncodingArray()); } finally { JT808ArrayPool.Return(buffer); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bytes"></param> /// <param name="version"></param> /// <param name="options"></param> /// <returns></returns> public byte[] AnalyzeJsonBuffer <T>(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); var analyze = jT808Config.GetAnalyze <T>(); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { utf8JsonWriter.WriteStartObject(); analyze.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.WriteEndObject(); utf8JsonWriter.Flush(); return(memoryStream.ToArray()); } }
public byte [] Serialize <T>(T obj, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { var formatter = jT808Config.GetMessagePackFormatter <T>(); JT808MessagePackWriter jT808MessagePackWriter = new JT808MessagePackWriter(buffer, version); formatter.Serialize(ref jT808MessagePackWriter, obj, jT808Config); return(jT808MessagePackWriter.FlushAndGetEncodingArray()); } finally { JT808ArrayPool.Return(buffer); } }
public dynamic Deserialize(ReadOnlySpan <byte> bytes, Type type, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { var formatter = jT808Config.GetMessagePackFormatterByType(type); JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); if (CheckPackageType(type)) { jT808MessagePackReader.Decode(buffer); } return(JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(formatter, ref jT808MessagePackReader, jT808Config)); } finally { JT808ArrayPool.Return(buffer); } }
public T Deserialize <T>(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); if (CheckPackageType(typeof(T))) { jT808MessagePackReader.Decode(buffer); } var formatter = jT808Config.GetMessagePackFormatter <T>(); return(formatter.Deserialize(ref jT808MessagePackReader, jT808Config)); } finally { JT808ArrayPool.Return(buffer); } }
/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="version"></param> /// <param name="options"></param> /// <param name="minBufferSize"></param> /// <returns></returns> public byte[] AnalyzeJsonBuffer(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default, int minBufferSize = 8096) { byte[] buffer = JT808ArrayPool.Rent(minBufferSize); try { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); jT808MessagePackReader.Decode(buffer); using MemoryStream memoryStream = new MemoryStream(); using Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options); jT808Package.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.Flush(); return(memoryStream.ToArray()); } finally { JT808ArrayPool.Return(buffer); } }
public string Analyze <T>(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013, JsonWriterOptions options = default) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); var analyze = jT808Config.GetAnalyze <T>(); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(memoryStream, options)) { if (!CheckPackageType(typeof(T))) { utf8JsonWriter.WriteStartObject(); } analyze.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); if (!CheckPackageType(typeof(T))) { utf8JsonWriter.WriteEndObject(); } utf8JsonWriter.Flush(); string value = Encoding.UTF8.GetString(memoryStream.ToArray()); return(value); } }
/// <summary> /// /// </summary> /// <param name="buffer">内存块</param> /// <param name="version">版本号:默认2013</param> public JT808MessagePackWriter(Span <byte> buffer, JT808Version version = JT808Version.JTT2013) { this.writer = new JT808BufferWriter(buffer); Version = version; }
/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="version"></param> /// <returns></returns> public JT808CarDVRDownPackage DownDeserialize(ReadOnlySpan <byte> bytes, JT808Version version = JT808Version.JTT2013) { JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes, version); return(JT808CarDVRDownPackage.Deserialize(ref jT808MessagePackReader, jT808Config)); }
public JT808ClientRequest(JT808Package package, JT808Version version = JT808Version.JTT2013, int minBufferSize = 1024) { Package = package; MinBufferSize = minBufferSize; Version = version; }