public string Analyze <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(); string value = Encoding.UTF8.GetString(memoryStream.ToArray()); return(value); } } finally { JT808ArrayPool.Return(buffer); } }
public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0802 value = new JT808_0x0802(); value.MsgNum = reader.ReadUInt16(); writer.WriteNumber($"[{value.MsgNum.ReadNumber()}]应答流水号", value.MsgNum); value.MultimediaItemCount = reader.ReadUInt16(); writer.WriteNumber($"[{value.MultimediaItemCount.ReadNumber()}]多媒体数据总项数", value.MultimediaItemCount); writer.WriteStartArray("多媒体数据集合"); for (var i = 0; i < value.MultimediaItemCount; i++) { writer.WriteStartObject(); JT808MultimediaSearchProperty jT808MultimediaSearchProperty = new JT808MultimediaSearchProperty(); jT808MultimediaSearchProperty.MultimediaId = reader.ReadUInt32(); writer.WriteNumber($"[{jT808MultimediaSearchProperty.MultimediaId.ReadNumber()}]多媒体ID", jT808MultimediaSearchProperty.MultimediaId); jT808MultimediaSearchProperty.MultimediaType = reader.ReadByte(); writer.WriteNumber($"[{jT808MultimediaSearchProperty.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)jT808MultimediaSearchProperty.MultimediaType).ToString()}", jT808MultimediaSearchProperty.MultimediaType); jT808MultimediaSearchProperty.ChannelId = reader.ReadByte(); writer.WriteNumber($"[{jT808MultimediaSearchProperty.ChannelId.ReadNumber()}]通道ID", jT808MultimediaSearchProperty.ChannelId); jT808MultimediaSearchProperty.EventItemCoding = reader.ReadByte(); writer.WriteNumber($"[{jT808MultimediaSearchProperty.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)jT808MultimediaSearchProperty.EventItemCoding).ToString()}", jT808MultimediaSearchProperty.EventItemCoding); JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); writer.WriteStartObject($"位置基本信息"); config.GetAnalyze <JT808_0x0200>().Analyze(ref positionReader, writer, config); writer.WriteEndObject(); writer.WriteEndObject(); } writer.WriteEndArray(); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="writer"></param> /// <param name="config"></param> public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0704 jT808_0X0704 = new JT808_0x0704(); jT808_0X0704.Count = reader.ReadUInt16(); writer.WriteNumber($"[{jT808_0X0704.Count.ReadNumber()}]数据项个数", jT808_0X0704.Count); jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte(); writer.WriteNumber($"[{((byte)jT808_0X0704.LocationType).ReadNumber()}]位置数据类型-{jT808_0X0704.LocationType}", (byte)jT808_0X0704.LocationType); writer.WriteStartArray("位置汇报数据集合"); for (int i = 0; i < jT808_0X0704.Count; i++) { writer.WriteStartObject(); int buflen = reader.ReadUInt16(); writer.WriteNumber($"[{buflen.ReadNumber()}]位置汇报数据长度", buflen); try { writer.WriteString($"位置汇报数据", reader.ReadVirtualArray(buflen).ToArray().ToHexString()); JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen)); writer.WriteStartObject("位置信息汇报"); config.GetAnalyze <JT808_0x0200>().Analyze(ref tmpReader, writer, config); writer.WriteEndObject(); } catch (Exception) { } writer.WriteEndObject(); } writer.WriteEndArray(); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bytes"></param> /// <param name="version"></param> /// <param name="options"></param> /// <returns></returns> 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)) { utf8JsonWriter.WriteStartObject(); analyze.Analyze(ref jT808MessagePackReader, utf8JsonWriter, jT808Config); utf8JsonWriter.WriteEndObject(); utf8JsonWriter.Flush(); string value = Encoding.UTF8.GetString(memoryStream.ToArray()); return(value); } }
public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0500 value = new JT808_0x0500(); value.MsgNum = reader.ReadUInt16(); writer.WriteNumber($"[{value.MsgNum.ReadNumber()}]应答流水号", value.MsgNum); writer.WriteStartObject("位置基本信息"); config.GetAnalyze <JT808_0x0200>().Analyze(ref reader, writer, config); writer.WriteEndObject(); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="writer"></param> /// <param name="config"></param> public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0704 jT808_0X0704 = new JT808_0x0704(); jT808_0X0704.Count = reader.ReadUInt16(); writer.WriteNumber($"[{jT808_0X0704.Count.ReadNumber()}]数据项个数", jT808_0X0704.Count); jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte(); writer.WriteNumber($"[{((byte)jT808_0X0704.LocationType).ReadNumber()}]位置数据类型-{jT808_0X0704.LocationType}", (byte)jT808_0X0704.LocationType); writer.WriteStartArray("位置汇报数据集合"); for (int i = 0; i < jT808_0X0704.Count; i++) { int remainContent = reader.ReadCurrentRemainContentLength(); if (remainContent <= 0) { continue; } writer.WriteStartObject(); int buflen = reader.ReadUInt16(); writer.WriteNumber($"[{buflen.ReadNumber()}]位置汇报数据长度", buflen); if ((remainContent - buflen) >= 0) { writer.WriteString($"位置汇报数据{{{i}}}", reader.ReadVirtualArray(buflen).ToArray().ToHexString()); JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen), reader.Version); writer.WriteStartObject("位置信息汇报"); try { config.GetAnalyze <JT808_0x0200>().Analyze(ref tmpReader, writer, config); } catch (Exception ex) { writer.WriteString($"分析异常", ex.StackTrace); } writer.WriteEndObject(); } else { int remainContent1 = reader.ReadCurrentRemainContentLength(); var buffer = reader.ReadArray(remainContent1); writer.WriteString($"位置汇报异常数据{{{i}}}", buffer.ToArray().ToHexString()); } writer.WriteEndObject(); } writer.WriteEndArray(); }
public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0801 value = new JT808_0x0801(); value.MultimediaId = reader.ReadUInt32(); writer.WriteNumber($"[{value.MultimediaId.ReadNumber()}]多媒体ID", value.MultimediaId); value.MultimediaType = reader.ReadByte(); writer.WriteNumber($"[{value.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)value.MultimediaType).ToString()}", value.MultimediaType); value.MultimediaCodingFormat = reader.ReadByte(); writer.WriteNumber($"[{value.MultimediaCodingFormat.ReadNumber()}]多媒体格式编码-{((JT808MultimediaCodingFormat)value.MultimediaCodingFormat).ToString()}", value.MultimediaCodingFormat); value.EventItemCoding = reader.ReadByte(); writer.WriteNumber($"[{value.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)value.EventItemCoding).ToString()}", value.MultimediaCodingFormat); value.ChannelId = reader.ReadByte(); writer.WriteNumber($"[{value.ChannelId.ReadNumber()}]通道ID", value.ChannelId); JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); writer.WriteStartObject("位置基本信息"); config.GetAnalyze <JT808_0x0200>().Analyze(ref positionReader, writer, config); writer.WriteEndObject(); value.MultimediaDataPackage = reader.ReadContent().ToArray(); writer.WriteString($"多媒体数据包", value.MultimediaDataPackage.ToHexString()); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="writer"></param> /// <param name="config"></param> public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0801 value = new JT808_0x0801(); value.MultimediaId = reader.ReadUInt32(); writer.WriteNumber($"[{value.MultimediaId.ReadNumber()}]多媒体ID", value.MultimediaId); value.MultimediaType = reader.ReadByte(); writer.WriteNumber($"[{value.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)value.MultimediaType).ToString()}", value.MultimediaType); value.MultimediaCodingFormat = reader.ReadByte(); writer.WriteNumber($"[{value.MultimediaCodingFormat.ReadNumber()}]多媒体格式编码-{((JT808MultimediaCodingFormat)value.MultimediaCodingFormat).ToString()}", value.MultimediaCodingFormat); value.EventItemCoding = reader.ReadByte(); writer.WriteNumber($"[{value.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)value.EventItemCoding).ToString()}", value.MultimediaCodingFormat); value.ChannelId = reader.ReadByte(); writer.WriteNumber($"[{value.ChannelId.ReadNumber()}]通道ID", value.ChannelId); if (reader.ReadCurrentRemainContentLength() >= 28) { var tempData = reader.ReadVirtualArray(28); try { JT808MessagePackReader positionReader = new JT808MessagePackReader(tempData, reader.Version); writer.WriteStartObject("位置基本信息"); config.GetAnalyze <JT808_0x0200>().Analyze(ref positionReader, writer, config); writer.WriteEndObject(); reader.Skip(28); } catch { PositionError = true; } value.MultimediaDataPackage = reader.ReadContent().ToArray(); writer.WriteString($"多媒体数据包", value.MultimediaDataPackage.ToHexString()); } else { value.MultimediaDataPackage = reader.ReadContent().ToArray(); writer.WriteString($"多媒体数据包", value.MultimediaDataPackage.ToHexString()); } }