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)
{