forked from rwmt/MultiplayerAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializer.cs
More file actions
26 lines (21 loc) · 811 Bytes
/
Copy pathSerializer.cs
File metadata and controls
26 lines (21 loc) · 811 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
using System;
namespace Multiplayer.API;
public record Serializer<Live, Networked>(
Func<Live, object, object[], Networked> Writer, // (live, target, args) => networked
Func<Networked, Live> Reader // (networked) => live
);
public static class Serializer
{
public static Serializer<Live, Networked> New<Live, Networked>(Func<Live, object, object[], Networked> writer, Func<Networked, Live> reader)
{
return new(writer, reader);
}
public static Serializer<Live, Networked> New<Live, Networked>(Func<Live, Networked> writer, Func<Networked, Live> reader)
{
return new((live, _, _) => writer(live), reader);
}
public static Serializer<Live, object> SimpleReader<Live>(Func<Live> reader)
{
return new((_, _, _) => null, _ => reader());
}
}