MessagePackHelper.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.IO;
  3. namespace ET
  4. {
  5. /*
  6. public static class MessagePackHelper
  7. {
  8. static MessagePackHelper()
  9. {
  10. UnityTypeBindings.Register();
  11. }
  12. public static void Init()
  13. {
  14. }
  15. public static object FromBytes(Type type, byte[] bytes, int index, int count)
  16. {
  17. ReadOnlyMemory<byte> memory = new ReadOnlyMemory<byte>(bytes, index, count);
  18. return MessagePack.MessagePackSerializer.Deserialize(type, memory);
  19. }
  20. public static byte[] ToBytes(object message)
  21. {
  22. return MessagePack.MessagePackSerializer.Serialize(message);
  23. }
  24. public static void ToStream(object message, MemoryStream stream)
  25. {
  26. MessagePack.MessagePackSerializer.Serialize(stream, message);
  27. }
  28. public static object FromStream(Type type, MemoryStream stream)
  29. {
  30. return MessagePack.MessagePackSerializer.Deserialize(type, stream);
  31. }
  32. public static string ToJson(object message)
  33. {
  34. return LitJson.JsonMapper.ToJson(message);
  35. }
  36. public static object FromJson(Type type, string json)
  37. {
  38. return LitJson.JsonMapper.ToObject(json, type);
  39. }
  40. public static T FromJson<T>(string json)
  41. {
  42. return LitJson.JsonMapper.ToObject<T>(json);
  43. }
  44. }
  45. */
  46. }