MessagePackHelper.cs 1023 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.IO;
  3. namespace ET
  4. {
  5. public static class MessagePackHelper
  6. {
  7. public static void SerializeTo(ushort opcode, object obj, MemoryStream stream)
  8. {
  9. if (opcode >= 20000)
  10. {
  11. ProtobufHelper.ToStream(obj, stream);
  12. return;
  13. }
  14. MongoHelper.ToBson(obj, stream);
  15. }
  16. public static object DeserializeFrom(ushort opcode, Type type, byte[] bytes, int index, int count)
  17. {
  18. if (opcode >= 20000)
  19. {
  20. return ProtobufHelper.FromBytes(type, bytes, index, count);
  21. }
  22. return MongoHelper.FromBson(type, bytes, index, count);
  23. }
  24. public static object DeserializeFrom(ushort opcode, Type type, MemoryStream stream)
  25. {
  26. if (opcode >= 20000)
  27. {
  28. return ProtobufHelper.FromStream(type, stream);
  29. }
  30. return MongoHelper.FromStream(type, stream);
  31. }
  32. }
  33. }