示例#1
0
 /// <summary>
 /// 通过二进制反序列化
 /// Deserialize with byte[]
 /// </summary>
 /// <param name="msg"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ProtoDeSerialize <T>(byte[] msg) where T : class
 {
     try
     {
         ProtoTypeRegister.Register <T>();
         return(ProtoBuf.Serializer.Deserialize(typeof(T), new System.IO.MemoryStream(msg)) as T);
     }
     catch (IOException e)
     {
         Log.PrintError(e);
         return(null);
     }
 }
 /// <summary>
 /// 通过二进制反序列化
 /// Deserialize with byte[]
 /// </summary>
 /// <param name="msg"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ProtoDeSerialize <T>(byte[] msg) where T : class
 {
     try
     {
         ProtoTypeRegister.Register <T>();
         return(ProtoBuf.Serializer.Deserialize(typeof(T), new System.IO.MemoryStream(msg)) as T);
     }
     catch (IOException ex)
     {
         Log.PrintError($"[StringifyHelper] 错误:{ex.Message}, {ex.Data["StackTrace"]}");
         return(null);
     }
 }
示例#3
0
 /// <summary>
 /// 获取文件来反序列化(只能是可热更资源)
 /// Use file to deserialize (only hot update resources)
 /// </summary>
 /// <param name="path"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ProtoDeSerializeFromFile <T>(string path) where T : class
 {
     try
     {
         ProtoTypeRegister.Register <T>();
         var res = Assets.LoadAsset(path, typeof(TextAsset));
         return(ProtoBuf.Serializer.Deserialize(typeof(T), new System.IO.MemoryStream(res.bytes)) as T);
     }
     catch (IOException e)
     {
         Log.PrintError(e);
         return(null);
     }
 }
 /// <summary>
 /// 获取文件来反序列化(只能是可热更资源)
 /// Use file to deserialize (only hot update resources)
 /// </summary>
 /// <param name="path"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ProtoDeSerializeFromFile <T>(string path) where T : class
 {
     try
     {
         ProtoTypeRegister.Register <T>();
         var res = Assets.LoadAsset(path, typeof(TextAsset));
         return(ProtoBuf.Serializer.Deserialize(typeof(T), new System.IO.MemoryStream(res.bytes)) as T);
     }
     catch (IOException ex)
     {
         Log.PrintError($"[StringifyHelper] 错误:{ex.Message}, {ex.Data["StackTrace"]}");
         return(null);
     }
 }
示例#5
0
 /// <summary>
 /// 序列化并返回二进制
 /// Serialize an Object and return byte[]
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static byte[] ProtoSerialize <T>(T obj) where T : class
 {
     try
     {
         ProtoTypeRegister.Register <T>();
         var stream = new System.IO.MemoryStream();
         ProtoBuf.Serializer.Serialize(stream, obj);
         return(stream.ToArray());
     }
     catch (IOException e)
     {
         Log.PrintError(e);
         return(null);
     }
 }
 /// <summary>
 /// 序列化并返回二进制
 /// Serialize an Object and return byte[]
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static byte[] ProtoSerialize <T>(T obj) where T : class
 {
     try
     {
         using (var stream = new System.IO.MemoryStream())
         {
             ProtoTypeRegister.Register <T>();
             ProtoBuf.Serializer.Serialize(stream, obj);
             return(stream.ToArray());
         }
     }
     catch (IOException ex)
     {
         Log.PrintError($"[StringifyHelper] 错误:{ex.Message}, {ex.Data["StackTrace"]}");
         return(null);
     }
 }