This commit is contained in:
CortexCore
2025-01-23 11:39:53 +08:00
parent 000a079985
commit 57e24939fb
7 changed files with 52 additions and 18 deletions

View File

@@ -9,6 +9,7 @@ using System.IO;
using System.Linq;
using System.Text;
using Cysharp.Threading.Tasks;
using MemoryPack;
using Microsoft.SqlServer.Server;
#if NET5_0_OR_GREATER
using Microsoft.SqlServer.Server;
@@ -107,22 +108,27 @@ namespace BITKit
return instance;
}
var json = reader.ReadString();
if (string.IsNullOrEmpty(json))
if (BITSharp.TryGetTypeFromFullName(typeName, out type))
{
throw new Exception($"从二进制中读取的json值为空");
return MemoryPackSerializer.Deserialize(type, reader.ReadBytes(reader.ReadInt32()));
}
try
{
if (BITSharp.TryGetTypeFromFullName(typeName, out type))
return JsonConvert.DeserializeObject(json, type);
}
catch (Exception e)
{
BIT4Log.Warning<BITBinary>($"反序列化失败,类型:{typeName},值:\n{json}");
BIT4Log.LogException(e);
}
// var json = reader.ReadString();
// if (string.IsNullOrEmpty(json))
// {
// throw new Exception($"从二进制中读取的json值为空");
// }
//
// try
// {
// if (BITSharp.TryGetTypeFromFullName(typeName, out type))
// return JsonConvert.DeserializeObject(json, type);
// }
// catch (Exception e)
// {
// BIT4Log.Warning<BITBinary>($"反序列化失败,类型:{typeName},值:\n{json}");
// BIT4Log.LogException(e);
// }
throw new Exception("未找到读取该二进制的BinaryReader");
}
@@ -172,7 +178,11 @@ namespace BITKit
{
try
{
writer.Write(JsonConvert.SerializeObject(value));
var bytes = MemoryPackSerializer.Serialize(value.GetType(),value);
writer.Write(bytes.Length);
writer.Write(bytes);
//writer.Write(JsonConvert.SerializeObject(value));
}
catch (Exception)
{

View File

@@ -17,7 +17,6 @@ using BITKit.Net.Examples;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Unity.Mathematics;
using UnityEngine;
namespace BITKit.Net
{

View File

@@ -1,6 +1,9 @@
using MemoryPack;
namespace BITKit.Net.Examples
{
public struct NetClientAllocateIdCommand
[MemoryPackable]
public partial struct NetClientAllocateIdCommand
{
public int Id;
public string Ip;

View File

@@ -64,8 +64,11 @@ namespace BITKit.StateMachine
if(_cancellationTokenSource.IsCancellationRequested)return;
if (CurrentState is null) return;
using var _ = IsBusy.GetHandle();
if (CurrentState is not null)
{
CurrentState.Enabled = false;
}
await CurrentState.OnStateExitAsync(CurrentState, null);
if(_cancellationTokenSource.IsCancellationRequested)return;
CurrentState.OnStateExit(CurrentState, null);
CurrentState = null;
}