-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathTextDataFile.cs
More file actions
51 lines (40 loc) · 1.25 KB
/
Copy pathTextDataFile.cs
File metadata and controls
51 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using MessagePack;
namespace GBFRDataTools.Entities;
public class TextDataFile
{
[JsonPropertyName("rows_")]
public List<TextData> Rows { get; set; } = [];
public static TextDataFile Read(byte[] data, bool isMessagePackFile = false)
{
string text;
if (isMessagePackFile)
text = MessagePackSerializer.ConvertToJson(data);
else
text = Encoding.UTF8.GetString(data);
JsonDocument doc = JsonDocument.Parse(text);
var file = new TextDataFile();
foreach (var elem in doc.RootElement.GetProperty("rows_").EnumerateArray())
{
var column = elem.GetProperty("column_");
TextData textData = column.Deserialize<TextData>(DefaultJsonSerializerOptions.InstanceForRead);
file.Rows.Add(textData);
}
return file;
}
}
public class TextData
{
[JsonPropertyName("text_")]
public string Text { get; set; }
[JsonPropertyName("subid_hash_")]
public string Subid_hash { get; set; }
[JsonPropertyName("id_hash_")]
public string Id_hash { get; set; }
}