protobuff 添加程序集引用 和修改使用MergeFromEx

This commit is contained in:
sin365 2025-11-06 15:32:54 +08:00
parent ec94778778
commit 588c8850ea
2 changed files with 8 additions and 3 deletions

View File

@ -10,7 +10,8 @@
"StoicGooseUnity",
"Unity.InputSystem",
"AxiNSApi",
"Unity.InputSystem.Switch"
"Unity.InputSystem.Switch",
"Google.Protobuf"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -8,6 +8,7 @@ namespace AxibugEmuOnline.Client.Common
public static class ProtoBufHelper
{
private static ProtobufferMsgPool _msgPool = new ProtobufferMsgPool();
static CodedInputStream codedInputStream = new CodedInputStream();
public static void RentSerizlizeData(IMessage msg, out byte[] data, out int usedlength)
{
@ -28,14 +29,17 @@ namespace AxibugEmuOnline.Client.Common
{
var msgType = typeof(T);
object msg = _msgPool.Get(msgType);
((IMessage)msg).MergeFrom(bytes);
//((IMessage)msg).MergeFrom(bytes);
((IMessage)msg).MergeFromEx(codedInputStream, bytes, 0, bytes.Length);
return (T)msg;
}
public static IMessage DeSerizlizeFromPool(byte[] bytes, Type protoType)
{
var msgType = protoType;
object msg = _msgPool.Get(msgType);
((IMessage)msg).MergeFrom(bytes);
//((IMessage)msg).MergeFrom(bytes);
((IMessage)msg).MergeFromEx(codedInputStream, bytes, 0, bytes.Length);
return (IMessage)msg;
}
public static void ReleaseToPool(IMessage msg)