MongoPacker.cs 950 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace ETModel
  3. {
  4. public class MongoPacker: IMessagePacker
  5. {
  6. public byte[] SerializeToByteArray(object obj)
  7. {
  8. return MongoHelper.ToBson(obj);
  9. }
  10. public string SerializeToText(object obj)
  11. {
  12. return MongoHelper.ToJson(obj);
  13. }
  14. public object DeserializeFrom(Type type, byte[] bytes)
  15. {
  16. return MongoHelper.FromBson(type, bytes);
  17. }
  18. public object DeserializeFrom(Type type, byte[] bytes, int index, int count)
  19. {
  20. return MongoHelper.FromBson(type, bytes, index, count);
  21. }
  22. public T DeserializeFrom<T>(byte[] bytes)
  23. {
  24. return MongoHelper.FromBson<T>(bytes);
  25. }
  26. public T DeserializeFrom<T>(byte[] bytes, int index, int count)
  27. {
  28. return MongoHelper.FromBson<T>(bytes, index, count);
  29. }
  30. public T DeserializeFrom<T>(string str)
  31. {
  32. return MongoHelper.FromJson<T>(str);
  33. }
  34. public object DeserializeFrom(Type type, string str)
  35. {
  36. return MongoHelper.FromJson(type, str);
  37. }
  38. }
  39. }