41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
|
namespace OECS;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Describes a component type discovered at compile time by the source generator.
|
||
|
|
/// Used by <see cref="WorldSerializer"/> to save/load components without reflection.
|
||
|
|
/// </summary>
|
||
|
|
public sealed class ComponentDescriptor
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// The assembly-qualified name of the component type, for stable serialization
|
||
|
|
/// across assemblies.
|
||
|
|
/// </summary>
|
||
|
|
public string TypeName { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// The <see cref="System.Type"/> of the component.
|
||
|
|
/// </summary>
|
||
|
|
public Type Type { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Serializes a boxed component instance to a MessagePack byte array.
|
||
|
|
/// </summary>
|
||
|
|
public Func<object, byte[]> Serialize { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Deserializes a MessagePack byte array into a boxed component instance.
|
||
|
|
/// </summary>
|
||
|
|
public Func<byte[], object> Deserialize { get; }
|
||
|
|
|
||
|
|
public ComponentDescriptor(
|
||
|
|
string typeName,
|
||
|
|
Type type,
|
||
|
|
Func<object, byte[]> serialize,
|
||
|
|
Func<byte[], object> deserialize)
|
||
|
|
{
|
||
|
|
TypeName = typeName;
|
||
|
|
Type = type;
|
||
|
|
Serialize = serialize;
|
||
|
|
Deserialize = deserialize;
|
||
|
|
}
|
||
|
|
}
|