Skip to content

Commit 3b45516

Browse files
scorteanucosminMrBlue
authored andcommitted
Add shared compiler types for Compiler/CSharp
1 parent cdcf3e1 commit 3b45516

8 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Oxide.CompilerServices;
4+
5+
[Serializable]
6+
public class CompilationResult
7+
{
8+
public string Name { get; set; }
9+
public byte[] Data { get; set; } = [];
10+
public byte[] Symbols { get; set; } = [];
11+
12+
[NonSerialized]
13+
public int Success;
14+
15+
[NonSerialized]
16+
public int Failed;
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace Oxide.CompilerServices;
4+
5+
[Serializable]
6+
public enum CompilerLanguageVersion
7+
{
8+
Latest = 500,
9+
V16 = 16,
10+
V15 = 15,
11+
V14 = 14,
12+
V13 = 13,
13+
V12 = 12,
14+
V11 = 11,
15+
V10 = 10,
16+
V9 = 9,
17+
V8 = 8,
18+
V7 = 7,
19+
V6 = 6,
20+
V5 = 5,
21+
V4 = 4,
22+
V3 = 3,
23+
V2 = 2,
24+
V1 = 1,
25+
Preview = 1000
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
namespace Oxide.CompilerServices;
3+
4+
[Serializable]
5+
public sealed class CompilerMessage
6+
{
7+
public int Id { get; set; }
8+
9+
public MessageType Type { get; set; }
10+
11+
public byte[] Data { get; set; }
12+
13+
public object ExtraData { get; set; }
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Oxide.CompilerServices;
4+
5+
[Serializable]
6+
public enum CompilerPlatform
7+
{
8+
AnyCPU,
9+
AnyCPU32Preferred,
10+
Arm,
11+
X86,
12+
X64,
13+
IA64
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Oxide.CompilerServices;
4+
5+
[Serializable]
6+
public enum CompilerTarget
7+
{
8+
Library,
9+
Exe,
10+
Module,
11+
WinExe
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Oxide.CompilerServices;
2+
3+
public interface ISerializer
4+
{
5+
public byte[] Serialize<T>(T type) where T : class;
6+
7+
public T Deserialize<T>(byte[] data) where T : class;
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace Oxide.CompilerServices;
4+
5+
[Flags]
6+
[Serializable]
7+
public enum MessageType : byte
8+
{
9+
Unknown = 0x00,
10+
Acknowledge = 0x01,
11+
Heartbeat = 0x02,
12+
VersionInfo = 0x04,
13+
Ready = 0x08,
14+
Command = 0x10,
15+
Data = 0x20,
16+
Error = 0x40,
17+
Shutdown = 80
18+
}

src/CompilerServices/Serializer.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
extern alias References;
2+
3+
using System.IO;
4+
using System.Text;
5+
using References::Newtonsoft.Json;
6+
7+
namespace Oxide.CompilerServices;
8+
9+
public class Serializer : ISerializer
10+
{
11+
private readonly JsonSerializer _jsonSerializer;
12+
13+
public Serializer()
14+
{
15+
_jsonSerializer = new JsonSerializer();
16+
}
17+
18+
public byte[] Serialize<T>(T type) where T : class
19+
{
20+
using MemoryStream memoryStream = new();
21+
using StreamWriter writer = new(memoryStream, Encoding.UTF8);
22+
_jsonSerializer.Serialize(writer, type);
23+
writer.Flush();
24+
return memoryStream.ToArray();
25+
}
26+
27+
public T Deserialize<T>(byte[] data) where T : class
28+
{
29+
using MemoryStream memoryStream = new(data);
30+
using StreamReader reader = new(memoryStream, Encoding.UTF8);
31+
return (T)_jsonSerializer.Deserialize(reader, typeof(T));
32+
}
33+
}

0 commit comments

Comments
 (0)