MemoryPackHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // using System;
  2. // using System.ComponentModel;
  3. // using MemoryPack;
  4. //
  5. // namespace ET
  6. // {
  7. // public static class MemoryPackHelper
  8. // {
  9. // public static byte[] Serialize(object message)
  10. // {
  11. // if (message is ISupportInitialize supportInitialize)
  12. // {
  13. // supportInitialize.BeginInit();
  14. // }
  15. // return MemoryPackSerializer.Serialize(message.GetType(), message);
  16. // }
  17. //
  18. // public static void Serialize(object message, MemoryBuffer stream)
  19. // {
  20. // if (message is ISupportInitialize supportInitialize)
  21. // {
  22. // supportInitialize.BeginInit();
  23. // }
  24. // MemoryPackSerializer.Serialize(message.GetType(), stream, message);
  25. // }
  26. //
  27. // public static object Deserialize(Type type, byte[] bytes, int index, int count)
  28. // {
  29. // object o = MemoryPackSerializer.Deserialize(type, bytes.AsSpan(index, count));
  30. // if (o is ISupportInitialize supportInitialize)
  31. // {
  32. // supportInitialize.EndInit();
  33. // }
  34. // return o;
  35. // }
  36. //
  37. // public static object Deserialize(Type type, byte[] bytes, int index, int count, ref object o)
  38. // {
  39. // MemoryPackSerializer.Deserialize(type, bytes.AsSpan(index, count), ref o);
  40. // if (o is ISupportInitialize supportInitialize)
  41. // {
  42. // supportInitialize.EndInit();
  43. // }
  44. // return o;
  45. // }
  46. //
  47. // public static object Deserialize(Type type, MemoryBuffer stream)
  48. // {
  49. // object o = MemoryPackSerializer.Deserialize(type, stream.GetSpan());
  50. // if (o is ISupportInitialize supportInitialize)
  51. // {
  52. // supportInitialize.EndInit();
  53. // }
  54. // return o;
  55. // }
  56. //
  57. // public static object Deserialize(Type type, MemoryBuffer stream, ref object o)
  58. // {
  59. // MemoryPackSerializer.Deserialize(type, stream.GetSpan(), ref o);
  60. // if (o is ISupportInitialize supportInitialize)
  61. // {
  62. // supportInitialize.EndInit();
  63. // }
  64. // return o;
  65. // }
  66. // }
  67. // }