提交示例代码

This commit is contained in:
Bob.Song
2026-03-05 11:39:06 +08:00
commit 25958f58c3
2534 changed files with 209593 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
using Fantasy.Serialize;
#pragma warning disable CS8604 // Possible null reference argument.
namespace Fantasy;
public static class SerializerComponentSystem
{
public static void Initialize(this SerializerComponent self)
{
self.Serialize = SerializerManager.GetSerializer(FantasySerializerType.ProtoBuf);
}
public static byte[] Serialize<T>(this SerializerComponent self, T @object)
{
using var memoryStreamBuffer = self.BufferPool.RentMemoryStream(MemoryStreamBufferSource.None);
self.Serialize.Serialize(typeof(T), @object, memoryStreamBuffer);
return memoryStreamBuffer.ToArray();
}
public static T Deserialize<T>(this SerializerComponent self, byte[] bytes)
{
return self.Serialize.Deserialize<T>(bytes);
}
}