mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] TEngineServer
[+] TEngineServer
This commit is contained in:
11
Assets/GameScripts/DotNet/Core/Helper/Proto/AProto.cs
Normal file
11
Assets/GameScripts/DotNet/Core/Helper/Proto/AProto.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using ProtoBuf;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[ProtoContract]
|
||||
public abstract class AProto
|
||||
{
|
||||
public virtual void AfterDeserialization() => EndInit();
|
||||
protected virtual void EndInit() { }
|
||||
}
|
||||
}
|
11
Assets/GameScripts/DotNet/Core/Helper/Proto/AProto.cs.meta
Normal file
11
Assets/GameScripts/DotNet/Core/Helper/Proto/AProto.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3172691aec101574282e3e66d998d4dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
#pragma warning disable CS8604
|
||||
|
||||
namespace TEngine.Core
|
||||
{
|
||||
public static class ProtoBufHelper
|
||||
{
|
||||
public static object FromBytes(Type type, byte[] bytes, int index, int count)
|
||||
{
|
||||
using var stream = new MemoryStream(bytes, index, count);
|
||||
return Serializer.Deserialize(type, stream);
|
||||
}
|
||||
|
||||
public static T FromBytes<T>(byte[] bytes)
|
||||
{
|
||||
using var stream = new MemoryStream(bytes, 0, bytes.Length);
|
||||
return Serializer.Deserialize<T>(stream);
|
||||
// return FromBytes<T>(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static T FromBytes<T>(byte[] bytes, int index, int count)
|
||||
{
|
||||
using var stream = new MemoryStream(bytes, index, count);
|
||||
return Serializer.Deserialize<T>(stream);
|
||||
}
|
||||
|
||||
public static byte[] ToBytes(object message)
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
Serializer.Serialize(stream, message);
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public static void ToStream(object message, MemoryStream stream)
|
||||
{
|
||||
Serializer.Serialize(stream, message);
|
||||
}
|
||||
|
||||
public static object FromStream(Type type, MemoryStream stream)
|
||||
{
|
||||
return Serializer.Deserialize(type, stream);
|
||||
}
|
||||
|
||||
public static T FromStream<T>(MemoryStream stream)
|
||||
{
|
||||
return (T) Serializer.Deserialize(typeof(T), stream);
|
||||
}
|
||||
|
||||
public static T Clone<T>(T t)
|
||||
{
|
||||
var bytes = ToBytes(t);
|
||||
using var stream = new MemoryStream(bytes, 0, bytes.Length);
|
||||
return Serializer.Deserialize<T>(stream);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27e0977e977a7834695b073736221239
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user