Migrated from net48 (.NET Framework) to net10.0 (cross-platform): - All 14 csproj: net48 → net10.0, WindowsDesktop SDK → Microsoft.NET.Sdk - Excluded WinForms files (Form/**, DebugControl, GameControl, etc.) - Excluded DB modules (GameDAL db/Sql/**, MrWu DB files) - Excluded server runtime files (GameBase, GlobalSever managers, GameNetModule stubs) - Added minimal stubs (GameDoStub.cs, NamespaceStubs.cs, ServerCoreStubs.cs) - Created hjha-console entry project - Fixed hardcoded Windows path → ./test/ directory - Updated global.json to SDK 10.0.109 Console test mode: PdkGameMain(null).Test() → 发牌→包庄→打牌→结算 Verified: dotnet build 0 errors, dotnet run outputs game state machine
78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using System;
|
|
using System.Buffers;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using MessagePack;
|
|
using Server.Net;
|
|
|
|
namespace Server.Core
|
|
{
|
|
public class MessagePackHelper
|
|
{
|
|
/// <summary>
|
|
/// 序列化
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <returns></returns>
|
|
public static byte[] Serialize(object message)
|
|
{
|
|
if (message is ISupportInitialize supportInitialize)
|
|
{
|
|
supportInitialize.BeginInit();
|
|
}
|
|
|
|
return MessagePackSerializer.Serialize(message.GetType(), message);
|
|
}
|
|
|
|
public static void Serialize(object message, MemoryStream stream)
|
|
{
|
|
if (message is ISupportInitialize supportInitialize)
|
|
{
|
|
supportInitialize.BeginInit();
|
|
}
|
|
|
|
MessagePackSerializer.Serialize(stream, message);
|
|
}
|
|
|
|
public static T Deserialize<T>(byte[] bytes)
|
|
{
|
|
return (T)Deserialize(typeof(T), bytes);
|
|
}
|
|
|
|
public static T Deserialize<T>(byte[] bytes, int index, int count)
|
|
{
|
|
return (T)Deserialize(typeof(T), bytes, index, count);
|
|
}
|
|
|
|
public static object Deserialize(Type type,byte[] bytes)
|
|
{
|
|
return Deserialize(type, bytes, 0, bytes.Length);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 反序列化
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="bytes"></param>
|
|
/// <param name="index"></param>
|
|
/// <param name="count"></param>
|
|
public static object Deserialize(Type type, byte[] bytes, int index, int count)
|
|
{
|
|
return Deserialize(type, bytes.AsMemory(index, count));
|
|
}
|
|
|
|
public static object Deserialize(Type type, Memory<byte> bytes)
|
|
{
|
|
object o = MessagePackSerializer.Deserialize(type,bytes);
|
|
if (o is ISupportInitialize supportInitialize)
|
|
{
|
|
supportInitialize.EndInit();
|
|
}
|
|
|
|
return o;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |