/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static JTActiveSafetyPackage Deserialize(ReadOnlySpan <byte> bytes) { JTActiveSafetyPackage jTActiveSafetyPackage = new JTActiveSafetyPackage(); JTActiveSafetyMessagePackReader reader = new JTActiveSafetyMessagePackReader(bytes); jTActiveSafetyPackage.FH_Flag = reader.ReadUInt32(); jTActiveSafetyPackage.FileName = reader.ReadString(50); jTActiveSafetyPackage.Offset = reader.ReadUInt32(); jTActiveSafetyPackage.Length = reader.ReadUInt32(); jTActiveSafetyPackage.Bodies = reader.ReadRemainArray().ToArray(); return(jTActiveSafetyPackage); }
/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <param name="options"></param> /// <returns></returns> public static byte[] AnalyzeJsonBuffer(ReadOnlySpan <byte> bytes, JsonWriterOptions options = default) { JTActiveSafetyMessagePackReader reader = new JTActiveSafetyMessagePackReader(bytes); using (MemoryStream memoryStream = new MemoryStream()) using (Utf8JsonWriter writer = new Utf8JsonWriter(memoryStream, options)) { writer.WriteStartObject(); var header = reader.ReadUInt32(); writer.WriteNumber($"[{ header.ReadNumber()}]头部", header); var FileName = reader.ReadString(50); writer.WriteString($"[文件名称]", FileName); var offset = reader.ReadUInt32(); writer.WriteNumber($"{offset.ReadNumber()}[数据偏移量]", offset); var length = reader.ReadUInt32(); writer.WriteNumber($"{length.ReadNumber()}[数据长度]", length); var bodies = reader.ReadRemainArray().ToArray(); writer.WriteString("[数据体]", string.Join(" ", (bodies).Select(p => p.ToString("X2")))); writer.WriteEndObject(); writer.Flush(); return(memoryStream.ToArray()); } }