-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
28 lines (23 loc) · 898 Bytes
/
Program.cs
File metadata and controls
28 lines (23 loc) · 898 Bytes
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
using System.Text.Json;
using System.Text.Json.Nodes;
using Google.FlatBuffers;
using MemoryPack;
using MemoryPack2Json;
using reflection;
string schemaPath = args[0];
string pathIn = Path.GetFullPath(args[1]);
string pathOut = Path.ChangeExtension(pathIn, "json");
SchemaT schema = Schema.GetRootAsSchema(new ByteBuffer(File.ReadAllBytes(schemaPath))).UnPack();
var converter = new Converter(schema);
JsonObject jsonObject;
using (var optionalState = MemoryPackReaderOptionalStatePool.Rent(null))
{
var reader = new MemoryPackReader(File.ReadAllBytes(pathIn), optionalState);
jsonObject = converter.TranslateObject(ref reader, schema.RootTable)!;
}
{
var writerOptions = new JsonWriterOptions { Indented = true };
using var stream = File.OpenWrite(pathOut);
using var utf8JsonWriter = new Utf8JsonWriter(stream, writerOptions);
jsonObject.WriteTo(utf8JsonWriter);
}